简体   繁体   中英

how to programatically add chart control to ASP.net c# page

I am creating a report application which queries a database and calculates the sales figures for staff. The result from the query is stored in a dataset. At the moment, I am dragging the chart control from the toolbox onto the page to create a control. This chart control sits in a div tag called slideshow as I'm using jQuery to create a slideshow. Each chart is bound to a row from the dataset.

However, the issue I am having now is that if a new staff is added, I will have to keep messing around with the web page to display a chart for the new staff. Is there a way in which I can say, "For each row in the dataset, create a chart control in the slideshow div tag ?"

Interactions between ASP.net and jquery can be a little tricky because you are dealing with server side vs. client side. What I suggest you do is create a list from the server side (eg produce a static JSON list in javascript or use AJAX), then use jquery to create your charts for each staff in your JSON list.

同意让服务器返回JSON并在jquery中完成所有操作的想法-您应该很容易地查看新的jquery模板,以将json转换为一组按要求格式化的div标签。

Yes, you can do what you ask.

Suppose that you have a Dataset ds with some rows. You want to create a chart for each row. Here's what you can do:

1) Declare an ASP Panel on your page:

<asp:Panel runat='server' id='pnlCharts' />

2) In your code-behind, you'll want to write something like this:

Dataset ds = getMyData();
foreach(Datarow row in ds.Tables[0].Rows)
{
Chart chart = new Chart();
// Add code to design a chart from a *single* row
Panel.Controls.Add(chart);
}

I though about your question some more. 我不过是关于您的问题。 You might also consider using the ASP Repeater to do what you want. You can also write the charts directly to the page where you want using Chart.RenderControl().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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