Hi team ,
I am using Telerik UI for winforms Chartview Drill down charts. I am using line series . I need to get the labels on top of every value( please refer attached screenshot of demo app) but getting object reference not set to an instance of an object .particularly in line series.ShowLabels = true; Can you please guide on this?
If I set
series.DataSource = DrillDownViewModel.ParseDataByDay(year, month);series.ShowLabels = true;
series.DrawLinesToLabels = true;
series.SyncLinesToLabelsColor = false;
Thanks
Anup
2 Answers, 1 is accepted
Hi Anup,
Thank you for the provided details.
If I have correctly understood you, an exception is raised in your project. To avoid any misunderstanding, would it be possible to isolate this exception in a standalone project and send it to me? This way I can more carefully investigate what is causing this exception and have a better look at the RadChartView control set-up.
I am looking forward to your reply.
Regards,
Dinko | Tech Support Engineer
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Sure Dinko, I will do a sample project and send you.
Hi Dinko,
Here is the sample project link.
If I uncomment line number 314 in the file charts.cs , the error pops up .
Please do the needful
Thanks
Anup
Hello Anup,
Thank you for the provided project. It was helpful to identify the exception.
This exception comes from the smart labels engine. It turns out that calling the FillBarSeries() method before the LineSeries is added to the chart will trigger a chain of methods and smart labels mode will try to recalculate each point. However, the points are still not added to the chart so their View property will be null which triggers the exception. To make this work, you can move the FillBarSeries() method after the series is added to the chart.
void radChartView1_Drill(object sender, DrillEventArgs e)
{
foreach (Control control in tabControl1.SelectedTab.Controls)
{
// You can access each control and its properties here
if (control is RadChartView)
{
RadChartView radChartView1 = (RadChartView)control;
Telerik.WinControls.UI.CartesianSeries series = new Telerik.WinControls.UI.BarSeries();
series.ShowLabels = true;
//series.LabelMode = BarLabelModes.Top;
series.ValueMember = "Value";
series.CategoryMember = "Date";
DateTimeCategoricalAxis horizontalAxis = new DateTimeCategoricalAxis();
CartesianArea area = e.View.GetArea<CartesianArea>();
area.ShowGrid = true;
horizontalAxis.GapLength = 0.25;
LinearAxis verticalAxis = new LinearAxis();
verticalAxis.AxisType = Telerik.Charting.AxisType.Second;
verticalAxis.Title = yAxisTitle;
CartesianGrid grid = area.GetGrid<CartesianGrid>();
grid.DrawHorizontalStripes = true;
grid.DrawVerticalStripes = true;
// radChartView1.ShowTrackBall = false;
switch (e.Level)
{
case 0:
series.DataSource = DrillDownViewModel.ParseDataByYear();
radChartView1.Title = "Chart of " + tabControl1.SelectedTab.Text +"";
radChartView1.ChartElement.TitleElement.Font = new Font("Arial", 12);
grid.DrawVerticalStripes = false;
FillBarSeries(series);
break;
case 1:
if (e.SelectedPoint != null)
{
month = ((DrillDownDataInfo)e.SelectedPoint.DataItem).Date.Month;
}
series.DataSource = drillDownViewModel.ParseDataByDay("A", System.Convert.ToString(month), "2023", tabControl1.SelectedTab.Text);
radChartView1.Title = "Chart of " + tabControl1.SelectedTab.Text + " for: " + $"{month:D2}" ;
radChartView1.ChartElement.TitleElement.Font = new Font("Arial", 12);
horizontalAxis.LabelFormat = "{0:dd}";
horizontalAxis.Title = "Days";
grid.DrawVerticalStripes = false;
// FillBarSeries(series); remove this
break;
case 2:
if (e.SelectedPoint != null)
{
hour = ((DrillDownDataInfo)e.SelectedPoint.DataItem).Date.Hour;
day = ((DrillDownDataInfo)e.SelectedPoint.DataItem).Date.Day;
month = ((DrillDownDataInfo)e.SelectedPoint.DataItem).Date.Month;
}
series.ValueMember = "Value";
series.CategoryMember = "Date";
series.DataSource = drillDownViewModel.ParseDataByHour("A", day, month, "2023", tabControl1.SelectedTab.Text);
//series.DataSource = drillDownViewModel.ParseDataByHour(System.Convert.ToString(ddlSiteRef.Text), hour, day, System.Convert.ToString(ddlMonths.SelectedValue), System.Convert.ToString(ddlYear.Text), tabControl1.SelectedTab.Text);
//series.ShowLabels = true;
//series.DrawLinesToLabels = true;
//series.SyncLinesToLabelsColor = false;
radChartView1.Title = " Chart of " + tabControl1.SelectedTab.Text + " for: " + $"{day:D2}" + "/" + $"{month:D2}" + "/" + "";
radChartView1.ChartElement.TitleElement.Font = new Font("Arial", 12);
horizontalAxis.LabelFormat = "{0:hh:mm tt}";
horizontalAxis.Title = "Hours";
horizontalAxis.LabelFitMode = AxisLabelFitMode.Rotate;
horizontalAxis.LabelRotationAngle = 310;
grid.DrawVerticalStripes = false;
// FillBarSeries(series); remove this
break;
case 3:
if (e.SelectedPoint != null)
{
hour = ((DrillDownDataInfo)e.SelectedPoint.DataItem).Date.Hour;
day = ((DrillDownDataInfo)e.SelectedPoint.DataItem).Date.Day;
month = ((DrillDownDataInfo)e.SelectedPoint.DataItem).Date.Month;
}
series = new LineSeries();
series.ValueMember = "Value";
series.CategoryMember = "Date";
series.ShowLabels = true;
series.DataSource = drillDownViewModel.ParseDataByMinute("A", hour, day, month, "2023", tabControl1.SelectedTab.Text);
series.DrawLinesToLabels = true;
series.SyncLinesToLabelsColor = false;
radChartView1.Title = " Chart of " + tabControl1.SelectedTab.Text + " for: " + $"{day:D2}" + "/" + $"{month:D2}" + "";
radChartView1.ChartElement.TitleElement.Font = new Font("Arial", 12);
horizontalAxis.LabelFormat = "{0:hh:mm tt}";
horizontalAxis.Title = "Minutes";
horizontalAxis.LabelFitMode = AxisLabelFitMode.Rotate;
horizontalAxis.LabelRotationAngle = 310;
grid.DrawVerticalStripes = false;
// FillBarSeries(series); remove this
break;
}
e.View.Axes.Clear();
series.HorizontalAxis = horizontalAxis;
series.VerticalAxis = verticalAxis;
e.View.Series.Clear();
e.View.Series.Add(series);
FillBarSeries(series);
FillColors(e.View, KnownPalette.Forest);
}
}
}
This way the exception is not raised on my side. I hope it will work also in your application.
Regards,
Dinko | Tech Support Engineer
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.