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

XAxis.AxisLabel don't appear and instead a serie item name, appear only numbers.

6 Answers 230 Views
Chart (obsolete as of Q1 2013)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Lourival de Souza Junior
Top achievements
Rank 1
Lourival de Souza Junior asked on 14 Aug 2010, 08:41 PM
Hi,
i'm trying to create a SIMPLE CHART that shows a title, legend, XAxis.AxisLabel and a XAxis itens label.   XAxis.AxisLabel don't appear and instead a serie item name, appear only numbers. See attachments. What's wrong with the code below? Tks. Lourival.

RadChart1.Series.Clear()
RadChart1.ChartTitle.TextBlock.Text = "My Chart"
Dim chartSeries As ChartSeries = RadChart1.CreateSeries("2009", System.Drawing.Color.RoyalBlue, System.Drawing.Color.LightSteelBlue, ChartSeriesType.Bar)
chartSeries.AddItem(120, "")
chartSeries.AddItem(140, "")
chartSeries.AddItem(35, "")
chartSeries.AddItem(120, "")
chartSeries.AddItem(140, "", System.Drawing.Color.Red)
chartSeries.AddItem(35, "")
chartSeries.AddItem(120, "")
chartSeries.AddItem(140, "")
RadChart1.Series.Add(chartSeries)
chartSeries.Appearance.LabelAppearance.Visible = False
Dim chartSeries2 As ChartSeries = RadChart1.CreateSeries("2010", System.Drawing.Color.DarkBlue, System.Drawing.Color.LightBlue, ChartSeriesType.Bar)
chartSeries2.AddItem(120, "")
chartSeries2.AddItem(140, "")
chartSeries2.AddItem(35, "")
chartSeries2.AddItem(120, "")
chartSeries2.AddItem(140, "")
chartSeries2.AddItem(35, "")
chartSeries2.AddItem(120, "")
chartSeries2.AddItem(140, "")
RadChart1.Series.Add(chartSeries)
chartSeries2.Appearance.LabelAppearance.Visible = False
RadChart1.PlotArea.XAxis.AxisLabel.TextBlock.Text = "Months"
RadChart1.PlotArea.XAxis.AxisLabel.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.Red
RadChart1.PlotArea.XAxis.AddRange(1, 8, 1)
RadChart1.PlotArea.XAxis(0).TextBlock.Text = "Jan"
RadChart1.PlotArea.XAxis(1).TextBlock.Text = "Fev"
RadChart1.PlotArea.XAxis(2).TextBlock.Text = "Mar"
RadChart1.PlotArea.XAxis(3).TextBlock.Text = "Abr"
RadChart1.PlotArea.XAxis(4).TextBlock.Text = "Mai"
RadChart1.PlotArea.XAxis(5).TextBlock.Text = "Jun"
RadChart1.PlotArea.XAxis(6).TextBlock.Text = "Jul"
RadChart1.PlotArea.XAxis(7).TextBlock.Text = "Ago"
RadChart1.DataBind()

6 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 18 Aug 2010, 11:58 AM
Hi Lourival de Souza Junior,

You need to set the AutoScale property of XAxis before calling AddRange. Omitting this the chart actaully ignores your subsequent settings. So, please add this line before the call to XAxis.AddRange:

RadChart1.PlotArea.XAxis.AutoScale = false;

Sincerely,
Ves
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
n/a
Top achievements
Rank 1
answered on 30 Aug 2010, 10:13 AM
Same here, setting AutoScale = false, don't shows the AxisLabel or the ItemNames.

Andy
0
Phillip Foster
Top achievements
Rank 1
answered on 30 Aug 2010, 03:00 PM
I'm also not getting this to work properly. I'm able to get the labels to change with the following code, but it only shows half the chart. There should be 24 intervals, but i'm only showing 13 or so. Any info would help. 

private void GetVolume()
 {
            rcVolume.Series.Clear();
            DateTime dtCurrent = calTrackedStart.SelectedDate;
            DataTable dtVolume = new DataTable();
             
            ChartSeries series = new ChartSeries("Category", ChartSeriesType.Bar, rcCBSummary.Series);
            while (dtCurrent <= calTrackedEnd.SelectedDate)
             {
                 
                dtVolume = webservice.GetAvayaArrivalPattern(dtCurrent);
 
                if (dtVolume.Rows.Count > 0)
                {
                    series = new ChartSeries(Convert.ToDateTime(dtVolume.Rows[0].ItemArray[0]).ToShortDateString(), ChartSeriesType.Line, rcCBSummary.Series);
                    for (int i = 0; i < dtVolume.Rows.Count; i++)
                        series.Items.Add(new ChartSeriesItem(Convert.ToInt16(dtVolume.Rows[i].ItemArray[2])));
                                         
                    rcVolume.Series.Add(series);
                    rcVolume.Refresh();
                }
 
                dtCurrent = dtCurrent.AddDays(1);
            }
 
            rcVolume.PlotArea.XAxis.Clear();
            rcVolume.PlotArea.XAxis.AutoScale = false;
             
            string intrvl = "0000";
            rcVolume.PlotArea.XAxis.AddRange(1, 24, 1);
            for (int k = 0; k < 24; k++)
            {
                intrvl = dtVolume.Rows[k].ItemArray[1].ToString();
                if (intrvl.Length < 4)
                    intrvl = "0" + intrvl;
 
                rcVolume.PlotArea.XAxis[k].TextBlock.Text = intrvl;
            }
            rcVolume.Refresh();
}
0
Ves
Telerik team
answered on 01 Sep 2010, 04:20 PM
Hi Phillip Foster,

I copied your code, filled the chart with fake data and it seems to work fine for me. Please, find attached my example along with the resulting chart.

Regards,
Ves
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Eduan Marais
Top achievements
Rank 2
answered on 19 Jan 2011, 02:59 PM
Hi.

I have a simular problem.
I populate a dataset based on the graph that I want to display. The dataset returns with a table that has 2 fields - the date, and a value
The value displays correctly, but the XAxis is displaying the number instead of the date.
If I set the AutoScale to true, all the data is not displayed in the plot area.

This is my code.

groupboxGraph.Text = "Test Graph";
data = new dsData(); 
data = ReadGraphData(TestGraph);
radChartSiloGraph.DataSource = data.tblData; 
radChartSiloGraph.DataBind();
radChartSiloGraph.ChartTitle.TextBlock.Text = "Test Graph"; 
radChartSiloGraph.DefaultType = ChartSeriesType.SplineArea; 
radChartSiloGraph.Series[0].Appearance.FillStyle.MainColor = Color.Fuchsia; 
radChartSiloGraph.Series[0].Appearance.TextAppearance.TextProperties.Color = Color.White;  
radChartSiloGraph.PlotArea.YAxis.AxisMode = ChartYAxisMode.Extended;


Also see attached screenshot of incorrect graph.

Thanks

Eduan



 

 

 

 

 

0
Ves
Telerik team
answered on 24 Jan 2011, 02:49 PM
Hi Eduan,

In order to databind RadChart with DateTime values you need to ensure that several conditions are met:

  • Make sure the data sent to chart contains the OLEAutomation equivalent of DateTime. It is a double, obtained through the ToOADate() method of DateTime.
  • Create a ChartSeries object, set its DataYColumn property with the name of the column, holding the values and set its DataXColumn property with the name of the column, holding the dates (the one with the double values, discussed in the above bullet). Then add this ChartSeries to radChart1.Series collection.
  • Set appropriate format for the X axis labels: radChart1.PlotArea.XAxis.Appearance.ValueFormat = Telerik.Charting.Styles.ChartValueFormat.ShortDate; In addition, you may want to set the radChart1.PlotArea.XAxis.Appearance.CustomFormat property in order to specify another DateTime formatting string.
  • Set radChart1.PlotArea.XAxis.IsZeroBased property to false, so that the axis range is calculated to focus on the data. This is needed as OLEAutomation date represents the number of days since 12/30/1899 and you do not need to cover all the period, but only the period where your data lies.
  • Finally, you can check this forum thread for an example of a sql query, which will convert the DateTime values to their OLE automation equivalents.

Best regards,
Ves
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
Tags
Chart (obsolete as of Q1 2013)
Asked by
Lourival de Souza Junior
Top achievements
Rank 1
Answers by
Ves
Telerik team
n/a
Top achievements
Rank 1
Phillip Foster
Top achievements
Rank 1
Eduan Marais
Top achievements
Rank 2
Share this question
or