2009-09-24 40 views
9

Hãy xem xét phương pháp điều khiển ASP.NET MVC xây dựng hình ảnh Biểu đồ ASP.NET.Biểu đồ ASP.NET: đặt phông chữ trên trục X và 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"); 
    } 

Hình ảnh render một cách hấp dẫn:

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

Câu hỏi: Làm thế nào tôi có thể thiết lập font lập trình cho:

  • X và Y nhãn trục - nghĩa là 0 đến 35 trên Y và ngày trên dữ liệu X
  • - tức là 12, 0, 0, 3, 6?

Trả lời

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

là thuộc tính bạn cần đặt phông chữ cho trục.

0

Một vấn đề khác mà tôi phải đối mặt là răng cưa trên văn bản. Thay đổi từ .png thành .jpg đã thực hiện thủ thuật!

+0

Tương tự, điều này sẽ làm mịn mọi thứ cho bạn: 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;

Các vấn đề liên quan