0

my bar chart is not displaying on my web page..help me on how to make it visible by setting the barchat.visible...thats where am getting the error.

public void BindGrid()
{
    string query = "select Customer, COUNT([Total Amount]) [Total Amount] from CustomerDebts group by Customer";
    DataTable dt = GetData(query);

    string[] x = new string[dt.Rows.Count];
    decimal[] y = new decimal[dt.Rows.Count];
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        x[i] = dt.Rows[i][0].ToString();
        y[i] = Convert.ToInt32(dt.Rows[i][1]);
    }
    BarChart1.Series.Add(new AjaxControlToolkit.BarChartSeries { Data = y });
    BarChart1.CategoriesAxis = string.Join(",", x);
     if (x.Length > 3)
    {
        BarChart1.ChartWidth = (x.Length * 150).ToString();
    }
    BarChart1.Visible;
}

private static DataTable GetData(string query)
{
    DataTable dt = new DataTable();
    string constr = TraceBizCommon.Configuration.ConfigSettings.ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand(query))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.CommandType = CommandType.Text;
                cmd.Connection = con;
                sda.SelectCommand = cmd;
                sda.Fill(dt);
            }
        }
        return dt;
    }
}
James Z
  • 12,209
  • 10
  • 24
  • 44
john kc
  • 45
  • 5

1 Answers1

0

BarChart.Visible is a property that needs an assignment, such as;

BarChart.Visible = true;

Take a look at the example here: https://www.aspsnippets.com/Articles/ASPNet-AJAX-Bar-Chart-Control-Populate-from-Database-example.aspx

Further information on the Chart class can be seen here: https://msdn.microsoft.com/en-us/library/system.web.ui.datavisualization.charting.chart(v=vs.110).aspx

James
  • 66
  • 2
  • Thanks James..its now visible..i only now have one problem..the barchart i want it to display the customer and the total amount but now it displays the customer but the amount is in decimals .kindly help – john kc Dec 10 '17 at 08:54
  • John, it probably has to do with your "y" variable being declared as decimal[] y = new decimal[dt.Rows.Count]; Maybe change that to int[] y = new int[dt.Rows.Count]; just a guess. – James Dec 12 '17 at 00:26