Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我想在代码隐藏中的UL标记中添加一个图表控件_C#_Asp.net - Fatal编程技术网

C# 我想在代码隐藏中的UL标记中添加一个图表控件

C# 我想在代码隐藏中的UL标记中添加一个图表控件,c#,asp.net,C#,Asp.net,我想通过代码在ul标签中动态添加图表控件。我该怎么做? 这是我对AnythingSliderJavaScript的声明 <script type="text/javascript"> var slider2 = ['Machines', 'Trend','test','test2','test3']; function formatText(index, panel) { return slider2[index - 1]; }

我想通过代码在ul标签中动态添加图表控件。我该怎么做? 这是我对AnythingSliderJavaScript的声明

<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>

var slider2=['Machines'、'Trend'、'test'、'test2'、'test3'];
函数格式文本(索引、面板){
返回滑块2[索引-1];
}
$(函数(){
$(“#slider2”)。任意滑块({
宽度:800,//如果resizeContent为false,则如果未定义面板大小,则这是默认宽度
高度:400,//如果resizeContent为false,如果未定义面板大小,则此高度为默认高度
建筑箭头:是的,
resizeContents:false,//如果为true,面板中的单独图像/对象将展开以适合视口
autoPlay:true,//这将从功能上关闭整个幻灯片放映,而不仅仅是在它是否开始运行时
navigationFormatter:formatText,//使用文本格式化导航标签
转发文本:“»;”,
背景语:“«
})
});
编辑: 这是添加了新代码的页面的源代码:

<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>

它列出了第一张图表的所有数据点(我在这里漏掉了)它不是动态添加的。

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

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

我真的不知道您为什么要这样做,但您可以让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);

此示例在上找到,并进行了一些调整以适合您的场景。还有其他选择,但这应该在列表中给出您需要做什么的想法。

我真的不知道您为什么要这样做,但您可以让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);


此示例在上找到,并进行了一些调整以适合您的场景。还有其他选择,但这应该在列表中给出您需要做什么的想法。

唯一的问题是,在每次页面加载期间,我还需要添加动态数量的图表。我试着使用一个转发器,但是图表没有显示出来。唯一的问题是,在每次加载页面时,我都会添加动态数量的图表。我试着用一个复读器,但是图表没有显示出来。我的答案对你有用;然而,你想要ul中的图表有什么原因吗?我想它不一定是ul。我想通常只是一个html容器。你的答案对我的申请不起作用。我真正需要的是在标记中插入,在服务器上创建asp图表,并在中插入控件。如果你试着把这些内容放进ul,这是行不通的。我已经用我找到的一个例子更新了我的答案。使用controls.add并不完全有效。我正在使用这个javascript:显示多个图表,而不使页面变大。当我使用controls.add时,它只是将所有图表放在一张幻灯片上,而不是将幻灯片分开。有什么想法吗?我的答案对你有用;然而,你想要ul中的图表有什么原因吗?我想它不一定是ul。我想通常只是一个html容器。你的答案对我的申请不起作用。我真正需要的是在标记中插入,在服务器上创建asp图表,并在中插入控件。如果你试着把这些内容放进ul,这是行不通的。我已经用我找到的一个例子更新了我的答案。使用controls.add并不完全有效。我正在使用这个javascript:显示多个图表,而不使页面变大。当我使用controls.add时,它只是将所有图表放在一张幻灯片上,而不是将幻灯片分开。有什么想法吗?好的,那我怎么能把anythingslider和面板一起使用而不是ul呢?保存图像后如何将其添加到面板中?不能使用面板。直到几分钟前你才告诉我关于“任何东西”滑块的事。请注意,上一次编辑答案是在21分钟前。这只是示例代码,您必须根据您的场景进行更改。你很可能只是将图表控件添加到你的ul中。哈哈,好吧,很抱歉,那么我想我会保留ul,但主要问题是:我现在如何将保存的图表添加到ul中?controls.add仍然没有给出我想要得到的结果。我已经更新了代码,使其更加具体,但您仍然没有显示如何添加图表。好的,那么我如何在面板上使用anythingslider而不是ul?保存图像后如何将其添加到面板中?不能使用面板。直到几分钟前你才告诉我关于“任何东西”滑块的事。请注意,上一次编辑答案是在21分钟前。这只是示例代码,您必须根据您的场景进行更改。你很可能只是将图表控件添加到你的ul中。哈哈,好吧,很抱歉,那么我想我会保留ul,但主要问题是:我现在如何将保存的图表添加到ul中?controls.add仍然没有提供我试图获得的结果。我已经更新了代码,使其更加具体,但您仍然没有显示如何添加图表。