为什么图表控件不显示任何数据?

时间:2015-11-16 19:03:03

标签: c# charts

我想制作即时充电时间图,但图表没有显示任何内容。

我做错了什么?

这是我输出的代码和快照:

namespace WindowsFormsApplication21
    {
        public partial class Form1 : Form
        {
            public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            double max = 24000000, min = 23999999.85;
            chart1.ChartAreas.Add("0");
            chart1.ChartAreas[0].AxisY.Minimum = min;
            chart1.ChartAreas[0].AxisY.Maximum = max;
            chart1.Series[0].Color = Color.Red;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            double[] q = new double[10];
            for (int i = 0; i < q.Length; i++)
            {
                int t = i + 1;
                q[i] = (24 * Math.Pow(10, 6)) * Math.Exp(t / (2000 * Math.Pow(10,6)));
                chart1.Series[0].Points.AddXY(t, q[i]);
            }
        }
        }
    }

这是我的输出

1 个答案:

答案 0 :(得分:0)

正如您所看到的,您的数据根本不适合这些值;所有都超过24M,这是你显示的最大值。

您不应该尝试对这些值进行硬编码。他们今天可能会工作,并停止使用下一组数据。

以下是在代码中设置它们的方法,添加DataPoints之后

ChartArea CA = chart1.ChartAreas[0];
Series S1 = chart1.Series[0];

CA.AxisY.Maximum = S1.Points.Max(x => x.YValues[0]);
CA.AxisY.Minimum = S1.Points.Min(x => x.YValues[0]);

CA.AxisY.LabelStyle.Format = "###,###,###,##0.000";

enter image description here

(我的系统显示德语本地化的小数点。)

相关问题