I’m using an example of RealtimeTickingStockCharts
I’ve added a modifier
new YAxisDragModifier({
dragMode: EDragMode.Scaling,
}),
I see icon changed to arrows but scaling does not work. What should I check ?
- Ivan Skiridomov asked 1 month ago
- last edited 1 month ago
- You must login to post comments
Hi Ivan
In this demo the YAxis is declared with AutoRange = EAutoRange.Always
. See Line #60 in the source code
// Create a NumericAxis on the YAxis with 2 Decimal Places
sciChartSurface.yAxes.add(
new NumericAxis(wasmContext, {
growBy: new NumberRange(0.1, 0.1),
labelFormat: ENumericFormat.Decimal,
labelPrecision: 2,
labelPrefix: "$",
autoRange: EAutoRange.Always
})
);
AutoRange.Always means ‘always autorange, always, to fit the data, always’ – even if you put modifiers like YAxisDragModifier
on the chart
How to handle the ability to autorange (fit new data) while allowing scrolling or panning of an axis? You need a way to toggle between the two modes.
Simple solution
The simple solution is to set yAxis.autoRange = EAutoRange.Once
. This will fit the data once on startup. Also when changing the data on the chart, call sciChartSurface.zoomExtents()
to manually fit the data.
Better / but more Complex Solution
A better solution would be to toggle between the two modes. Consider how TradingView does this.
- When the chart starts up, it is in
yAxis.autoRange = EAutoRange.Always
mode - When the user mouse-down on the yAxis, you set
yAxis.autoRange = EAutoRange.Never
, allowing the yAxis drag to work. Here is how to detect mouse-down on axis. - The user must then click a button to re-enable auto ranging on the Y-Axis by setting
yAxis.autoRange = EAutoRange.Always
again
Let me know if this helps
Best regards
Andrew
- Andrew Burnett-Thompson answered 1 month ago
- last edited 1 month ago
- You must login to post comments
Please login first to submit.