MSChart的:如何分组RangeBar数据和文本标签,而不是指标? [英] MSChart: How to group RangeBar data with text labels instead of indexes?

查看:585
本文介绍了MSChart的:如何分组RangeBar数据和文本标签,而不是指标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在找绘制出RangeBar图表区域(System.Windows.Forms.DataVisualization.Charting)数据和我有问题,分组数据时,我有文本值,在垂直轴上的标签。

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.

下面是相关的code:

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 与拥有这些成员类型项目的列表(通过公共属性访问与相应的大写名称):

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;

当我称之为 DataSeries.Points.AddXY()与X型为一个整数(召回X是范围栏上的垂直轴)是我想要做什么。的时间段是根据该指数在底部图表进行分组:

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:

不过,当我改变要尽量使用文本标签将它们分组,通过更换 AddXY 这一点:

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.)

任何想法?谢谢!

推荐答案

在数据点使用一个AxisLabel属性。 一种方式做这将是这样的:

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;
}

这篇关于MSChart的:如何分组RangeBar数据和文本标签,而不是指标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆