简体   繁体   中英

how to enable auto scaling property in chart control using c#

In my application im having a chart control that is working fine. For every 1 second updating the x-Axis values and y-axis values in the chart. I want to enable auto scaling for the chart control programmatically for y axis. Please refer my code below,

chart1.Series.Clear();
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;

series1.Name = "Series1";
series1.MarkerStyle = MarkerStyle.Circle;
series1.MarkerColor = Color.BlueViolet;
series1.MarkerSize = 10;
series1.Color = System.Drawing.Color.Green;            
series1.IsXValueIndexed = true;
series1.YAxisType = AxisType.Primary;
series1.ChartType = SeriesChartType.Line;
this.chart1.Series.Add(series1);

How to enable auto scaling programmatically.

chart1.Series.Clear();
        chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
        chart1.ChartAreas[0].RecalculateAxesScale();

        series1.Name = "Series1";
        series1.MarkerStyle = MarkerStyle.Circle;
        series1.MarkerColor = Color.BlueViolet;
        series1.MarkerSize = 10;
        series1.Color = System.Drawing.Color.Green;
        //series1.IsVisibleInLegend = false;
        series1.IsXValueIndexed = true;
        //series1.XValueType = ChartValueType.Time;
        series1.YAxisType = AxisType.Primary;
        series1.ChartType = SeriesChartType.Line;
        this.chart1.Series.Add(series1);

Working fine

chart.ChartAreas[0].AxisY.Maximum = Double.NaN;

但是有些人在使用上述方法时会遇到麻烦,因此如果不起作用,请尝试此方法

chart.ChartAreas[0].RecalculateAxesScale();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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