System.Web.UI.DataVisualization.Charting图表未显示在IE8上

本文关键字:显示 IE8 Web UI DataVisualization Charting System | 更新日期: 2023-09-27 18:21:50

我使用System.Web.UI.DataVisualization.Charting创建了一个图表。这些图表显示在谷歌chrome和safari上。但这在windowsxpIE8上是不可见的。我真的不知道怎么解决这个问题。

以下是我创建图表的代码片段。

<img src="/ConvertFiles/CreateActualsVsForecastChart/?actuals=@(thisMonth)&forecast=@(prevMonth)" />
public FileResult CreateActualsVsForecastChart(string actuals, string forecast, string chartName)
    {
        //IList<ResultModel> peoples = _resultService.GetResults();
        if (actuals.Equals(""))
            actuals = "0";
        if (forecast.Equals(""))
            forecast = "0";
        Chart chart = new Chart();
        chart.Width = 350;
        chart.Height = 400;
        chart.BackColor = Color.FromArgb(211, 223, 240);
        chart.BorderlineDashStyle = ChartDashStyle.Solid;
        chart.BackGradientStyle = GradientStyle.TopBottom;
        chart.BorderlineWidth = 1;
        chart.Palette = ChartColorPalette.BrightPastel;
        chart.BorderlineColor = Color.FromArgb(26, 59, 105);
        chart.RenderType = RenderType.BinaryStreaming;
        chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
        chart.AntiAliasing = AntiAliasingStyles.All;
        chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
        chart.Titles.Add(CreateTitle(chartName));
        chart.Legends.Add(CreateLegend());
        chart.Series.Add(CreateSeries4(new List<ChartKeyValue>()
            {
                new ChartKeyValue(){ Lable = "Forecast", Value = Convert.ToDouble(forecast), IsCurrent=true},
            }, SeriesChartType.Column, "Forecast", "pink"));
        chart.Series.Add(CreateSeries4(new List<ChartKeyValue>()
            {
                new ChartKeyValue(){ Lable = "Actual", Value = Convert.ToDouble(actuals), IsCurrent=true}
            }, SeriesChartType.Column, "Actual", "blue"));
        chart.ChartAreas.Add(CreateChartArea());
        MemoryStream ms = new MemoryStream();
        chart.SaveImage(ms);
        return File(ms.GetBuffer(), @"image/png");
    }

关于是什么原因导致IE8上没有显示这个,有什么想法吗?谢谢

System.Web.UI.DataVisualization.Charting图表未显示在IE8上

在对此感到愤怒之后,我发现IE8在创建图表时不会调整父容器的大小。您需要将它显式地放在DOM中。例如:

<div>
<asp:Chart ID="Chart1" runat="server" SuppressExceptions="True" Width="1000px" Height="600px">
</asp:Chart>
</div>

不会在IE8中渲染任何内容(div的宽度为0px),但是:

<div style="width: 1100px">
<asp:Chart ID="Chart1" runat="server" SuppressExceptions="True" Width="1000px" Height="600px">
</asp:Chart>
</div>

意志。只需将容器宽度设置为比图表宽度大一些像素。