Reputation: 2070
I created a chart using System.Web.UI.DataVisualization.Charting. The charts are displayed on google chrome and safari. But this is not visible on windows xp IE8. I really don't know how to fix this.
Here's a code snippet on my creation of charts.
<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");
}
Any ideas on what's causing this to not be displayed on IE8? Thanks.
Upvotes: 1
Views: 2040
Reputation: 94
After going mad about this, I found that IE8 doesn't resize parent container when the chart is being created. You need to put it explicitly in the DOM. So for example:
<div>
<asp:Chart ID="Chart1" runat="server" SuppressExceptions="True" Width="1000px" Height="600px">
</asp:Chart>
</div>
will not render anything in IE8 (the div's width will be 0px), but:
<div style="width: 1100px">
<asp:Chart ID="Chart1" runat="server" SuppressExceptions="True" Width="1000px" Height="600px">
</asp:Chart>
</div>
will. Just set container width some pixel greater than chart width.
Upvotes: 1