如何MSChart的使用C#来设定在X轴值 [英] How to set values in x axis MSChart using C#

查看:1140
本文介绍了如何MSChart的使用C#来设定在X轴值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这些XY值:

Series S1 = new Series()
S1.Points.AddXY(9, 25);
S1.Points.AddXY(10, 35);
S1.Points.AddXY(11, 15);
chart1.Series.Add(S1);

但我需要显示在这样的图中的X值:

but I need to show the X values in the graph like this:

X =9-10

X =10-11

X =11-12

我怎样才能做到这一点?

How can I achieve that?

到目前为止,这是我发现:

So far this is what I've found:

和这里是code:

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

        Series S1 = new Series();
        S1.Points.AddXY(9, 25);
        S1.Points.AddXY(10, 35);
        S1.Points.AddXY(11, 15);
        chart1.Series.Add(S1);

        chart1.Series[0].Points[0].AxisLabel = "9-10";
        chart1.Series[0].Points[1].AxisLabel = "10-11";
        chart1.Series[0].Points[2].AxisLabel = "11-12";

你可以看到我对数字的工作,并设置文本为X轴标签,但我可以做的只是为数据点值,我需要它值的整个范围。

as you can see I work with numbers, and set texts for the X axis labels, but I can do that just for the DataPoints values, I need it for the whole range of values.

任何想法吗?

推荐答案

下面是答案感谢sipla:

Here is the answer thanks to sipla:

使用自定义标签和自定义事件的工作:

working with Custom labels and the Customize event:

string[] range = new string[10];

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

        range[0] = "";
        range[1] = "7-8";
        range[2] = "8-9";
        range[3] = "9-10";
        range[4] = "10-11";
        range[5] = "11-12";
        range[6] = "12-1";
        range[7] = "1-2";
        range[8] = "2-3";
        range[9] = "";

        Series S1 = new Series();            
        S1.Points.AddXY(9, 25);
        S1.Points.AddXY(10, 35);
        S1.Points.AddXY(11, 15);
        chart1.Series.Add(S1);            

    }

    int count;
    private void chart1_Customize(object sender, EventArgs e)
    {
        count = 0;
        foreach (CustomLabel lbl in chart1.ChartAreas[0].AxisX.CustomLabels)
        {
            lbl.Text = range[count];
            count++;
        }                        
    }

这篇关于如何MSChart的使用C#来设定在X轴值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆