How to start a line chart with 0 X-Axis

I am creating a line chart, but I want the chart to start at 0 on the X axis. How can I do this.

I'm trying some kind of method, but still haven't got what I want.

Chart1.ChartAreas[0].AxisX.Interval = 0;

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

Chart1.ChartAreas[0].AxisX.Minimum = 0;

Chart1.ChartAreas[0].AxisX.Crossing = 0;

This is what I do now

enter image description here

This is what I want

enter image description here

And one more, how can I set the primary and secondary unit in the diagram.?

my code is here

protected void Page_Load(object sender, EventArgs e)
    {
        System.Drawing.Font axisFont = new System.Drawing.Font("Arial", 8, System.Drawing.FontStyle.Bold);
        System.Drawing.Font titleFont = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold);

        Chart1.Width = 600;
        Chart1.Height = 400;
        Chart1.BorderlineColor = System.Drawing.Color.Black;
        Chart1.BorderlineWidth = 1;
        Chart1.BorderlineDashStyle = ChartDashStyle.Solid;

        double[] min = { 60.9, 0, 28.81, 7.27 };
        double[] ave = { 60.9, 0, 28.81, 7.27 };
        double[] max = { 5167.72, 1.27, 4176.16, 2566.59 };


        Chart1.Series["Series1"].ChartArea = "ChartArea1";
        Chart1.Series["Series2"].ChartArea = "ChartArea1";
        Chart1.Series["Series3"].ChartArea = "ChartArea1";

        Chart1.Series["Series1"].Points.AddXY("Step 1-2", max[0]);
        Chart1.Series["Series2"].Points.AddXY("Step 1-2", ave[0]);
        Chart1.Series["Series3"].Points.AddXY("Step 1-2", min[0]);

        Chart1.Series["Series1"].Points.AddXY("Step 2-3", max[1]);
        Chart1.Series["Series2"].Points.AddXY("Step 2-3", ave[1]);
        Chart1.Series["Series3"].Points.AddXY("Step 2-3", min[1]);

        Chart1.Series["Series1"].Points.AddXY("Step 3-4", max[2]);
        Chart1.Series["Series2"].Points.AddXY("Step 3-4", ave[2]);
        Chart1.Series["Series3"].Points.AddXY("Step 3-4", min[2]);

        Chart1.Series["Series1"].Points.AddXY("Step 4-5", max[3]);
        Chart1.Series["Series2"].Points.AddXY("Step 4-5", ave[3]);
        Chart1.Series["Series3"].Points.AddXY("Step 4-5", min[3]);
        String hour1 = "hh";
        Chart1.Titles.Add("Cycle Time : "+hour1);
        Chart1.Titles[0].Font = titleFont;

        Chart1.Series["Series1"].MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Triangle;
        Chart1.Series["Series2"].MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Square;
        Chart1.Series["Series3"].MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Diamond;
        Chart1.Series["Series1"].MarkerSize = 15;
        Chart1.Series["Series2"].MarkerSize = 15;
        Chart1.Series["Series3"].MarkerSize = 15;
        Chart1.Legends.Add("Legend1");


        Chart1.Series["Series1"].LegendText = "Max";
        Chart1.Series["Series2"].LegendText = "Ave";
        Chart1.Series["Series3"].LegendText = "Min";

        Chart1.Series["Series1"].Legend = "Legend1";
        Chart1.Series["Series2"].Legend = "Legend1";
        Chart1.Series["Series3"].Legend = "Legend1";
        Chart1.Series["Series1"].IsVisibleInLegend = true;
        Chart1.Series["Series2"].IsVisibleInLegend = true;
        Chart1.Series["Series3"].IsVisibleInLegend = true;

         //This part I try to make the graph start from 0 in X-axis but not work
        //Chart1.ChartAreas[0].AxisX.Interval = 0;
        //Chart1.ChartAreas[0].AxisX.IsStartedFromZero = true;
        //Chart1.ChartAreas[0].AxisX.Minimum = 0;
        //Chart1.ChartAreas[0].AxisX.Crossing = 0;
        //Chart1.ChartAreas[0].AxisX.Minimum = 0;
        //Chart1.ChartAreas[0].Position.Auto = false;


        Chart1.ChartAreas[0].AxisX.TitleFont = axisFont;
        Chart1.ChartAreas[0].AxisY.TitleFont = axisFont;

        Chart1.ChartAreas[0].AxisX.Title = "Step";
        Chart1.ChartAreas[0].AxisY.Title = "Time (" + hour1 + ")";


        Chart1.ChartAreas[0].BackColor = System.Drawing.Color.AliceBlue;
        Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
        Chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.ColorTranslator.FromHtml("#D5E8F5");


    }
+4
source share
2 answers

I had a similar problem, and it turned out that the solution is to set the IsMarginVisible flag to false:

chart1.ChartAreas[0].AxisX.IsMarginVisible = false;

Hope this helps.

+11
source

Chart , , , , .

, (-1,0), X-Axis 0, ? , ? ?

2 , X Y.

, , ( 3 * 1-3 * s).

, , , 0.

0?

: 0.

, -

        Chart1.Series["Series1"].Points.AddXY(string.Empty, 1.0);
        Chart1.Series["Series2"].Points.AddXY(string.Empty, 2.0);
        Chart1.Series["Series3"].Points.AddXY(string.Empty, 3.0);

1, .

.

:

Chart1.Series["SeriesMin"].Points.AddXY(0, max[0]);
Chart1.Series["SeriesAve"].Points.AddXY(0, ave[0]);
Chart1.Series["SeriesMax"].Points.AddXY(0, min[0]);

Chart1.Series["SeriesMin"].Points[0].AxisLabel = "Step 1-2";
Chart1.Series["SeriesAve"].Points[0].AxisLabel = "Step 1-2";
Chart1.Series["SeriesMax"].Points[0].AxisLabel = "Step 1-2";

Chart1.ChartAreas[0].AxisX.Interval = 0;
Chart1.ChartAreas[0].AxisX.IsStartedFromZero = true;
Chart1.ChartAreas[0].AxisX.Minimum = 0;
Chart1.ChartAreas[0].AxisX.Crossing = 0;
Chart1.ChartAreas[0].AxisX.Minimum = 0;
//Chart1.ChartAreas[0].Position.Auto = false; //EXCEPT THIS ONE!!

, , db.

+3

Source: https://habr.com/ru/post/1541204/


All Articles