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

发布于 2024-11-16 16:58:48 字数 1519 浏览 2 评论 0原文

我希望在 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 是范围栏上的垂直轴),它可以满足我的要求。时间范围根据底部图表中的索引进行分组:

good Chart

但是,当我更改为尝试使用文本标签对它们进行分组,方法是将 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:

good chart

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:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浸婚纱 2024-11-23 16:58:48

使用 DataPoint 的 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;
}

Use AxisLabel property of the DataPoint.
One way to do it would be something like this:

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文