我想投影具有给定宽度的列(ei从16-05-03 12:00:00到16-07-26 12:00:00)并且它沿x轴投影(ei标签bool) ,int,long,bool,int long)(见下图)。
为此我有2个图表区域都具有相同的参数。
private void AddChartAreas(string name)
{
// AxisX
chart1.ChartAreas.Add(name);
chart1.ChartAreas[name].AxisX.MajorGrid.Enabled = false;
chart1.ChartAreas[name].AxisX.Interval = 1;
// AxisY
chart1.ChartAreas[name].AxisY.ScrollBar.Enabled = true;
chart1.ChartAreas[name].AxisY.ScaleView.Zoomable = true;
chart1.ChartAreas[name].AxisY.MajorGrid.Enabled = false;
chart1.ChartAreas[name].AxisY.LabelStyle.Format = "yyyy-MM-dd hh:mm:ss";
chart1.ChartAreas[name].AxisY.Interval = 0;
chart1.ChartAreas[name].AxisY.IntervalType = DateTimeIntervalType.Years;
minDate = new DateTime(2016, 01, 01, 00, 00, 00, 000);
maxDate = new DateTime(2016, 12, 01, 00, 00, 00, 000); // or DateTime.Now;
chart1.ChartAreas[name].AxisY.Minimum = minDate.ToOADate();
chart1.ChartAreas[name].AxisY.Maximum = maxDate.ToOADate();
chart1.ChartAreas[name].AxisY.LabelStyle.IsEndLabelVisible = true;
chart1.ChartAreas[name].AxisY.IsLabelAutoFit = true;
chart1.ChartAreas[name].AxisY.LabelStyle.ForeColor = Color.Yellow;
chart1.ChartAreas[name].Axes[0].Enabled = AxisEnabled.False;
chart1.ChartAreas[name].Axes[1].Enabled = AxisEnabled.False;
chart1.ChartAreas[name].BackColor = Color.Transparent;
chart1.ChartAreas[name].Position.Height = 100;
chart1.ChartAreas[name].Position.Width = 100;
chart1.ChartAreas[name].InnerPlotPosition.Height = 90;
chart1.ChartAreas[name].InnerPlotPosition.Width = 80;
chart1.ChartAreas[name].InnerPlotPosition.X = 10;
}
第一个图表区域(条形系列)创建如下:
var series = new Series {
Name = "S1",
Color = Color.LightSlateGray,
ChartType = SeriesChartType.Bar
};
chart1.Series.Add(series);
第二个图表区域(范围列系列):
var series = new Series {
Name = "S2",
Color = Color.LightSlateGray,
ChartType = SeriesChartType.RangeColumn
};
chart1.Series.Add(series);
要为条形码添加点,只需为x,y绑定2个列表:
var lables = new string[6];
var values = new DateTime[6];
minDate = new DateTime(2016, 01, 01, 00, 00, 00, 000);
// Dummy data
lables[0] = "bool";
lables[1] = "int";
lables[2] = "long";
lables[3] = "bool";
lables[4] = "int";
lables[5] = "long";
// Dummy data
values[0] = minDate.AddMonths(10);
values[1] = minDate.AddMonths(10);
values[2] = minDate.AddMonths(10);
values[3] = minDate.AddMonths(10);
values[4] = minDate.AddMonths(10);
values[5] = minDate.AddMonths(10);
// Simply bind 2 lists
series[0].Points.DataBindXY(lables, values);
对于列范围系列:
pointIndex = series[1].Points.AddXY(values2[1], values2[5]);
现在它看起来像这样:
如何使它看起来像第一张照片。
答案 0 :(得分:0)
我想出了一个解决方案。
而不是范围栏我制作范围栏系列并将PointWidth
设为5
:
var series = new Series {
Name = "S2",
Color = Color.LightSlateGray,
ChartType = SeriesChartType.Rangebar
};
series["PointWidth"] = "5";
chart1.Series.Add(series);
比绘图时:
minDate = new DateTime(2016, 01, 01, 00, 00, 00, 000);
values2[0] = minDate.AddMonths(1);
values2[1] = minDate.AddMonths(2);
pointIndex = series2.Points.AddXY(values2[1], values2[1]);
这会给我我想要的结果。