Set Bar Labels C#

Thread is closed for posting
2 posts, 0 answers
  1. William
    William  avatar
    72 posts
    Member since:
    Jun 2011

    Posted 30 Jun 2011 Link to this post

    See attached image. I would like to set the labels under each of the bars in my bar chart. They are currently just 1, 2, and 3. How would I could about manually setting them?

    Here is my code for building that chart:

    protected void makeStockChart()
            {
                RadChart stockChart = new RadChart();
                stockChart.ChartTitle.Visible = false;
                stockChart.Appearance.Border.Visible = false;
                stockChart.Legend.Appearance.Visible = false;
                stockChart.PlotArea.YAxis.Appearance.Visible = Telerik.Charting.Styles.ChartAxisVisibility.False;
                stockChart.PlotArea.Appearance.FillStyle.MainColor = System.Drawing.Color.White;
                stockChart.PlotArea.Appearance.FillStyle.SecondColor = System.Drawing.Color.White;
                stockChart.PlotArea.Appearance.Border.Color = System.Drawing.Color.White;
     
                // Create a ChartSeries and assign its name and chart type
                ChartSeries chartSeries = new ChartSeries();
                chartSeries.Name = "Count";
                chartSeries.Type = ChartSeriesType.Bar;
     
                // Open SQL Connection
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                connection.Open();
                SqlCommand command = new SqlCommand("GetStockData", connection);
                command.CommandType = CommandType.StoredProcedure;
                SqlDataReader reader = command.ExecuteReader();
     
                while (reader.Read())
                {
                    // Pretty up the value
                    string value = string.Format("{0:d}", (reader.GetValue(1)));
                    
                    // Set value and value text
                    ChartSeriesItem chartSeriesItem = new ChartSeriesItem(Convert.ToDouble(reader.GetValue(1)), value);
                    chartSeriesItem.Name = reader.GetValue(0).ToString();
                     
                    chartSeries.AddItem(chartSeriesItem);
                     
                }
                 
                // Close SQL Connection
                connection.Close();
     
                // add the series to the RadChart Series collection
                stockChart.Series.Add(chartSeries);
                // add the RadChart to the page.
                this.stockChart.Controls.Add(stockChart);
                 
            }
  2. William
    William  avatar
    72 posts
    Member since:
    Jun 2011

    Posted 30 Jun 2011 Link to this post

    Nevermind. I figured it out in the ASPX. 
Back to Top