Hi There,
Is there any way where we can find if chart is some data or not. I know it will display "No Data" template when there is no data I want know a property which triggers it. Why I need so because we have chart and some other UI element like grid... which should syn other UI element when there is some data on chart.
Basically I am looking for some property like "IsChartHasSomeData" . Please help me to know this I mean how can we do this.?
7 Answers, 1 is accepted
The chart does not have a property to indicate whether the empty content message is shown. However, you can deduct this from the information in the chart, if it has no series - the empty content message is shown. If it has series, but none of the series have data points - again the message is shown. I suspect that if you use MVVM you can easily track if the chart is fed by some items source or not. Let us know how it goes.
Regards,
Petar Marchev
Telerik
Well..
I did this EmptyContent="{Binding NoDataDisplay,Mode=TwoWay}" . when there is no data " NoDataDisplay" is set with string "No Data to plot."
But when chart gets data above property(EmptyContent) is not Set.Hence so I dont know when data has arrived .
So I still have issue . Please help if you any other idea.
Thankyou
You are mistaken the purpose of the EmptyContent property. It is the content that gets displayed when there is no data. It is not set/reset in order to notify you in code when there is no data.
As I mentioned earlier, if you use MVVM, this means that in the view models you know if you have or have not passed any items for display, so when there are no items, the chart is empty. I will give you a very simple example - if your view model is named MainViewModel, it probably has a property similar to Data. Data is some collection that has a Count property. When the count is zero - there is no data in the chart. When the count is not zero, there is some data in the chart. So, if you use MVVM it should be obvious when there is and when there isn't data in the chart.
Regards,
Petar Marchev
Telerik
Understood. that. We are exposing Observablecollection properties on Viewmodel. this collection be set based on some events...
And events are based on some calculations. So there is need to say that chart has some data or not i.e calculations result data point count may be zero. when Chart has no data we will display some other custom UI elemnts on chart.. for this reason we are looking for some kind of property or some work around.
I am a bit confused. Do you still need our help?
You mentioned that the observable collection is set in some events. If these events are in your view models, you can execute a quick check when they occur - if the observable collection is empty or not. If the collection is empty - the chart is empty. So you can expose a new property in your view models to indicate whether or not there is any data.
Even if these events are not in the view models, you can add a collection changed handler to the observable collection and get the same results.
Once you introduce this IsDataEmpty property in your view models, you can easily update the UI when there is and when there is no data.
Let us know if you need further assistance.
Regards,
Petar Marchev
Telerik
I know we can do this from viewmodel. but due to complexity of view model and event logic we have to write alot of plumbing code.
So was trying to check if we can find any thing on chart itself.
I have attached a small project that demonstrates one possible way to detect whether the empty content presenter is visible or not. Essentially, we are looking inside the visual tree to find the empty content presenter and start listening for visibility changes. We understand that the given work-around is a bit cumbersome and we would suggest that you only use it if you insist on this functionality and cannot achieve it via view models. Let us know if you need more information.
Regards,
Petar Marchev
Telerik