diff options
| author | Haishan <[email protected]> | 2019-04-21 00:05:44 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2019-04-21 21:58:33 +0800 |
| commit | 882b168082ddbcbe7991a71a09944f1a60084fc3 (patch) | |
| tree | d12345be635943537042a929aed8376ae4480324 /src/components/TrafficChartSample.js | |
| parent | eda2501b1d68c6f82a4a824ffe12caf5be7b33f2 (diff) | |
squash: feat(config): add options to select traffic chart style
Diffstat (limited to 'src/components/TrafficChartSample.js')
| -rw-r--r-- | src/components/TrafficChartSample.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/components/TrafficChartSample.js b/src/components/TrafficChartSample.js new file mode 100644 index 0000000..772f6d2 --- /dev/null +++ b/src/components/TrafficChartSample.js @@ -0,0 +1,54 @@ +import React, { useMemo } from 'react'; +import useLineChart from '../hooks/useLineChart'; +import { chartJSResource, commonDataSetProps, chartStyles } from 'm/chart'; + +const extraChartOptions = { + legend: { + display: false + }, + scales: { + xAxes: [{ display: false }], + yAxes: [{ display: false }] + } +}; + +const data1 = [23e3, 35e3, 46e3, 33e3, 90e3, 68e3, 23e3, 45e3]; +const data2 = [184e3, 183e3, 196e3, 182e3, 190e3, 186e3, 182e3, 189e3]; +const labels = data1; + +export default function TrafficChart({ id }) { + const Chart = chartJSResource.read(); + + const data = useMemo( + () => ({ + labels, + datasets: [ + { + ...commonDataSetProps, + ...chartStyles[id].up, + data: data1 + }, + { + ...commonDataSetProps, + ...chartStyles[id].down, + data: data2 + } + ] + }), + [] + ); + + const eleId = 'chart-' + id; + useLineChart(Chart, eleId, data, null, extraChartOptions); + + return ( + <div + style={{ + width: 150, + padding: 5 + }} + > + <canvas id={eleId} /> + </div> + ); +} |
