MVC3 System.Web.UI.DataVisualization.Charting 字体不呈现,但样式呈现

发布于 2024-12-01 05:00:18 字数 1924 浏览 0 评论 0原文

我正在与 .net 4.0 图表控件作斗争,目前我很困惑为什么字体只是拒绝渲染。它显示为几乎无法读取的重叠字符。我确定该字体已安装在我的系统中。

奇怪的是,字体样式会根据设置而变化。![屏幕截图][1]

我也很难发现 Interval 属性,它会删除计数超过 9 的标签,直到 Interval 设置为 1。interval 属性也行为与 System.Web.Helpers.Chart() 控件不同,后者似乎忽略了该设置。瘸!

感谢您的任何帮助。

剃刀代码..

<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");
        }
    }

I am battling with the .net 4.0 Chart Controls and am currently stuck on why the font simply refuses to render. It shows as near unreadable overlapping characters. I'm sure the font is installed in my system.

Oddly the font stlye changes in accordance with the setting.![screen shot][1]

I also had a hard time discovering the Interval property where it was removing labels above the count of 9 until Interval was set to 1. The interval property also behaved differently than the System.Web.Helpers.Chart() control which seems to ignore the setting. Lame!

Thanks for any help.

Razor Code..

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

Controller Code...

 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");
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坏尐絯℡ 2024-12-08 05:00:18

只需给图表设置背景颜色,如下所示:

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

Just give your chart a back color as follows:

 chart.BackColor = Color.FromArgb(255, 255, 255);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文