Question

I am doing a trending application with the MS Chart controls 4.

I integrated zoom and scroll with the mouse wheel and the right button, which gives the control a unusual smoothness.

However, I relealize that the ChartArea.Axis methods ScaleView.Scroll and ScaleView.Zoom does actually not zooms nor scrolls the grid, the labels and the striplines.

Instead, it zooms and scrolls the point series but keeps the grids labels as is, and only adjusts the label values.

For example, if I want to scroll this sample chart to the right :

enter image description here

I have this.

enter image description here

Basically, this is what I want to achieve :

enter image description here

How can I achieve a real scrolling and zooming with the MS Chart controls ?

EDIT: I managed to get the wanted behavior by setting the X value to DateTimes. However, I would like to use doubles on the X axis.

Was it helpful?

Solution

It seems that this behavior is by design : only DateTime type axis values allows my chart to be scrolled smoothly.

OTHER TIPS

You can adjust the IntervalOffset manually based on the ScaleView.Position

Call this code whenever the chart is updated (e.g. on AxisViewChanged and AxisScrollBarClicked event)

if (chart1.ChartAreas[0].AxisY.ScaleView.IsZoomed)
{
    double offset = chart1.ChartAreas[0].AxisY.Minimum - chart1.ChartAreas[0].AxisY.ScaleView.Position;

    chart1.ChartAreas[0].AxisY.LabelStyle.IntervalOffset = offset;
    chart1.ChartAreas[0].AxisY.MajorGrid.IntervalOffset = offset;
    chart1.ChartAreas[0].AxisY.MajorTickMark.IntervalOffset = offset;
    chart1.ChartAreas[0].AxisY.MinorGrid.IntervalOffset = offset;
    chart1.ChartAreas[0].AxisY.MinorTickMark.IntervalOffset = offset;
}
else
{
    chart1.ChartAreas[0].AxisY.LabelStyle.IntervalOffset = 0;
    chart1.ChartAreas[0].AxisY.MajorGrid.IntervalOffset = 0;
    chart1.ChartAreas[0].AxisY.MajorTickMark.IntervalOffset = 0;
    chart1.ChartAreas[0].AxisY.MinorGrid.IntervalOffset = 0;
    chart1.ChartAreas[0].AxisY.MinorTickMark.IntervalOffset = 0;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top