2009-09-24 23 views
9

ASP.NETチャートイメージを作成するASP.NET MVCコントローラメソッドについて考えてみましょう。ASP.NETチャート:X軸とY軸のフォントを設定する

public FileStreamResult MakeImg(IEnumerable<MyObj> stats) 
    { 
     Chart barchart = BarChart(400, 300); 

     Series series1 = new Series("Series1"); 
     series1.ChartArea = "ca1";    
     series1.ChartType = SeriesChartType.Column; 
     series1.IsValueShownAsLabel = true;  
     series1.Font = new Font("Verdana", 9f, FontStyle.Regular); 

     barchart.Series.Add(series1);    

     // Set chart data source 
     barchart.DataSource = stats; 

     // Set series members names for the X and Y values 
     barchart.Series["Series1"].XValueMember = "FriendlyDate"; 
     barchart.Series["Series1"].YValueMembers = "NumRecords"; 

     // Data bind to the selected data source 
     barchart.DataBind(); 

     MemoryStream ms = new MemoryStream(); 
     barchart.SaveImage(ms, ChartImageFormat.Png); 
     ms.Seek(0, SeekOrigin.Begin); 

     return new FileStreamResult(ms, "image/png"); 
    } 

画像が魅力のないようにレンダリングされる:

fugly http://www.imagechicken.com/uploads/1253830647005451400.png

質問:どのようにするためのプログラムでフォントを設定することができる:

  • X及びY軸のラベルを - すなわち、0から35までのY、日付はX
  • data - すなわち、12,0,0,3,6、

答えて

13
chart.ChartAreas[0].AxisX.LabelStyle.Font 
chart.ChartAreas[0].AxisY.LabelStyle.Font 

あなたは軸のフォントを設定する必要があるプロパティです。

0

私が直面したもう一つの問題は、テキストのギザギザでした。 .pngから.jpgに変更すると、このトリックが実行されました。

+0

同様に、これですべてのことがスムーズに行われます:chart1.AntiAliasing = AntiAliasingStyles.All; – Simon

1

Chart1.ChartAreas [0] .AxisX.LabelStyle.Font = new System.Drawing.Font( "Verdana"、8f); Chart1.ChartAreas [0] .AxisY.LabelStyle.ForeColor = System.Drawing.Color.Red;

関連する問題