简体   繁体   中英

C# - How do you make a chart object start at 0 on the X axis?

I've been trying to set the position on the X axis from which the data starts getting plotted with no luck. It always start at 1 no matter what. I've tried doing

chartArea.AxisX.Minimum = -1;
chartArea.AxisX.Maximum = 5;

But it doesn't work. Even if I do:

chartArea.AxisX.Minimum = 3;
chartArea.AxisX.Maximum = 6;

The bars will be invisible rather than start at 3.

manaCurveChart.ChartAreas[0].AxisX.IsStartedFromZero = true;

Doesn't seem to do anything either.

EDIT: Here's the code

            ChartArea chartArea = manaCurveChart.ChartAreas[0];
            chartArea.AxisX.IsStartedFromZero = true;
            chartArea.AxisX.Minimum = -1;
            chartArea.AxisX.Maximum = 5;

            string[] Pets = new string[] { "Dog", "Cat" };
            int[] PointArray = new int[] { 1, 2 };

            manaCurveChart.Titles.Add("Pets");
            for (int i = 0; i < Pets.Length; i++)
            {
                Series series = manaCurveChart.Series.Add(Pets[i]);
                series.Points.Add(PointArray[i]);
            }

Instead of doing

series.Points.Add(PointArray[i]); 

(where the x value is determined automatically), use

series.Points.AddXY(i, PointArray[i]);

so the x value is specified explicitly. It forces the x axis to have a minimum of 0, and you can then set your min/max/intervals as desired (or leave them to be determined automatically).

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