范围区域

该示例演示了范围区域图表。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as chart from '@grapecity/wijmo.chart'; import { getRawData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { let rawData = getRawData(); let pct25_75 = calcRanges(rawData, 25, 75); let pct5_95 = calcRanges(rawData, 5, 95); let chartCtr = new chart.FlexChart('#chart', { chartType: 'Area', series: [ { itemsSource: pct5_95, bindingX: 'day', binding: 'min,max', name: '5% - 95%', style: { fill: 'rgba(136, 189, 230, 0.2)', stroke: 'transparent' }, }, { itemsSource: pct25_75, bindingX: 'day', binding: 'min,max', name: '25% - 75%', style: { fill: 'rgba(136, 189, 230, 0.4)', stroke: 'transparent' } }, { itemsSource: rawData, bindingX: 'day', binding: 'time', name: 'raw data', chartType: 'Scatter', style: { fill: 'black', stroke: 'transparent' }, symbolSize: 4 }, ], axisX: { title: 'day' }, axisY: { title: 'time' }, }); // } function calcRanges(rawData, minPct, maxPct) { let dict = {}; let data = []; for (let i = 0; i < rawData.length; i++) { let day = rawData[i].day; if (!dict[day]) { dict[day] = []; } dict[day].push(rawData[i].time); } for (let d in dict) { let vals = dict[d]; vals.sort((a, b) => a - b); let min = calcPecentile(vals, minPct); // vals[Math.ceil(minPct / 100 * vals.length)]; let max = calcPecentile(vals, maxPct); //vals[Math.ceil(maxPct / 100 * vals.length)]; data.push({ day: parseInt(d), min: min, max: max }); } return data; } function calcPecentile(vals, pct) { let i = Math.ceil(pct / 100 * vals.length); if (i < 0) { i = 0; } else if (i >= vals.length) { i = vals.length - 1; } return vals[i]; } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Range Area</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <div id="chart"></div> </div> </body> </html> export function getRawData() { let data = []; for (let d = 1; d <= 7; d++) { for (let i = 0; i < 20; i++) { data.push({ day: d, time: Math.random() * 60 }); } } return data; } body { margin-bottom: 24px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './app.css'; import * as React from 'react'; import * as ReactDOM from 'react-dom'; import * as wjChart from '@grapecity/wijmo.react.chart'; import { getRawData } from './data'; class App extends React.Component { render() { let rawData = getRawData(); return <wjChart.FlexChart chartType='Area'> <wjChart.FlexChartSeries itemsSource={calcRanges(rawData, 5, 95)} bindingX='day' binding='min,max' name='5% - 95%' style={{ fill: 'rgba(136, 189, 230, 0.2)', stroke: 'transparent' }}/> <wjChart.FlexChartSeries itemsSource={calcRanges(rawData, 25, 75)} bindingX='day' binding='min,max' name='25% - 75%' style={{ fill: 'rgba(136, 189, 230, 0.4)', stroke: 'transparent' }}/> <wjChart.FlexChartSeries itemsSource={rawData} bindingX='day' binding='time' name='raw data' chartType='Scatter' style={{ fill: 'black', stroke: 'transparent' }} symbolSize={4}/> <wjChart.FlexChartAxis wjProperty="axisY" title='time'/> <wjChart.FlexChartAxis wjProperty="axisX" title='day'/> </wjChart.FlexChart>; } } const calcRanges = (rawData, minPct, maxPct) => { let dict = {}; let data = []; for (let i = 0; i < rawData.length; i++) { let day = rawData[i].day; if (!dict[day]) { dict[day] = []; } dict[day].push(rawData[i].time); } for (let d in dict) { let vals = dict[d]; vals.sort((a, b) => a - b); let min = calcPecentile(vals, minPct); // vals[Math.ceil(minPct / 100 * vals.length)]; let max = calcPecentile(vals, maxPct); //vals[Math.ceil(maxPct / 100 * vals.length)]; data.push({ day: parseInt(d), min: min, max: max }); } return data; }; const calcPecentile = (vals, pct) => { let i = Math.ceil(pct / 100 * vals.length); if (i < 0) { i = 0; } else if (i >= vals.length) { i = vals.length - 1; } return vals[i]; }; ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>AutoComplete</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> body { margin-bottom: 24px; } export function getRawData() { let data = []; for (let d = 1; d <= 7; d++) { for (let i = 0; i < 20; i++) { data.push({ day: d, time: Math.random() * 60 }); } } return data; }