none
Non-invocable member 'System.Web.UI.DataVisualization.Charting.Chart.Series' cannot be used like a method.

    คำถาม

  • Hi there.

    I try this statement but I have error, why?

    Can you help me?

    <%@ Page Title="Home page" Language="C#" AutoEventWireup="true" %>
    
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.Odbc" %>
    <%@ Import Namespace="System.Drawing" %>
    <%@ Import Namespace="System.IO" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Import Namespace="System.Linq" %>
    <%@ Import Namespace="System.Configuration" %>
    <%@ Import Namespace="System.Security.Principal" %>
    <%@ Import Namespace="System.Text" %>
    <%@ Import Namespace="DocumentFormat.OpenXml" %>
    <%@ Import Namespace="DocumentFormat.OpenXml.Presentation" %>
    <%@ Import Namespace="DocumentFormat.OpenXml.Packaging" %>
    <%@ Import Namespace="DocumentFormat.OpenXml.Drawing" %>
    
    
    <%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
    <title>Grafico</title>
    
    <script runat="server"> 
    
    
       private void Page_Load(object sender, System.EventArgs e)
       {
           
    
           OdbcConnection myConnectionString = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
           myConnectionString.Open();
    
           String strQuery = " SELECT Region, Number " +
                             " FROM myFirstTabelMysql; ";
                               
           OdbcCommand objCmd = new OdbcCommand(strQuery, myConnectionString);
           objCmd.CommandType = CommandType.Text;
           objCmd.CommandText = strQuery;
    
           Chart1.Series("Default").Points.DataBindXY(objCmd.ExecuteReader, "Region", objCmd.ExecuteReader, "Number");
    
           myConnectionString.Close();
           myConnectionString.Dispose();
    
       }   
    </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
    
    <asp:Chart ID="Chart1" runat="server" Width="550" Height="350"> 
       <Series> 
          <asp:Series Name="Default" ChartType="Bar" Palette="Chocolate" ChartArea="ChartArea1"></asp:Series> 
       </Series> 
        
       <ChartAreas> 
          <asp:ChartArea Name="ChartArea1" Area3DStyle-Enable3D="true"> 
          </asp:ChartArea> 
       </ChartAreas> 
    </asp:Chart>
    
    
        </div>
        </form>
    </body>
    </html>

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1955: Non-invocable member 'System.Web.UI.DataVisualization.Charting.Chart.Series' cannot be used like a method.

    Source Error:

    Line 598:       objCmd.CommandText = strQuery;
    Line 599:
    Line 600:       Chart1.Series("Default").Points.DataBindXY(objCmd.ExecuteReader, "Region", objCmd.ExecuteReader, "Number");
    Line 601:
    Line 602:       myConnectionString.Close();


    28 กุมภาพันธ์ 2555 10:37

คำตอบ

ตอบทั้งหมด

  • Series is a collection; use square brackets; e.g. Chart1.Series["Default"]...
    • ทำเครื่องหมายเป็นคำตอบโดย cms9651 10 เมษายน 2555 20:00
    1 มีนาคม 2555 9:44
  • Series is a collection; use square brackets; e.g. Chart1.Series["Default"]...

    thanks for ur reply, but:

       private void Page_Load(object sender, System.EventArgs e)
       {
           
    
           OdbcConnection myConnectionString = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
           myConnectionString.Open();
    
           String strQuery = " SELECT Region, Number " +
                             " FROM myFirstTabelMysql; ";
                               
           OdbcCommand objCmd = new OdbcCommand(strQuery, myConnectionString);
           objCmd.CommandType = CommandType.Text;
           objCmd.CommandText = strQuery;
    
           Chart1.Series["Default"].Points.DataBindXY(objCmd.ExecuteReader, "Region", objCmd.ExecuteReader, "Number");
    
           myConnectionString.Close();
           myConnectionString.Dispose();
    
       }   


    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1502: The best overloaded method match for 'System.Web.UI.DataVisualization.Charting.DataPointCollection.DataBindXY(System.Collections.IEnumerable, params System.Collections.IEnumerable[])' has some invalid arguments

    6 มีนาคม 2555 12:40