Home > front end >  Chart Horizontal Scroll with MouseWheel c# winform
Chart Horizontal Scroll with MouseWheel c# winform

Time:11-23

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:

(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:

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; enabled.

hope to solve this also because i am very close to finish my project.

ty all in advance

CodePudding user response:

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:

        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

  • Related