Larry
Larry

Reputation: 18031

How to really scroll and zoom a MS Chart controls?

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.

Upvotes: 1

Views: 3472

Answers (2)

RyanC
RyanC

Reputation: 31

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;
}

Upvotes: 1

Larry
Larry

Reputation: 18031

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

Upvotes: 1

Related Questions