简体   繁体   English

ASP.NET图表控件-第一个图表在页面首次加载时显示为空白

[英]ASP.NET charting control - first charts show blank at first load of page

I have a page which generates four graphs using the ASP.NET 4.0 charting control and displays them. 我有一个页面,该页面使用ASP.NET 4.0图表控件生成四个图形并显示它们。 The charts are created in the code-behind on Page Load and added into a table on the page. 这些图表是在“页面加载”的代码背后创建的,并添加到页面的表格中。

My problem is that when the page loads, the first 1 or more graphs (usually just one, but sometimes 2 or 3) are blank (the user gets an empty outlined box of the size of the graph with a red X in the upper left corner). 我的问题是,当页面加载时,前1个或多个图形(通常只有一个,有时2或3个)是空白的(用户会得到一个图形大小的空轮廓框,左上角有一个红色的X)角)。

Refreshing the page causes all graphs to properly render. 刷新页面会使所有图形正确呈现。

Any ideas on how to get the graphs to populate on the first pass? 关于如何在第一次通过时填充图形的任何想法?

Here is the code that generates a chart and adds it to the page (the routine containing this code is called 4 times). 这是生成图表并将其添加到页面的代码(包含此代码的例程称为4次)。 Note that the 'points' object contains a collection of Name-Value pairs, where the Name is the Label to be displayed on the X-Axis, and the Value is the numeric Y-Axis value: 请注意,“点”对象包含“名称/值”对的集合,其中“名称”是要在X轴上显示的标签,而“值”是数字Y轴值:

Chart graph = new Chart();
graph.Width = 800;
graph.Height = 400;
Series series = new Series();
series.Name = "Series1";
series.Palette = ChartColorPalette.Bright;
series.IsXValueIndexed = true;
for (int j = 0; j < points.Count; j++)
{
    DataPoint dataPoint = new DataPoint(j+1.0, points.GetItem(j).Value);
    dataPoint.AxisLabel = points.GetItem(j).Name.Trim();                    
    series.Points.Add(dataPoint);
}
graph.Series.Add(series);
ChartArea chartArea = new ChartArea();
chartArea.Name = "ChartArea1";
chartArea.AxisX.Interval = 1;
chartArea.AxisY.LabelStyle.Format = "###,###,###,###";
graph.ChartAreas.Add(chartArea);
graph.Titles.Add(caption);

TableRow tr = new TableRow();
TableCell td = new TableCell();
td.Width = new Unit(100.0, UnitType.Percentage);
tblGraph.Rows.Add(tr);
tr.Cells.Add(td);
td.Controls.Add(graph);

Same issue here. 同样的问题在这里。 The Chart images ARE written to the file system, but this happens about 20ms after the page is rendered. 图表图像已写入文件系统,但是在呈现页面后约20毫秒发生。 If you put your code to sleep for, say, 20 milliseconds after rendering the Chart control, the issue won't happen - There will be time for the images to be written to the disk. 如果在渲染Chart控件后让代码进入休眠状态(例如20毫秒),则不会发生此问题-将有足够的时间将图像写入磁盘。

What would be the process to do that (the delay in rendering the page)? 这样做的过程是什么(延迟呈现页面)? I have the same issue off and on. 我有同样的问题断断续续。 In development, the graph (only one here) doesn't display 9 out of 10 times. 在开发中,图形(此处仅一个)在10次中没有显示9次。 In production, the graph DOES display about 7 out of 10 times. 在生产中,图形DOES大约显示10次中的7次。 It's that 3 out of 10 that I want to fix. 我要修复的十分之三。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM