我有一个图表,显示相同 DateTime X 值的两个不同 Y 值。我正在使用带有主 Y 轴和辅助 Y 轴的同一图表区域上的样条曲线绘制它们。除了交换 Y 轴标签外,该图似乎工作正常。预期的主要 Y 轴标签位于辅助轴上,反之亦然。
此外,应该注意的是,图表从不显示在屏幕上,它们使用该chart.SaveImage
方法在文件系统和数据库中保存为图像文件。
这是图表输出的图像:
这是生成图表的代码:
// create the chart
Chart chart = new Chart();
chart.Size = new Size(width, height);
chart.AntiAliasing = AntiAliasingStyles.All;
string datatype = data[0].DataType;
string datatype2 = data2[0].DataType;
SampleUnit unit = GetSampleUnit(data[0].Unit);
string u = "";
if (unit != null)
{
u = unit.ShortName;
}
SampleUnit unit2 = GetSampleUnit(data2[0].Unit);
string u2 = "";
if (unit2 != null)
{
u2 = unit2.ShortName;
}
var chartArea = new ChartArea();
chartArea.AxisX.LabelStyle.Format = "dd MMM\nHH:mm";
chartArea.AxisX.MajorGrid.LineColor = Color.LightGray;
chartArea.AxisY.MajorGrid.LineColor = Color.LightGray;
chartArea.AxisX.LabelStyle.Font = new Font("Calibri", 8);
chartArea.AxisY.LabelStyle.Font = new Font("Calibri", 8);
chartArea.AxisY2.LabelStyle.Font = new Font("Calibri", 8);
chartArea.AxisY2.Enabled = AxisEnabled.True;
chartArea.AxisY2.MajorGrid.Enabled = false;
if (string.IsNullOrEmpty(u))
{
chartArea.AxisY.Title = datatype;
}
else
{
chartArea.AxisY.Title = datatype + " (" + u + ")";
}
if (string.IsNullOrEmpty(u2))
{
chartArea.AxisY2.Title = datatype2;
}
else
{
chartArea.AxisY2.Title = datatype2 + " (" + u2 + ")";
}
chartArea.AxisY.TitleForeColor = Color.MediumBlue;
chartArea.AxisY2.TitleForeColor = Color.Red;
chart.ChartAreas.Add(chartArea);
var series = new Series();
series.Name = datatype;
series.ChartType = SeriesChartType.Spline;
series.XValueType = ChartValueType.DateTime;
series.YValueType = ChartValueType.Double;
series.YAxisType = AxisType.Primary;
series.Color = Color.MediumBlue;
chart.Series.Add(series);
var series2 = new Series();
series2.Name = datatype2;
series2.ChartType = SeriesChartType.Spline;
series2.XValueType = ChartValueType.DateTime;
series2.YValueType = ChartValueType.Double;
series.Color = Color.Red;
series.YAxisType = AxisType.Secondary;
chart.Series.Add(series2);
chart.Titles.Add(sensor.Name + " " + char.ToUpper(datatype[0]) + datatype.Substring(1) + " " + char.ToUpper(datatype2[0]) + datatype2.Substring(1));
// bind the datapoints
chart.Series[datatype].Points.DataBindXY(data, "Timestamp", data, "Value");
chart.Series[datatype2].Points.DataBindXY(data2, "Timestamp", data2, "Value");
// draw!
chart.Invalidate();
所以,我有两个问题:
- 为什么轴标签颠倒了?
- 化妆品:为什么轴标题要放一个条“|” 最后而不是右括号“)”?这只是将图表保存为图像的视觉工件吗?