在'SeriesCollection'中找不到名为'LightBlue'的图表元素。 [英] A chart element with the name 'LightBlue' could not be found in the 'SeriesCollection'.

查看:1331
本文介绍了在'SeriesCollection'中找不到名为'LightBlue'的图表元素。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到此错误:

I am encountering this error:

在'SeriesCollection'中找不到名为'LightBlue'的图表元素。
A chart element with the name 'LightBlue' could not be found in the 'SeriesCollection'.



我的ASP.NET模板源


My ASP.NET template source

<%@ Page Language="C#" AutoEventWireup="true" 

   CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Chart ID="Chart1" runat="server">
            <Legends>
                <asp:Legend Name="Legend1">
                </asp:Legend>
            </Legends>
            <Titles>
                <asp:Title Name="Title1">
                </asp:Title>
            </Titles>
             <Series>
         <asp:Series Name="Series1" ChartType="StackedBar100" ></asp:Series>
     </Series>
            <MapAreas>
                <asp:MapArea Coordinates="0,0,0,0" />
            </MapAreas>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea1">
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
    </div>
    </form>
</body>
</html>





我的C#代码隐藏



My C# code-behind

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.UI.DataVisualization.Charting;
public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // Populate series data
        Random random = new Random();
        for (int pointIndex = 0; pointIndex < 10; pointIndex++)
        {
            Chart1.Series["Series1"].Points.AddY(random.Next(45, 95));
        }
        // Set chart type
        Chart1.Series["Series1"].ChartType = SeriesChartType.StackedArea100;
        // Show point labels
        Chart1.Series["Series1"].IsValueShownAsLabel = true;
        // Disable X axis margin
        Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;
        // Enable 3D
        Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;

        //// Set the first two series to be grouped into Group
        Chart1.Series["LightBlue"]["StackedGroupName"] = "Group1";
        Chart1.Series["Gold"]["StackedGroupName"] = "Group1";
        //// Set the last two series to be grouped into Group2
        Chart1.Series["Red"]["StackedGroupName"] = "Group2";
        Chart1.Series["DarkBlue"]["StackedGroupName"] = "Group2";
    }
}

推荐答案

venkysmv85写道:
venkysmv85 wrote:



< asp:removed name =Series1charttype =StackedBar100xmlns:asp =#unknown>


<asp:removed name="Series1" charttype="StackedBar100" xmlns:asp="#unknown">





您只需定义此系列!现在你尝试从哪里访问'LightBlue'?







You just define this Series! Now you try to access 'LightBlue' from where?


venkysmv85写道:
venkysmv85 wrote:

Chart1.Series [LightBlue] [StackedGroupName] =Group1; Chart1.Series [Gold] [StackedGroupName] =Group1; ////设置要分组为Group2的最后两个系列Chart1.Series [Red] [StackedGroupName] =Group2; Chart1.Series [DarkBlue] [StackedGroupName] =Group2;

Chart1.Series["LightBlue"]["StackedGroupName"] = "Group1"; Chart1.Series["Gold"]["StackedGroupName"] = "Group1"; //// Set the last two series to be grouped into Group2 Chart1.Series["Red"]["StackedGroupName"] = "Group2"; Chart1.Series["DarkBlue"]["StackedGroupName"] = "Group2";





在我看来,不仅仅是LightBlue,Gold,Red, DarkBlue都是未定义的。你有什么不能得到的?您刚刚在系列集中定义了一个系列。即Series1就是这样!在尝试访问/修改它们之前添加其他系列。



[来自WW:不确定是谁在贬低我们的答案...因为我们所说的是正确的......所以我扔了你的方式]



Looks to me, not just LightBlue, Gold, Red, DarkBlue all are undefined. What were you unable to get? You have just defined one series in your series collection. i.e. Series1 thats it! Add other series before trying to access/modify them.

[From WW: Not sure who's downvoting our answers...since what we said was correct...so I threw a 5 your way]


我不太熟悉Chart控件,但我可以告诉你,你肯定没有正确使用它。请参阅 Microsoft图表控件的示例环境 [< a href =http://code.msdn.microsoft.com/mschart/Release/ProjectReleases.aspx?ReleaseId=1591target =_ blanktitle =New Window> ^ ]第一个数组索引系列必须是系列的名称。示例代码中的一些示例:



I'm not very familiar with the Chart control, but I can tell you that you're definitely not using it correctly. Have a look at the microsoft samples at Samples Environment for Microsoft Chart Controls[^] The first array index in a Series has to be the name of the series. A few examples from the sample code:

// Set point width of the series
Chart1.Series["Series1"]["PointWidth"] = BarWidthList.SelectedItem.Text;
Chart1.Series["Series2"]["PointWidth"] = BarWidthList.SelectedItem.Text;
// Set drawing style
Chart1.Series["Series1"]["DrawingStyle"] = this.DrawingStyle.SelectedItem.Text;
Chart1.Series["Series2"]["DrawingStyle"] = this.DrawingStyle.SelectedItem.Text;


这是因为你没有在你的aspx中定义[LightBlue]。如果观察者是Series1,系列的名称是在aspx中定义的,那么现在.net框架会搜索名为LightBlue的系列并且找不到它。
This is because you have not defined ["LightBlue"] in your aspx. If you observer Series1, the name of the series is defined in aspx, now the .net framework searches for a series named "LightBlue" and does not find it.


这篇关于在'SeriesCollection'中找不到名为'LightBlue'的图表元素。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆