MVC3 System.Web.UI.DataVisualization.Charting Font不会渲染但Style会渲染

时间:2011-08-23 20:52:49

标签: asp.net-mvc-3 charts

我正在与.net 4.0图表控件作斗争,目前我一直坚持为什么字体只是拒绝渲染。它显示为几乎不可读的重叠字符。我确定字体已安装在我的系统中。

奇怪的是,字体stlye根据设置而变化。![截屏] [1]

我还很难发现Interval属性,它删除了9以上的标签,直到Interval设置为1. interval属性的行为也与System.Web.Helpers.Chart()控件不同忽略该设置。拉梅!

感谢您的帮助。

Razor Code ..

<img src="@Url.Action("ChartSample")" alt="image" />//In Razer

控制器代码......

 public ActionResult ChartSample()
    {
        var chart = new System.Web.UI.DataVisualization.Charting.Chart();
        chart.BackColor = Color.Transparent;
        chart.Width = Unit.Pixel(250);
        chart.Height = Unit.Pixel(2500);

        var series = new Series();
        series.ChartArea = "ca1";

        series.ChartType = SeriesChartType.Bar;
        //series.Font = new Font("Verdana", 8.25f, FontStyle.Regular);

        var myRandom = new Random();

        for (int i = 0; i < 100; i++)
        {
            var dp = new DataPoint();
            dp.AxisLabel = String.Format("{0}-{1}", i, Guid.NewGuid().ToString().Substring(0, 4));
            dp.YValues = new double[] { myRandom.Next(5, 100) };
            series.Points.Add(dp);
        }


        chart.Series.Add(series);

        var area = new ChartArea("ca1");
        area.Area3DStyle.Enable3D = false;
        area.AxisX.Interval = 1;
        //area.BackColor = Color.Transparent;
        //var labelStyle = new LabelStyle();
        //labelStyle.Enabled = true;
        //labelStyle.Font = new Font("Arial", 3f);
        area.AxisX.LabelStyle.Font = new Font("Verdana", 8.25f, FontStyle.Underline);//Why does it recognize the style but not the font!!!???

        chart.ChartAreas.Add(area);

        using (var ms = new MemoryStream())
        {
            chart.SaveImage(ms, ChartImageFormat.Png);
            ms.Seek(0, SeekOrigin.Begin);

            return File(ms.ToArray(), "image/png", "mychart.png");
        }
    }

1 个答案:

答案 0 :(得分:1)

按照以下方式为图表添加背面颜色:

 chart.BackColor = Color.FromArgb(255, 255, 255);