简体   繁体   中英

Binding data with chart's points

I am using coulmn chart in which i want to bind coulmn of table with series's
points .I know points.databind() method .but what type of object it take as first parameter???

.aspx Code:

<asp:Chart ID="Chart1" runat="server">
    <Series>
        <asp:Series Name="Series1">                
            </Points>
        </asp:Series>
    </Series>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1">
        </asp:ChartArea>
    </ChartAreas>
</asp:Chart>

Code Behind:

protected void Page_Load(object sender, EventArgs e)
{
    assessdal d=new assessdal();
    Chart1.DataSource = d.showop1();
    Chart1.DataBind();

    Chart1.Series[0].Points.DataBind(?,"qno");
}

public DataSet showop1()
{
    SqlConnection con = dbconnect.GetConnection();
    SqlCommand cmd = new SqlCommand("select assessid, qno ,description, 

    option1,option2,option3,option4 from assessmenttest", con);
    SqlDataAdapter ad =new SqlDataAdapter(cmd);
    DataSet ds=new DataSet();
    ad.Fill(ds);
    return ds;
}

If i were right, in that example (from where u taken the above code) they use datareader to bind the charts .

U are using dataset to bind.

so do as follows... if u have more rows to bind. (more than 1 series)

    for each (DataRow row in dssearchgrid.Tables[0].Rows)
    {
        string seriesName = row["sno"].ToString();
        Chart1.Series.Add(seriesName);
        Chart1.Series[seriesName].ChartType = SeriesChartType.Line;
        Chart1.Series[seriesName].BorderWidth = 2;

 for (int colIndex = 1; colIndex < dssearchgrid.Tables[0].Columns.Count; colIndex++)
        {
            // For each column (column 1 and onward) add the value as a point
            string columnName = dssearchgrid.Tables[0].Columns[colIndex].ColumnName;
            if (row[columnName] != "")
            {
                YVal = Convert.ToInt32(row[columnName]);
            }
            else
            {
                YVal = 0;
            }

            Chart1.Series[seriesName].Points.AddXY(columnName, YVal);
        }

i konw this is not the proper way... but this is what i know :-)

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