1

我使用 System.Web.UI.DataVisualization.Charting 创建了一个图表。图表显示在 google chrome 和 safari 上。但这在 windows xp IE8 上不可见。我真的不知道如何解决这个问题。

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

<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 上显示的任何想法?谢谢。

4

1 回答 1

1

在为此发疯后,我发现 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>

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

于 2013-07-19T14:17:59.087 回答