This is a migrated thread and some comments may be shown as answers.

How to get actual visable range when scrolling

2 Answers 97 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Coder
Top achievements
Rank 1
Coder asked on 17 Feb 2014, 04:28 AM
Hi,

I am using a RadCartesianChart with DateTimeCategoricalAxis.

I want to be able to get the actual minimum and maximum values seen on my chart for both the x and y axis everytime I scroll.

I also want to be able to get the data item on mouse click, or the collection of items on mouse drag.

Is it possible to do this? If so, how?

I have tried everything, but this nothing works.

Can Telerik chart support this, or should I be looking elsewhere?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 18 Feb 2014, 03:49 PM
Hi,

You can get the actual minimum and maximum values after scroll by using the ActualVisibleRange property. Note that this property is available only on numerical axes and you cannot get such a range in a categorical axis. You can implement your logic in the RadCartesianChart.ZoomChanged event handler which is invoked every time you zoom in or zoom out.

As for your second requirement you could use the RadCartesianChart.ConvertPointToData() method, which gets the coordinates of the mouse and creates a data item based on them.
private void RadCartesianChart_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    Point mousePosition = e.GetPosition(this.Chart);
    DataTuple tuple = this.Chart.ConvertPointToData(mousePosition, this.horizontalAxis, this.verticalAxis);
     
    DateTime Category = (DateTime)tuple.FirstValue;
 
    var dataItems = ((ICollection<DataItem>)(this.Chart.Series[0] as LineSeries).ItemsSource).Where(x => x.Category == Category);
}

Another option would be to use the Selection Behavior of the ChartView and handle its SelectionChanged event. You could also take a look at the Selection demo available with our UI for WPF Demos - once you install the demos locally, navigate to the ChartView example and then select the Selection example.

Regards,
Martin
Telerik
0
Coder
Top achievements
Rank 1
answered on 19 Feb 2014, 04:11 AM
Thanks. I used this approach to get the min and max datetimes on each side of the chart for every PanOffsetChange

First I calculated the min and max offsets like this:

            Point newMinPoint = new Point(chart.PlotAreaClip.X + e.NewPanOffset.X, 0);
            Point newMaxPoint = new Point(chart.PlotAreaClip.X + +e.NewPanOffset.X + chart.PlotAreaClip.Width, 0);

then I used ConvertPointToData to get the actual DateTime for these points.
Tags
ChartView
Asked by
Coder
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Coder
Top achievements
Rank 1
Share this question
or