|
| 1 | +import { SciChartSurface } from 'scichart/Charting/Visuals/SciChartSurface'; |
| 2 | +import { NumericAxis } from 'scichart/Charting/Visuals/Axis/NumericAxis'; |
| 3 | +import { FastLineRenderableSeries } from 'scichart/Charting/Visuals/RenderableSeries/FastLineRenderableSeries'; |
| 4 | +import { XyDataSeries } from 'scichart/Charting/Model/XyDataSeries'; |
| 5 | +import { NumberRange } from 'scichart/Core/NumberRange'; |
| 6 | +import { ZoomPanModifier } from 'scichart/Charting/ChartModifiers/ZoomPanModifier'; |
| 7 | +import { MouseWheelZoomModifier } from 'scichart/Charting/ChartModifiers/MouseWheelZoomModifier'; |
| 8 | +import { ZoomExtentsModifier } from 'scichart/Charting/ChartModifiers/ZoomExtentsModifier'; |
| 9 | +import { XyCustomFilter } from 'scichart/Charting/Model/Filters/XyCustomFilter'; |
| 10 | +import { RolloverModifier } from 'scichart/Charting/ChartModifiers/RolloverModifier'; |
| 11 | +import { CursorModifier } from 'scichart/Charting/ChartModifiers/CursorModifier'; |
| 12 | + |
| 13 | +async function initSciChart() { |
| 14 | + // Create the SciChartSurface in the div 'scichart-root' |
| 15 | + // The SciChartSurface, and webassembly context 'wasmContext' are paired. This wasmContext |
| 16 | + // instance must be passed to other types that exist on the same surface. |
| 17 | + const { sciChartSurface, wasmContext } = await SciChartSurface.create('scichart-root'); |
| 18 | + // Create an X,Y Axis and add to the chart |
| 19 | + sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { visibleRange: new NumberRange(0,100), labelPrecision: 0, axisTitle: "Percentile" })); |
| 20 | + sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { growBy: new NumberRange(0.1, 0.1), labelPrecision: 0, axisTitle:"Wealth" })); |
| 21 | + |
| 22 | + const dataSeries = new XyDataSeries(wasmContext); |
| 23 | + // Generate data that approximates real world wealth distribution |
| 24 | + let y = -1000; |
| 25 | + for (let x = 1; x <= 100; x++) { |
| 26 | + if (x < 10) { |
| 27 | + y = y / 2; |
| 28 | + } else if (x < 80) { |
| 29 | + y = y + 1; |
| 30 | + } else { |
| 31 | + y = y*1.4; |
| 32 | + } |
| 33 | + dataSeries.append(x,y); |
| 34 | + } |
| 35 | + const lineSeries1 = new FastLineRenderableSeries(wasmContext, { |
| 36 | + stroke: 'white', |
| 37 | + dataSeries |
| 38 | + }); |
| 39 | + sciChartSurface.renderableSeries.add(lineSeries1); |
| 40 | + sciChartSurface.chartModifiers.add(new CursorModifier()); |
| 41 | + |
| 42 | + // Create Transformed chart |
| 43 | + const { sciChartSurface: sciChartSurface2, wasmContext: wasmContext2 } = await SciChartSurface.create('scichart-root2'); |
| 44 | + sciChartSurface2.xAxes.add(new NumericAxis(wasmContext2, { visibleRange: new NumberRange(0,100), labelPrecision: 0, axisTitle: "Percentile" })); |
| 45 | + sciChartSurface2.yAxes.add(new NumericAxis(wasmContext, { growBy: new NumberRange(0.1, 0.1), axisTitle:"Transformed Wealth" })); |
| 46 | + |
| 47 | + // Inverse hyperbolic sine filter |
| 48 | + const ihsFilter = new XyCustomFilter(dataSeries, { filterFunction: ((i, y) => Math.log(y + Math.sqrt(1 + y*y))) }); |
| 49 | + |
| 50 | + const lineSeriesTransformed = new FastLineRenderableSeries(wasmContext, { |
| 51 | + stroke: 'white', |
| 52 | + dataSeries: ihsFilter |
| 53 | + }); |
| 54 | + sciChartSurface2.renderableSeries.add(lineSeriesTransformed); |
| 55 | + sciChartSurface2.chartModifiers.add(new CursorModifier()); |
| 56 | +} |
| 57 | + |
| 58 | +initSciChart(); |
0 commit comments