Telerik radChart xaxis datacolumn not showing
-
12-12-2019 - |
Question
I have a datatable that I add to the chart in foreach loop as follow and assigning dtMonth datarow to xaxis of chart, which is month names:
foreach (DataRow dr in dtMD.Rows)
{
DataTable dtMDByName = ocw.GetMDByName(Convert.ToDateTime(txtStartDate.Text), Convert.ToDateTime(txtEndDate.Text), dr["MD"].ToString());
if (dtMDByName.Rows.Count > 0)
{
ChartSeries MDChartSeries = new ChartSeries();
MDChartSeries.Name = dtMDByName.Rows[0][1].ToString();
MDChartSeries.Type = ChartSeriesType.Line;
foreach (DataRow drByName in dtMDByName.Rows)
{
MDChartSeries.AddItem(Convert.ToDouble(drByName["T"]));
radMD.PlotArea.XAxis.DataLabelsColumn = drByName["dtMonth"].ToString();
}
radMD.ChartTitle.TextBlock.Text = "MDs";
radMD.PlotArea.XAxis.AutoScale = true;
radMD.Series.Add(MDChartSeries);
}
}
but still it shows as numbers in xaxis, anything im doing wrong in above code?
even if I do it outside the second loop i.e following code still it doesn't show month names:
radMD.PlotArea.XAxis.DataLabelsColumn = "dtMonth";
Thanks
Solution
found out you need to set autoscale to false and then add textblock as follow:
radMD.PlotArea.XAxis.AutoScale = true;
for (int i = 0; i < dtMDByName.Rows.Count; i++)
{
radMD.PlotArea.XAxis[i].TextBlock.Text = dtMDByName.Rows[i][3].ToString();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow