开发者

MSChart: How to group RangeBar data with text labels instead of indexes?

I'm looking to plot data on a RangeBar chart area开发者_StackOverflow (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:

MSChart: How to group RangeBar data with text labels instead of indexes?

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:

MSChart: How to group RangeBar data with text labels instead of indexes?

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!


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜