How to align two (or more) charts in size, scroll and grid

前端 未结 1 696
执念已碎
执念已碎 2021-01-03 14:40

I have three signals (volgate, current, and energy) referred to the same period. I print data on two graphs: one with voltage (blue) and current (red) and the other with onl

1条回答
  •  醉梦人生
    2021-01-03 15:00

    I recommend using only one chart. You can add a 2nd ChartArea to it and make it the one your 3rd series is using.

    Given your identical x-axes this should be the simplest and cleanest solution.

    To enable scrolling, as usual one needs to set these properties:

            ChartArea ca1 = chart1.ChartAreas[0];
            ChartArea ca2 = chart1.ChartAreas[1];
    
            Axis ax1 = ca1.AxisX;
            Axis ax2 = ca2.AxisX;
    
            series3.ChartArea = ca2.Name;
    
            ax1.ScaleView.Zoomable = true;
            ax2.ScaleView.Zoomable = true;
    
            ca1.CursorX.IsUserSelectionEnabled = true;
            ca2.CursorX.IsUserSelectionEnabled = true;
    

    To keep two ChartAreas in synch this should be enough:

    private void chart1_AxisViewChanged(object sender, ViewEventArgs e)
    {
        ChartArea ca1 = chart1.ChartAreas[0];
        ChartArea ca2 = chart1.ChartAreas[1];
        Axis ax1 = ca1.AxisX;
        Axis ax2 = ca2.AxisX;
    
        if (e.Axis== ax1) { ax2.ScaleView.Size = ax1.ScaleView.Size;
                            ax2.ScaleView.Position = ax1.ScaleView.Position;  }
        if (e.Axis== ax2) { ax1.ScaleView.Size = ax2.ScaleView.Size;
                            ax1.ScaleView.Position = ax2.ScaleView.Position;   }
    }
    

    0 讨论(0)
提交回复
热议问题