2011-06-22 14 views
3

RangeBarグラフ領域(System.Windows.Forms.DataVisualization.Charting)にデータをプロットしようとしていますが、縦軸にラベルのテキスト値があるときにデータをグループ化する際に問題が発生しています。MSChart:RangeBarデータをインデックスの代わりにテキストラベルでグループ化するにはどうすればよいですか?

ここ関連コードは次のとおり

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); 
時間範囲は、下のグラフのインデックスに応じてグループ化されています

データは、もはやグループ化されていません:

enter image description here

それはようなものですそれぞれは独自のビンを取得し、ラベルで結合するだけです。 (各インデックスにはラベルが1つしかありません)

アイデアはありますか?ありがとう!

+0

あなたはconnectedTimeRangeSeries.Points.AddXY(theLabel、timeRangeは[i]を.StartConnectionTime、timeRangeは[i]の.StopConnectionTime)を行うにはどうすればよいです。 2つの値で私は1つの値しか持てないと言っています。 –

答えて

4

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; 
} 
関連する問題