How to do aligned scrolling through two chart areas without using AlignToChartArea?

倖福魔咒の 提交于 2019-12-08 02:54:03

问题


I have two ChartArea objects in a Chart (System.Windows.Forms.DataVisualization.Charting is what I'm using).

One is a Point graph, and the other is a RangeBar graph. The horizontal axis on the RangeBar graph is actually the Y axis, so I cannot just use something like this:

Chart1.ChartAreas["Chart Area 2"].AlignWithChartArea = "Default";

I've figured out how to zoom both charts and keep them aligned, but when I try to scroll both charts by clicking on the scrollbar on one of the horizontal axes, I can't quite get it to line up. They almost line up, but they're off by maybe a second or so (the horizontal axis in both graphs is time).

Here's what I have:

private void theChart_AxisViewChanged(object sender, ViewEventArgs e)
{
    if (e.ChartArea == theChart.ChartAreas["MyPointChartArea"])
    {
        theChart.ChartAreas["MyRangeBarChartArea"].AxisY.ScaleView.Position = e.NewPosition;
        theChart.ChartAreas["MyRangeBarChartArea"].AxisY.ScaleView.Size = e.NewSize;
        theChart.ChartAreas["MyRangeBarChartArea"].AxisY.ScaleView.SizeType = e.NewSizeType;
    }
    if (e.ChartArea == theChart.ChartAreas["MyRangeBarChartArea"])
    {
        theChart.ChartAreas["MyPointChartArea"].AxisX.ScaleView.Position = e.NewPosition;
        theChart.ChartAreas["MyPointChartArea"].AxisX.ScaleView.Size = e.NewSize;
        theChart.ChartAreas["MyPointChartArea"].AxisX.ScaleView.SizeType = e.NewSizeType;
    }
}

What else do I need to do to get the charts to line up? The physical extent of the charts is the same. It's just the data that are slightly misaligned.

Thanks for any help.

来源:https://stackoverflow.com/questions/5957157/how-to-do-aligned-scrolling-through-two-chart-areas-without-using-aligntochartar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!