I have a simple columns chart. The user can use a button that will basically change the data entirely.
The chartsurface has SeriesSource binded. Reassigning the series is changing the data on the chart, but the X-Axis is not being refreshed, so the data is showing up on the wrong part of the chart.
I uploaded 2 images to show the problem. In the “after” image, the long column should actually be at the “10+” label. If I open the same data in a new chart it shows correctly.
What’s the best method to entirely refresh a chart’s data?
Thanks in advance
It sounds like your chart is using its default AutoRange behaviour of AutoRange.Auto to detect when to range. Take a look at this article: AutoRange.Never vs AutoRange.Auto vs AutoRange.Always
The default state of the chart is AutoRange.Auto, which means ‘When I start up, autorange the chart if it does not have a valid VisibleRange’.
When you set new data on the chart the old VisibleRange exists on the axis, so the axis believes it is valid. There are a few ways to solve this:
set AutoRange.Always on the axis. This will force it to reset its range each time data changes, but you will not be able to zoom in using Modifiers (since AutoRange overrides mouse-zoom).
call ScIChartSurface.ZoomExtents(), or use a ViewportManager to reset zoom after setting data. In an MVVM scenario this is tricky since you don’t know when the data has bound and you need to zoom to fit after the data is bound.
Give the above suggestions a try and let me know your feedback in the comments.
Please login first to submit.