本文介绍了如何从0 X轴使线图开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个折线图,但我想显示图表从0开始的X轴。我怎样才能做到这一点。

我尝试一些方法,但还是没有得到我想要的。

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

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

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

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

这就是我现在做的

这就是我想要的。

和一多,我怎么能在图表中设定的主要和次要单元..?

我的code此处

 保护无效的Page_Load(对象发件人,EventArgs的)
    {
        System.Drawing.Font axisFont =新System.Drawing.Font(宋体,8,System.Drawing.FontStyle.Bold);
        System.Drawing.Font titleFont =新System.Drawing.Font(宋体,10,System.Drawing.FontStyle.Bold);

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

        双[]分钟= {60.9,0,28.81,7.27};
        双[]平均= {60.9,0,28.81,7.27};
        双[]最大= {5167.72,1.27,4176.16,2566.59};


        Chart1.Series [系列1] ChartArea =ChartArea1。
        Chart1.Series [系列2] ChartArea =ChartArea1。
        Chart1.Series [系列3] ChartArea =ChartArea1。

        Chart1.Series [系列1] Points.AddXY(步骤1-2,最大值[0])。
        Chart1.Series [系列2] Points.AddXY(步骤1-2,大道[0])。
        Chart1.Series [系列3] Points.AddXY(步骤1-2,最小值[0])。

        Chart1.Series [系列1] Points.AddXY(步骤2-3,最大值[1])。
        Chart1.Series [系列2] Points.AddXY(步骤2-3,大道[1])。
        Chart1.Series [系列3] Points.AddXY(步骤2-3,分[1])。

        Chart1.Series [系列1] Points.AddXY(步骤3-4,最大值[2])。
        Chart1.Series [系列2] Points.AddXY(步骤3-4,大街[2])。
        Chart1.Series [系列3] Points.AddXY(步骤3-4,最小值[2])。

        Chart1.Series [系列1] Points.AddXY(步骤4-5,最大值[3])。
        Chart1.Series [系列2] Points.AddXY(步骤4-5,大街[3])。
        Chart1.Series [系列3] Points.AddXY(步骤4-5,最小值[3])。
        字符串hour1 =HH;
        Chart1.Titles.Add(周期时间:+ hour1);
        Chart1.Titles [0] .Font = titleFont;

        Chart1.Series [系列1] MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Triangle。
        Chart1.Series [系列2] MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Square。
        Chart1.Series [系列3] MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Diamond。
        Chart1.Series [系列1] MarkerSize = 15。
        Chart1.Series [系列2] MarkerSize = 15。
        Chart1.Series [系列3] MarkerSize = 15。
        Chart1.Legends.Add(Legend1);


        Chart1.Series [系列1] LegendText =最大。
        Chart1.Series [系列2] LegendText =大道。
        Chart1.Series [系列3] LegendText =最小。

        Chart1.Series [系列1] =传奇Legend1。
        Chart1.Series [系列2] =传奇Legend1。
        Chart1.Series [系列3] =传奇Legend1。
        Chart1.Series [系列1] IsVisibleInLegend = TRUE。
        Chart1.Series [系列2] IsVisibleInLegend = TRUE。
        Chart1.Series [系列3] IsVisibleInLegend = TRUE。

         //这部分我尽量让图从0开始的X轴,但无法正常工作
        //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 =步骤;
        Chart1.ChartAreas [0] .AxisY.Title =时间(+ 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);


    }
 

解决方案

我也有类似的问题,发现解决办法是设置IsMarginVisible标志设置为false:

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

希望这有助于。

I create a line chart, but I want to display the chart begin from 0 in X-axis.How can I do this.

I try some method but still did not get 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

This is what I want

And one more, how can I set major and minor unit in the chart..?

my code 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");


    }
解决方案

I had a similar issue, and found that the solution was to set the IsMarginVisible flag to false:

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

Hope this helps.

这篇关于如何从0 X轴使线图开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 08:22