1

そこで、カスタム ビジネス オブジェクトのリストを Rad チャートにバインドします。この例では、1 年間の月間収益の概要です。X 軸のラベルに設定している日付が、設定したとおりにレンダリングされません。

これが私の基本的なコードです。指定された年のmonthLedgerオブジェクトのリストを取得することがわかります。monthLedgerオブジェクトにはさまざまなプロパティがありますが、このシナリオの主なプロパティはmonthLedger.Full_datemonthLedger.Revenue_Amountです。

List<monthLedger> year = getYearRevenueByMonth(2011);

DataSeries ser = new DataSeries();

foreach(monthLedger month in year)
{
    ser.Add(new DataPoint 
            { 
                YValue = Convert.ToDouble(month.Revenue_Amount), 
                Label = month.Revenue_Amount.ToString("0.00###"), 
                XValue = month.Full_Date.ToOADate()
            });
}


radChart1.DefaultView.ChartArea.AxisX.IsDateTime = true;
radChart1.DefaultView.ChartArea.AxisX.AutoRange = true;
radChart1.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "dd-MMM";
radChart1.DefaultView.ChartArea.DataSeries.Add(ser);

2011 年のリストで取得するデータは次のとおりです (Full_Date || Revenue_Amount):

  • {01/01/2011 午前 12:00:00} || 0.00
  • {01/02/2011 午前 12:00:00} || 0.00
  • {01/03/2011 午前 12:00:00} || 0.00
  • {01/04/2011 午前 12:00:00} || 0.00
  • {01/05/2011 午前 12:00:00} || 0.00
  • {01/06/2011 午前 12:00:00} || 0.00
  • {01/07/2011 午前 12:00:00} || 0.00
  • {01/08/2011 午前 12:00:00} || 0.00
  • {01/09/2011 午前 12:00:00} || 0.00
  • {01/10/2011 12:00:00 AM} || 0.00
  • {01/11/2011 午前 12:00:00} || 246.50
  • {01/12/2011 午前 12:00:00} || 311.60

私が期待するのは 12 か月の素晴らしいグラフですが、最終的に 13 列がグラフ化され、ラベル付けされた日付は、OLE Automation Date に変換した日付とまったく同じではありません。

グラフィック結果のスクリーンショットを添付しました。 ここに画像の説明を入力

私は何を間違っていますか?

4

1 に答える 1

2

あなたの画像からわかるように、チャートは30日のステップでバーをプロットします。これは、XAxis の自動範囲が原因です。Chart は 1 か月の時間厳守のステップを定義できないため (月によって日数が異なります)、XAxis は 30 日が最も適切であると自動的に定義します。手動で範囲を設定しても役に立たないので、XValue の代わりに XCategory を使用することをお勧めします。

foreach(monthLedger month in year) 
   { 
    ser.Add(new DataPoint  
            {  
                YValue = Convert.ToDouble(month.Revenue_Amount),  
                Label = month.Revenue_Amount.ToString("0.00###"),  
                XCategory = month.Full_Date
            }); 
   } 

これを削除できます - radChart1.DefaultView.ChartArea.AxisX.IsDateTime = true; もう必要ないからです。

乾杯、エフゲニア

于 2012-01-08T09:52:11.957 に答える