gpt4 book ai didi

c# - MSChart:如何使用文本标签而不是索引对 RangeBar 数据进行分组?

转载 作者:行者123 更新时间:2023-11-30 15:43:57 29 4
gpt4 key购买 nike

我想在 RangeBar 图表区域 (System.Windows.Forms.DataVisualization.Charting) 上绘制数据,但当我在垂直轴上有标签的文本值时,我在对数据进行分组时遇到了问题。

相关代码如下:

var connectedTimeRangeSeries = theChart.Series.Add("ConnectedTimeRangeSeries");
var connectedTimeRangesChartArea = theChart.ChartAreas["PerItemConnectedChartArea"];

connectedTimeRangeSeries.ChartArea = connectedTimeRangesChartArea.Name;
connectedTimeRangeSeries.ChartType = SeriesChartType.RangeBar;
connectedTimeRangeSeries.XValueType = ChartValueType.Auto;
connectedTimeRangeSeries.YValueType = ChartValueType.Auto;

for (int i = 0; i < timeRanges.Count; i++)
{
string theLabel = timeRanges[i].ItemLabel;

connectedTimeRangeSeries.Points.AddXY(timeRanges[i].ItemId + 1, timeRanges[i].StartConnectionTime, timeRanges[i].StopConnectionTime);
}

timeRanges 是一个列表,其中包含具有这些成员类型的项目(通过具有相应大写名称的公共(public)属性访问):

private int itemId;
private string itemLabel;
private DateTime startConnectionTime;
private DateTime stopConnectionTime;

当我调用 DataSeries.Points.AddXY() 并将 X 类型作为整数(回想一下 X 是范围栏上的垂直轴)时,它会执行我想要的操作。时间范围根据底部图表中的索引进行分组:

good chart

但是,当我更改为尝试使用文本标签对它们进行分组时,将 AddXY 替换为:

connectedTimeRangeSeries.Points.AddXY(theLabel, timeRanges[i].StartConnectionTime, timeRanges[i].StopConnectionTime);

数据不再分组:

enter image description here

这就像每个人都有自己的垃圾箱,我只是想让他们通过标签组合起来。 (每个索引只有一个标签。)

有什么想法吗?谢谢!

最佳答案

使用数据点的 AxisLabel 属性。一种方法是这样的:

for (int i = 0; i < timeRanges.Count; i++)
{
string theLabel = timeRanges[i].ItemLabel;
int pointIndex = connectedTimeRangeSeries.Points.AddXY(timeRanges[i].ItemId + 1, timeRanges[i].StartConnectionTime, timeRanges[i].StopConnectionTime);
connectedTimeRangeSeries.Points[pointIndex].AxisLabel = theLabel;
}

关于c# - MSChart:如何使用文本标签而不是索引对 RangeBar 数据进行分组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6444058/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com