最大轴x图表c#

时间:2018-11-14 10:31:22

标签: c# charts

我正在处理一个项目,其中有两个图,如果我看到x轴的最大值(24),则在下面的图上,但是在上面的图上则没有。如何使它出现在24岁?我在Visual Studio中使用图表窗口,Windows窗体中的默认图表

Chart image

   public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {

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

        for (int i = 0; i <= 24; i++)
        {
            chart1.Series[0].Points.AddXY(i,1+i);

        }

    }
}

1 个答案:

答案 0 :(得分:0)

将代码更改为(更多信息here):

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        // Maximum/Minimum controls the length of the Axis
        chart1.ChartAreas[0].AxisX.Maximum = 30;
        chart1.ChartAreas[0].AxisX.Minimum = 0;
        chart1.ChartAreas[0].AxisY.Maximum = 30;
        chart1.ChartAreas[0].AxisY.Minimum = 0;

        // Interval controls the interval between values on the chart
        chart1.ChartAreas[0].AxisX.Interval = 1;
        chart1.ChartAreas[0].AxisY.Interval = 1;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        chart1.ChartAreas[0].AxisX.Minimum = 0;

        for (int i = 0; i <= 24; i++)
        {
            chart1.Series[0].Points.AddXY(i, 1 + i);

        }
    }
}

图表如下:

enter image description here