Hi,
I'm working on a bar chart and what I want is the intervals that are calculated once the graph is created.
So for instance, I know the interval is 1,000 in the chart below.
I looked into the NumericYAxis and tried Interval, TickMarkValues and ActualTickMarkValues, but they are zero.
Hello Wai,
Thank you for your post. I have been looking into your question and the NumericYAxis has a ActualTickmarkValues property that you can use to get the interval. You can get the values of the axis, by calling the MajorValues and you can calculate the interval based on two sequential values:
NumericYAxis y = xmDataChart.Axes[1] as NumericYAxis;
var vals = y.ActualTickmarkValues.MajorValues();
if (vals.Count() > 1)
{
double interval = vals.ElementAt(1) - vals.ElementAt(0);
}
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir, MCPD
Developer Support Supervisor - XAML
Infragistics
www.infragistics.com/support
Hi Krasimir,
I tried your suggestion, but the count is 1 (not 2) and the value is zero.
At what point should I be checking this? I am checking at Loaded event on the page.
Thank you for your reply. I have been looking into your question and you can use the RangeChanged event of the Axis to get the interval and add the code that I have suggested in a Dispatcher, in order to provide the XamDataChart the time to calculate the range:
private void yAxis_RangeChanged(object sender, AxisRangeChangedEventArgs e)
Dispatcher.BeginInvoke(new Action(() =>
NumericYAxis y = xamDataChart1.Axes[1] as NumericYAxis;
MessageBox.Show("Iterval is " + interval);
}));
I have created a sample for you, that shows how you can implement this approach.
I tried your example and it does not work. The dispatcher runs async so the datachart may not be finished by the
time the dispatcher runs. If I put a breakpoint and wait, it will return the intervals, but it’s hit and miss otherwise.
Let me explain what I’m trying to do. I have a barchart where the values appear above each bar. For values that
appear right close to the maximum value, the value gets cut off, hence I wanted to increase the maximum value
by 1 interval (see image below).
If you could suggest an alternative approach that would be fine.
Thank you for the clarification on your scenario. I have create a sample application that shows how you can use the approach I have suggested to implement your requirement.
I tried your example and it worked sometimes, sometimes it returned the wrong value as per my last note.
When I implemented it in my project it only worked after I left the view.
Anyways, I found an alternate solution to get the desired result.
Thanks for the help.
Thank you for your reply. I am very glad that you have managed to implement your requirement. Please let me know if you need any further assistance on the matter.