我想在代码后面的UL标签中添加一个图表控件

时间:2012-06-28 17:48:10

标签: c# asp.net

我想通过代码在我的ul标签内动态添加图表控件。我怎样才能做到这一点?  这是我对anythingslider javascript的陈述

<script type="text/javascript">
     var slider2 = ['Machines', 'Trend','test','test2','test3'];
     function formatText(index, panel) {
         return slider2[index - 1];
     }

     $(function () {
         $('#slider2').anythingSlider({
             width: 800,       // if resizeContent is false, this is the default width if panel size is not defined
             height: 400,       // if resizeContent is false, this is the default height if panel size is not defined
             buildArrows: true,
             resizeContents: false,     // If true, solitary images/objects in the panel will expand to fit the viewport
             autoPlay: true,     // This turns off the entire slideshow FUNCTIONALY, not just if it starts running or not
             navigationFormatter: formatText, // Format navigation labels with text
             forwardText: "&raquo;",
             backText: "&laquo;"
         })
     });
</script>

编辑: 这是包含新添加代码的页面的源代码:

<ul id="MainContent_slider2">
<img id="MainContent_PlantMachineChart" src="/ChartImg.axd?i=chart_93717cef16e84387b35d83bdd04da217_0.png&amp;g=898a170672b0476ca6f6d49173c231b1" alt="" usemap="#MainContent_PlantMachineChartImageMap"    style="height:400px;width:868px;border-width:0px;" />

<map name="MainContent_PlantMachineChartImageMap"  id="MainContent_PlantMachineChartImageMap">
 </map>

 <li><img id="MainContent_ctl01" src="/ChartImg.axd?    i=chart_93717cef16e84387b35d83bdd04da217_1.png&amp;g=23020f9898ab40898782de3234fae6e4"    alt="" style="height:400px;width:868px;border-width:0px;" /></li'><li'><img    id="MainContent_ctl03" src="/ChartImg.axd?   i=chart_93717cef16e84387b35d83bdd04da217_2.png&amp;g=aa749f6279484859a7892f1f117fbd1c"    alt="" style="height:400px;width:868px;border-width:0px;" /></li></ul>

它包含了第一个图表(我在这里留下的)列出的所有数据点,这些数据点没有动态添加。

2 个答案:

答案 0 :(得分:3)

我真的不知道你为什么要这样做,但是你可以制作ul runat="server"并像这样添加控件:

<强> HTML

<ul runat="server" ID="ul_Charts"></ul>

<强>服务器侧

ul_Charts.Controls.Add(yourControl);

编辑:您需要以编程方式创建图表并将图表控件插入元素中,如下所示:

// Create a pie chart
Chart chart = new Chart();

// Choose chart type and add series info
Series series = new Series("Default");
series.ChartType = SeriesChartType.Pie;
chart.Series.Add(series);

// Create chart legend
Legend legend = new Legend();
chart.Legends.Add(legend);

// Define the chart area
ChartArea chartArea = new ChartArea();
ChartArea3DStyle areaStyle = new ChartArea3DStyle(chartArea);
areaStyle.Rotation = 0;
chart.ChartAreas.Add(chartArea);

Axis yAxis = new Axis(chartArea, AxisName.Y);
Axis xAxis = new Axis(chartArea, AxisName.X);

// Bind the data to the chart
chart.Series["Default"].Points.DataBindXY(xValues, yValues);

// Add chart
HtmlGenericControl li = new HtmlGenericControl("li");
li.Controls.Add(chart);
ul_Charts.Controls.Add(li);

此示例在asp.net forums上找到,并进行了一些调整,以适应您的情况。还有其他选择,但这应该列出你需要做什么。

答案 1 :(得分:0)

您可以在aspx中使用占位符,然后在运行时将控件加载到其中。