This is a migrated thread and some comments may be shown as answers.

Set Bar Labels C#

1 Answer 73 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 30 Jun 2011, 04:07 PM
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);
             
        }

1 Answer, 1 is accepted

Sort by
0
William
Top achievements
Rank 1
answered on 30 Jun 2011, 08:41 PM
Nevermind. I figured it out in the ASPX. 
Tags
Chart (Obsolete)
Asked by
William
Top achievements
Rank 1
Answers by
William
Top achievements
Rank 1
Share this question
or