ASP.NET Chart:在X和Y轴上设置字体

时间:2009-09-24 21:39:18

标签: asp.net asp.net-mvc mschart microsoft-chart-controls

考虑构建ASP.NET图表图像的ASP.NET MVC控制器方法。

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轴标签 - 即Y上的0到35,以及X
  • 上的日期
  • 数据 - 即12,0,0,3,6?

3 个答案:

答案 0 :(得分:13)

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

是设置Axes字体所需的属性。

答案 1 :(得分:1)

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

答案 2 :(得分:0)

我遇到的另一个问题是文字上的锯齿。从.png更改为.jpg就可以了!