为图表中的每列设置自定义宽度

时间:2017-10-18 21:49:34

标签: c# .net winforms charts

在Windows窗体应用程序中,我想为每列设置自定义宽度。例如,从x = 1到x = 3,y = 1。

这就是我所做的

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

chart1.Series[0].XValueMember = "Time";
chart1.Series[0].YValueMembers = "Busy";
chart1.ChartAreas[0].AxisX.IntervalOffsetType = DateTimeIntervalType.Number;
this.chart1.Series["ServerBusyTime"].Points.AddXY(2, 10);
this.chart1.Series["ServerBusyTime"].Points.AddXY(1, 5);
this.chart1.Series["ServerBusyTime"].Points.AddXY(3, 5);
this.chart1.Series["ServerBusyTime"].Points.AddXY(4, 5);

结果如下:

chart 1

这就是我想要的:

chart 2

1 个答案:

答案 0 :(得分:0)

您必须添加一个

[..].AddXY(x,1)

对于要添加到图表的每个x值

for (var i1 = 2; i < 6; i++)
   this.chart1.Series["ServerBusyTime"].Points.AddXY(i1, 1);
for (var i2 = 10; i < 20; i++)
   this.chart1.Series["ServerBusyTime"].Points.AddXY(i2, 1);