enez2692
enez2692

Reputation: 77

Synchronized Panning Two Chart Areas

I have one chart with two areas. When I zoom or slide on scroll bar one chart area, other chart area also zoom and sliding. I have been trying to add panning to my project. When I was searching I found MSChart Extension and I loved it(https://www.codeproject.com/Articles/357817/MSChart-Extension-Zoom-and-Pan-Control).

I want to use MSChart Extension but like I said I need to synchronize two chart areas. When I zoom one chart area, the other chart area must be zoomed or when I pan one area the other chart area must be panned automatically.

or I just need to add the panning feature instead of scroll bars without MSChart Extension.

Could you please help me for that?

I did it on standard chart code without mschart extension with following code piece It works with mouse wheel zoom and slide on scroll bars, but it does not sychronize two chart areas when I control chart with MSChart Extension (zoom and pan).

private void chart1_AxisViewChanged(object sender, ViewEventArgs e)
{
            if (e.Axis == chart1.ChartAreas["ChartArea1"].AxisX)
            {
                chart1.ChartAreas["ChartArea2"].AxisX.ScaleView.Size = chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Size;
                chart1.ChartAreas["ChartArea2"].AxisX.ScaleView.Position = chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Position;
            }

            if (e.Axis == chart1.ChartAreas["ChartArea2"].AxisX)
            {
                chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Size = chart1.ChartAreas["ChartArea2"].AxisX.ScaleView.Size;
                chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Position = chart1.ChartAreas["ChartArea2"].AxisX.ScaleView.Position;
            }
        }

Best kind regards,

Upvotes: 4

Views: 1061

Answers (1)

Baddack
Baddack

Reputation: 2053

If you have two chart areas, you can align them together with special properties like AxisView with the AlignWithChartArea and AlignmentStyle methods.

For example:

using System.Windows.Forms.DataVisualization.Charting;
...

// Make Chart Area 2 align to Chart Area 1
Chart1.ChartAreas["Chart Area 2"].AlignWithChartArea = "Default"; //or "ChartArea1"

// Set the alignment type
Chart1.ChartAreas["Chart Area 2"].AlignmentStyle = AreaAlignmentStyles.Position |
                                                AreaAlignmentStyles.PlotPosition |
                                                AreaAlignmentStyles.Cursor |
                                                AreaAlignmentStyles.AxesView;    
... 

Source: Microsoft Chart for Windows Forms Samples Environment

Upvotes: 4

Related Questions