【问题标题】:ASP.NET Chart: setting the fonts on X and Y axisASP.NET 图表:设置 X 和 Y 轴上的字体
【发布时间】:2009-09-24 21:39:18
【问题描述】:

考虑构建 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?

【问题讨论】:

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


    【解决方案1】:
    chart.ChartAreas[0].AxisX.LabelStyle.Font
    chart.ChartAreas[0].AxisY.LabelStyle.Font
    

    是您需要为轴设置字体的属性。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

        • 同样,这将为您解决所有问题:chart1.AntiAliasing = AntiAliasingStyles.All;
        猜你喜欢
        • 1970-01-01
        • 2019-07-07
        • 2014-05-13
        • 1970-01-01
        • 1970-01-01
        • 2015-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多