简体   繁体   English

使用 MouseWheel c# winform 绘制图表水平滚动

[英]Chart Horizontal Scroll with MouseWheel c# winform

i have a problem with my code that i cannot solve:我的代码有一个无法解决的问题:

i have a stacked column chart with indexed x value for the two series that make the chart, i need to scroll horizontally the chart, so i have written this code:我有一个堆积柱形图,其中包含制作图表的两个系列的索引 x 值,我需要水平滚动图表,所以我编写了以下代码:

(first in the initialization part) (首先在初始化部分)

this.CHART.MouseWheel += CHART_MouseWheel1;

(and then the function part) (然后是功能部分)

    private void CHART_MouseWheel1(object sender, MouseEventArgs e)
    {
        try
        {
            if (e.Delta > 0)
            {
                if (this.CHART.ChartAreas[0].AxisX.ScaleView.Position < this.CHART.ChartAreas[0].AxisX.Maximum)
                {
                    this.CHART.ChartAreas[0].AxisX.ScaleView.Position = this.CHART.ChartAreas[0].AxisX.ScaleView.Position + 1;
                }
            }
            else if (e.Delta < 0)
            {
                if (this.CHART.ChartAreas[0].AxisX.ScaleView.Position > this.CHART.ChartAreas[0].AxisX.Minimum)
                {
                    this.CHART.ChartAreas[0].AxisX.ScaleView.Position = this.CHART.ChartAreas[0].AxisX.ScaleView.Position - 1;
                }
            }
        }
        catch { }
    }

but for some reason my maximum value this.CHART.ChartAreas[0].AxisX.Maximum exceed the maximum number of the points in the series so i end up with something like this when i scroll to much:但由于某种原因,我的最大值this.CHART.ChartAreas[0].AxisX.Maximum超过了系列中的最大点数,所以当我滚动到很多时,我最终会得到这样的结果:

chart visualization in runtime运行时图表可视化

and i cannot see any relation between my maximum value for the scrolling and the number of point in the series我看不到滚动的最大值与系列中的点数之间的任何关系

i also think that i need to tell you that i have this.CHART.ChartAreas[0].AxisX.IsMarginVisible = true;我也认为我需要告诉你我有this.CHART.ChartAreas[0].AxisX.IsMarginVisible = true; enabled.启用。

hope to solve this also because i am very close to finish my project.希望解决这个问题也因为我非常接近完成我的项目。

ty all in advance全部提前

Hiii guys i found an answer to my problem by myself after trying lots of things, and the main things is that the series X values needs to be indexed, and that make a lot of things easier because you will now work with number of point and not with, in my case, a datetime value, soo that is the code:嗨,伙计们,我在尝试了很多事情之后自己找到了我的问题的答案,主要是需要对系列 X 值进行索引,这使很多事情变得更容易,因为您现在将使用点数和没有,在我的情况下,一个日期时间值,所以这就是代码:

        private void CHART1_MouseWheel(object sender, MouseEventArgs e)
    {
        try
        {
            if (this.CHART1.Series["S1"].Points.Count > 10)
            {
                if (e.Delta > 0)
                {
                    if (this.CHART1.ChartAreas[0].AxisX.ScaleView.Position < this.CHART1.ChartAreas[0].AxisX.Maximum - this.CHART1.ChartAreas[0].AxisX.ScaleView.Size - 1)
                    {
                        this.CHART1.ChartAreas[0].AxisX.ScaleView.Position = this.CHART1.ChartAreas[0].AxisX.ScaleView.Position + 1;
                    }
                }
                else if (e.Delta < 0)
                {
                    if (this.CHART1.ChartAreas[0].AxisX.ScaleView.Position > 1)
                    {
                        this.CHART1.ChartAreas[0].AxisX.ScaleView.Position = this.CHART1.ChartAreas[0].AxisX.ScaleView.Position - 1;
                    }
                }
            }
        }
        catch (System.Exception ex)
        {
            throw ex;
        }
    }

i hope that i have helped same problem tyall我希望我已经帮助了同样的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM