您好我正在尝试让条形对齐x轴上的数字。如下图所示,图表中的条形图似乎向左或向右对齐。
[URL = HTTP://imageshack.us/photo/my-images/528/stackoverflowexample.png/] [IMG = HTTP://img528.imageshack.us/img528/19/stackoverflowexample.png] [/ IMG] [/ URL]
上传[URL = http://imageshack.us] ImageShack.us [/ URL]
我想知道是否有办法使用代码行使它们直接对齐数字1,2和3?
我也想知道是否可以将1,2和3更改为名称temprature,vcc和light ??
我已经做了一些调查并且无法找到如何纠正这个问题(正如你从我已经尝试的注释掉的代码行中看到的)这就是为什么我转向你们。我有在下面发布了我的代码(稍加修改,以便它可以在没有我的变量的任何c#中工作)。
感谢takin有时间阅读本文
chart1.ChartAreas.Add("area");
//chart1.ChartAreas["area"].AxisX.Minimum = 0;
//chart1.ChartAreas["area"].AxisX.Maximum = 2;
//chart1.ChartAreas["area"].AxisX.Interval = 1;
//chart1.ChartAreas["area"].AxisX.IntervalAutoMode;
chart1.ChartAreas["area"].AxisY.Minimum = 0;
chart1.ChartAreas["area"].AxisY.Maximum = sumLight + 100;
chart1.ChartAreas["area"].AxisY.Interval = 50;
chart1.ChartAreas["area"].AxisY.Title = "Average Value";
//chart1.ChartAreas["area"].AxisX.Title = "Speed (m/s)";
chart1.Series.Add("Temprature");
chart1.Series.Add("VCC");
chart1.Series.Add("Light");
chart1.Series["Temprature"].Color = Color.Red;
chart1.Series["VCC"].Color = Color.Green;
chart1.Series["Light"].Color = Color.Yellow;
chart1.Series["Temprature"].Points.AddXY(1, 78.32);
chart1.Series["VCC"].Points.AddXY(2, 3.92);
chart1.Series["Light"].Points.AddXY(3, 333);
chart1.Series["Temprature"].IsValueShownAsLabel = true;
chart1.Series["VCC"].IsValueShownAsLabel = true;
chart1.Series["Light"].IsValueShownAsLabel = true;
chart1.Legends.Add("legend");
chart1.Titles.Add("Average for Temperature, Light & VCC using timestamp");
chart1.Visible = true;
答案 0 :(得分:0)
我想你可能会通过插入空数据点来实现某些目标。 所以这个块:
chart1.Series["Temprature"].Points.AddXY(1, 78.32);
chart1.Series["VCC"].Points.AddXY(2, 3.92);
chart1.Series["Light"].Points.AddXY(3, 333);
应该成为
chart1.Series["Temprature"].Points.AddXY(1, 78.32);
chart1.Series["Temprature"].Points.Add(new DataPoint(2,0){IsEmpty=true});
chart1.Series["Temprature"].Points.Add(new DataPoint(3,0){IsEmpty=true});
chart1.Series["VCC"].Points.Add(new DataPoint(1,0){IsEmpty=true});
chart1.Series["VCC"].Points.AddXY(2, 3.92);
chart1.Series["VCC"].Points.Add(new DataPoint(3,0){IsEmpty=true});
chart1.Series["Light"].Points.Add(new DataPoint(1,0){IsEmpty=true});
chart1.Series["Light"].Points.Add(new DataPoint(2,0){IsEmpty=true});
chart1.Series["Light"].Points.AddXY(3, 333);
此外,您可能只尝试使用一个带有3个彩色DataPoints的系列:
chart1.Series[0].Points.AddXY("Temprature", 78.32);
chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Color = Color.Red;
chart1.Series[0].Points.AddXY("VCC", 3.92);
chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Color = Color.Green;
chart1.Series[0].Points.AddXY("Light", 333);
chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Color = Color.Yellow;