Web page displaying Empty Pie Chart for dynamic values in ASP.Net

Last Reply 7 months ago By narasiman

Posted 8 months ago

i dynamically set the value in pie chart My code as follows

<asp:PieChart ID="PieChart1" runat="server" ChartHeight="300"
ChartWidth="450" ChartTitle="Today's Attendance"
ChartTitleColor="#0E426C">
<piechartvalues>
<asp:PieChartValue Category="Present" Data="80" />
<asp:PieChartValue Category="Absent" Data="10" />
<asp:PieChartValue Category="Leave" Data="10" />

when i run the above code shows the empty pie chart. what is the mistake in my above code.

Posted 7 months ago

in page load code as follows

    DataTable _objdt = new DataTable();
    _objdt = GetDataForChart();
    BindDataToChartcontrol(_objdt);
           

    public void BindDataToChartcontrol(DataTable _objdt)
    {
        Chart1.DataSource = _objdt;
        Chart1.DataBind();

    }

    public DataTable GetDataForChart()
    {
        DataTable _objdt = new DataTable();

        _objdt.Columns.Add("Country", typeof(string));
        _objdt.Columns.Add("Growth", typeof(long));

        _objdt.Columns.Add("LabelValue");
        var _objrow = _objdt.NewRow();
        _objrow["Country"] = "On or Before Time";
        _objrow["Growth"] = 80;

        _objdt.Rows.Add(_objrow);
        _objrow = _objdt.NewRow();
        _objrow["Country"] = "Grace Time";
        _objrow["Growth"] = 15;
        _objdt.Rows.Add(_objrow);

        _objrow = _objdt.NewRow();
        _objrow["Country"] = "Late Time";
        _objrow["Growth"] = 5;
        _objdt.Rows.Add(_objrow);

        return _objdt;
    }

 When i run the above code. pie chart is display