By Marina Koronidou - Thursday, November 8, 2012
Hi,
I am implementing a report where the data displayed change depending on values selected by the user.
The user clicks on a NEXT and PREVIOUS buttons, that change the date ranges and in turn this changes the data displayed.
However, there is the possibility that no data exist for a particular date range.
So I had the idea of creating an empty chart to replace the initial chart every time there is no data.
For this to look nicer, I need to hide the x axis that is displayed by default and add a message in the middle of the chart informing the user that there is no data available.
I have been searching for this for hours but I was not able to find a solution.
Can anyone give me a suggestion maybe? Thanks Marina
|
By Nevron Support - Thursday, November 8, 2012
Hi Marina,
For the message you can use a NLabel object like this one:
NLabel label = new NLabel(); label.Text = "No data selected"; label.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(50, NRelativeUnit.ParentPercentage)); label.ContentAlignment = ContentAlignment.MiddleCenter; label.Visible = false; nChartControl1.Panels.Add(label);
When it happens that data does not exist you can clear the chart series, hide the axes and make the "no data" label visible:
chart.Series.Clear(); chart.Axis(StandardAxis.PrimaryY).Visible = false; chart.Axis(StandardAxis.PrimaryX).Visible = false; label.Visible = true;
Here we don't replace the whole chart, but simply clear some of its settings to make it look empty.
|
By Marina Koronidou - Thursday, November 8, 2012
Thanks, this approach works just fine.
My problem however now is that I am not able to keep the chart's title.
I was using the control.Panels.Add(title); command to add the title in my report and now this has stopped working...
|
By Nevron Support - Friday, November 9, 2012
Hi Marina,
The chart control can display multiple labels at the same time and the title shouldn't be affected. We were not able to reproduce this behavior, so can you please explain in more detail what happens?
|
By Marina Koronidou - Friday, November 9, 2012
Well I used AddHeader method instead and now it works.
I should have been using this method for the chart title anyway 
Thanks again for the help!
|
|