|
| 1 | +import { SciChartSurface } from 'scichart/Charting/Visuals/SciChartSurface'; |
| 2 | +import { NumericAxis } from 'scichart/Charting/Visuals/Axis/NumericAxis'; |
| 3 | +import { XyDataSeries } from 'scichart/Charting/Model/XyDataSeries'; |
| 4 | +import { MouseWheelZoomModifier } from 'scichart/Charting/ChartModifiers/MouseWheelZoomModifier'; |
| 5 | +import { ZoomExtentsModifier } from 'scichart/Charting/ChartModifiers/ZoomExtentsModifier'; |
| 6 | +import { NumberRange } from 'scichart/Core/NumberRange'; |
| 7 | +import { ZoomPanModifier } from 'scichart/Charting/ChartModifiers/ZoomPanModifier'; |
| 8 | +import { StackedColumnRenderableSeries } from 'scichart/Charting/Visuals/RenderableSeries/StackedColumnRenderableSeries'; |
| 9 | +import { StackedColumnCollection } from 'scichart/Charting/Visuals/RenderableSeries/StackedColumnCollection'; |
| 10 | +import { RolloverModifier } from 'scichart/Charting/ChartModifiers/RolloverModifier'; |
| 11 | + |
| 12 | +const xValues = [1992, 1993, 1994, 1995, 1996]; |
| 13 | +const tomatoesData1 = [7, 30, 27, 24, 21]; |
| 14 | +const cucumberData2 = [16, 10, 9, 8, 22]; |
| 15 | +const pepperData3 = [7, 24, 21, 11, 19]; |
| 16 | + |
| 17 | +const THRESHOLD = 10; |
| 18 | + |
| 19 | +async function initSciChart() { |
| 20 | + // LICENSING // |
| 21 | + // Set your license code here |
| 22 | + // You can get a trial license key from https://www.scichart.com/licensing-scichart-js/ |
| 23 | + // Purchased license keys can be viewed at https://www.scichart.com/profile |
| 24 | + // |
| 25 | + // e.g. |
| 26 | + // SciChartSurface.setRuntimeLicenseKey("YOUR_RUNTIME_KEY"); |
| 27 | + const { wasmContext, sciChartSurface } = await SciChartSurface.create('scichart-root'); |
| 28 | + const xAxis = new NumericAxis(wasmContext); |
| 29 | + xAxis.labelProvider.precision = 0; |
| 30 | + sciChartSurface.xAxes.add(xAxis); |
| 31 | + const yAxis = new NumericAxis(wasmContext); |
| 32 | + yAxis.growBy = new NumberRange(0, 0.1); |
| 33 | + sciChartSurface.yAxes.add(yAxis); |
| 34 | + |
| 35 | + const dataSeries1 = new XyDataSeries(wasmContext, { xValues, yValues: tomatoesData1, dataSeriesName: 'Tomato' }); |
| 36 | + const dataSeries2 = new XyDataSeries(wasmContext, { xValues, yValues: cucumberData2, dataSeriesName: 'Cucumber' }); |
| 37 | + const dataSeries3 = new XyDataSeries(wasmContext, { xValues, yValues: pepperData3, dataSeriesName: 'Pepper' }); |
| 38 | + const rendSeries1 = new StackedColumnRenderableSeries(wasmContext); |
| 39 | + rendSeries1.fill = '#dc443f'; |
| 40 | + rendSeries1.stroke = 'black'; |
| 41 | + rendSeries1.strokeThickness = 1; |
| 42 | + rendSeries1.dataSeries = dataSeries1; |
| 43 | + rendSeries1.rolloverModifierProps.markerColor = '#b83735'; |
| 44 | + rendSeries1.rolloverModifierProps.tooltipColor = '#dc443f'; |
| 45 | + rendSeries1.rolloverModifierProps.tooltipTextColor = '#fff'; |
| 46 | + rendSeries1.stackedGroupId = 'one'; |
| 47 | + |
| 48 | + const rendSeries2 = new StackedColumnRenderableSeries(wasmContext); |
| 49 | + rendSeries2.fill = '#aad34f'; |
| 50 | + rendSeries2.stroke = 'black'; |
| 51 | + rendSeries2.strokeThickness = 1; |
| 52 | + rendSeries2.dataSeries = dataSeries2; |
| 53 | + rendSeries2.rolloverModifierProps.markerColor = '#87a73e'; |
| 54 | + rendSeries2.rolloverModifierProps.tooltipColor = '#aad34f'; |
| 55 | + rendSeries2.rolloverModifierProps.tooltipTextColor = '#000'; |
| 56 | + rendSeries2.stackedGroupId = 'two'; |
| 57 | + |
| 58 | + const rendSeries3 = new StackedColumnRenderableSeries(wasmContext); |
| 59 | + rendSeries3.fill = '#8562b4'; |
| 60 | + rendSeries3.stroke = 'black'; |
| 61 | + rendSeries3.strokeThickness = 1; |
| 62 | + rendSeries3.dataSeries = dataSeries3; |
| 63 | + rendSeries3.rolloverModifierProps.markerColor = '#715195'; |
| 64 | + rendSeries3.rolloverModifierProps.tooltipColor = '#8562b4'; |
| 65 | + rendSeries3.rolloverModifierProps.tooltipTextColor = '#fff'; |
| 66 | + rendSeries3.stackedGroupId = 'three'; |
| 67 | + |
| 68 | + const verticallyStackedColumnCollection = new StackedColumnCollection(wasmContext); |
| 69 | + verticallyStackedColumnCollection.dataPointWidth = 0.5; |
| 70 | + verticallyStackedColumnCollection.zeroLineY = 0; |
| 71 | + verticallyStackedColumnCollection.add(rendSeries1, rendSeries2, rendSeries3); |
| 72 | + |
| 73 | + sciChartSurface.renderableSeries.add(verticallyStackedColumnCollection); |
| 74 | + |
| 75 | + // Collection for threshold |
| 76 | + const yValues0_1: number[] = []; |
| 77 | + for (let i = 0; i < xValues.length; i++) yValues0_1.push(tomatoesData1[i] > THRESHOLD ? tomatoesData1[i] : NaN); |
| 78 | + const dataSeries0_1 = new XyDataSeries(wasmContext, { xValues, yValues: yValues0_1, dataSeriesName: 'Threshold' }); |
| 79 | + const rendSeries0_1 = new StackedColumnRenderableSeries(wasmContext, { |
| 80 | + fill: 'red', |
| 81 | + stroke: 'black', |
| 82 | + dataSeries: dataSeries0_1, |
| 83 | + stackedGroupId: '1' |
| 84 | + }); |
| 85 | + |
| 86 | + const yValues0_2: number[] = []; |
| 87 | + for (let i = 0; i < xValues.length; i++) yValues0_2.push(cucumberData2[i] > THRESHOLD ? cucumberData2[i] : NaN); |
| 88 | + const dataSeries0_2 = new XyDataSeries(wasmContext, { xValues, yValues: yValues0_2, dataSeriesName: 'Threshold' }); |
| 89 | + const rendSeries0_2 = new StackedColumnRenderableSeries(wasmContext, { |
| 90 | + fill: 'red', |
| 91 | + stroke: 'black', |
| 92 | + dataSeries: dataSeries0_2, |
| 93 | + stackedGroupId: '2' |
| 94 | + }); |
| 95 | + |
| 96 | + const yValues0_3: number[] = []; |
| 97 | + for (let i = 0; i < xValues.length; i++) yValues0_3.push(pepperData3[i] > THRESHOLD ? pepperData3[i] : NaN); |
| 98 | + const dataSeries0_3 = new XyDataSeries(wasmContext, { xValues, yValues: yValues0_3, dataSeriesName: 'Threshold' }); |
| 99 | + const rendSeries0_3 = new StackedColumnRenderableSeries(wasmContext, { |
| 100 | + fill: 'red', |
| 101 | + stroke: 'black', |
| 102 | + dataSeries: dataSeries0_3, |
| 103 | + stackedGroupId: '3' |
| 104 | + }); |
| 105 | + const verticallyStackedColumnCollection0 = new StackedColumnCollection(wasmContext); |
| 106 | + verticallyStackedColumnCollection0.dataPointWidth = 0.5; |
| 107 | + verticallyStackedColumnCollection0.zeroLineY = THRESHOLD; |
| 108 | + verticallyStackedColumnCollection0.add(rendSeries0_1, rendSeries0_2, rendSeries0_3); |
| 109 | + sciChartSurface.renderableSeries.add(verticallyStackedColumnCollection0); |
| 110 | + |
| 111 | + const rm = new RolloverModifier(); |
| 112 | + // Exclude threshold series to hide tooltips |
| 113 | + rm.includeSeries(rendSeries0_1, false); |
| 114 | + rm.includeSeries(rendSeries0_2, false); |
| 115 | + rm.includeSeries(rendSeries0_3, false); |
| 116 | + |
| 117 | + sciChartSurface.chartModifiers.add( |
| 118 | + new ZoomExtentsModifier(), |
| 119 | + new ZoomPanModifier(), |
| 120 | + new MouseWheelZoomModifier(), |
| 121 | + rm |
| 122 | + ); |
| 123 | +} |
| 124 | + |
| 125 | +initSciChart(); |
0 commit comments