我需要在几天内显示多条生产线的%利用率。所以我的Y轴将是%值。我每天都需要为每条生产线提供酒吧。因此,我的X轴将是一组列,每列都标记为生产线,然后分组并标记日期。我如何使用MSchart进行此操作。
以下是我需要的样本。它只显示2条生产线(我需要显示2条以上的生产线),并且不在X轴标签中包含生产线名称。
我快到了。这是我正在创建的图表的图像:
以下是创建它的代码:
Private Sub ChartSetup()
Try
dvCapacityUtilization.RowFilter = ""
dvCapacityUtilization.Sort = "Period ASC, CutUpSet ASC"
Me.cuChart.BeginInit()
With Me.cuChart
.ChartAreas(0).AxisX.Interval = 30
.ChartAreas(0).AxisX.LabelStyle.Format = "MM/yy"
.ChartAreas(0).AxisX.LabelStyle.Angle = -90
.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.Gray
.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.White
.ChartAreas(0).AxisX.MinorGrid.LineColor = Color.White
.DataBindCrossTable(dvCapacityUtilization, _
"CutUpSet", "Period", "CapacityUtilization", "Label = CapacityUtilization")
End With
'
For Each series In Me.cuChart.Series
series.IsValueShownAsLabel = False
series.LabelFormat = "0.0%"
series.SetCustomProperty("PointWidth", "0.5")
series.SetCustomProperty("DrawingStyle", "Cylinder")
series.XValueType = DataVisualization.Charting.ChartValueType.Date
Next
Me.cuChart.EndInit()
Catch ex As Exception
ErrHandler(Me.Name & " - Chart Setup", ex)
End Try
End Sub
跟进: 如上面#1中所述,我使用了series.IsValueShownAsLabel = False,但仍然显示了值标签。要删除它们,我必须执行以下操作:
对于系列中的每个点。积分 point.Label = String.Empty 下一步
为什么我必须这样做而不是使用IsValueShownAsLabel = False?
答案 0 :(得分:0)
WINFORM:最后找出一些R& D。请按照以下步骤操作。
<强> 1。在新的winform中从ToolBox拖放新的图表控件。
<强> 2。删除默认的“Series1”,因为它是根据列值动态生成的。
第3。假设我们有以下样本数据表。
public DataTable GetDataTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("UtilizationDate", typeof(DateTime));
dt.Columns.Add("ProductionLine", typeof(string));
dt.Columns.Add("UtilizationValue", typeof(int));
DataRow dr = dt.NewRow();
dr[0] = DateTime.Now;
dr[1] = "Proy01";
dr[2] = 25;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = DateTime.Now;
dr[1] = "Proy02";
dr[2] = 15;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = DateTime.Now;
dr[1] = "Proy03";
dr[2] = 125;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = DateTime.Now.AddMonths(1);
dr[1] = "Proy01";
dr[2] = 13;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = DateTime.Now.AddMonths(1);
dr[1] = "Proy02";
dr[2] = 111;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = DateTime.Now.AddMonths(1);
dr[1] = "Proy03";
dr[2] = 77;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = DateTime.Now.AddMonths(2);
dr[1] = "Proy01";
dr[2] = 13;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = DateTime.Now.AddMonths(2);
dr[1] = "Proy02";
dr[2] = 111;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = DateTime.Now.AddMonths(2);
dr[1] = "Proy03";
dr[2] = 77;
dt.Rows.Add(dr);
return dt;
}
<强> 4。现在使用DataBindCrossTable添加以下代码行。
chart1.ChartAreas["ChartArea1"].AxisX.IntervalType = DateTimeIntervalType.Months;
chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "MM-yy";
DataTable dt = GetDataTable();
chart1.DataBindCrossTable(dt.DefaultView, "ProductionLine", "UtilizationDate", "UtilizationValue", "Label=UtilizationValue");
foreach (Series item in chart1.Series)
{
item.IsValueShownAsLabel = true;
item["PixelPointWidth"] = "50";
item["DrawingStyle"] = "Cylinder";
item.XValueType = ChartValueType.DateTime;
}