MSChart:如何使用文本标签而不是索引对 RangeBar 数据进行分组?
我希望在 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
是一个包含具有这些成员类型的项目的列表(通过具有相应大写名称的公共属性访问):
private int itemId;
private string itemLabel;
private DateTime startConnectionTime;
private DateTime stopConnectionTime;
当我调用 DataSeries.Points.AddXY()
时将 X 类型作为整数(回想一下,X 是范围栏上的垂直轴),它可以满足我的要求。时间范围根据底部图表中的索引进行分组:
但是,当我更改为尝试使用文本标签对它们进行分组,方法是将 AddXY
替换为:
connectedTimeRangeSeries.Points.AddXY(theLabel, timeRanges[i].StartConnectionTime, timeRanges[i].StopConnectionTime);
数据不再分组:
就像每个一个有自己的垃圾箱,我只想将它们按标签组合起来。 (每个索引都有一个且只有一个标签。)
有什么想法吗?谢谢!
I'm looking to plot data on a RangeBar chart area (System.Windows.Forms.DataVisualization.Charting) and I'm having issues grouping the data when I have text values for the labels on the vertical axis.
Here's the pertinent code:
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
is a list with items having these member types (accessed through public properties with corresponding capitalized names):
private int itemId;
private string itemLabel;
private DateTime startConnectionTime;
private DateTime stopConnectionTime;
When I call DataSeries.Points.AddXY()
with the X type as an integer (recall X is the vertical axis on the range bar) it does what I want. The time ranges are grouped according to the index in the bottom graph:
However, when I change to try to use a text label to group them, by replacing AddXY
with this:
connectedTimeRangeSeries.Points.AddXY(theLabel, timeRanges[i].StartConnectionTime, timeRanges[i].StopConnectionTime);
the data are no longer grouped:
It's like each one gets its own bin, and I just want them to be combined by label. (Each index has one and only one label.)
Any ideas? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 DataPoint 的 AxisLabel 属性。
一种方法是这样的:
Use AxisLabel property of the DataPoint.
One way to do it would be something like this: