Chart auto scale Y

0 Answers 109 Views
Chart
Rick
Top achievements
Rank 1
Iron
Rick asked on 01 Jul 2023, 01:42 AM

Hi,

 

  how can I auto scale the chart on the Y axis when the plotted area changes?  I couldn't find it anywhere in the doc.  Thank you!

Rick
Top achievements
Rank 1
Iron
commented on 01 Jul 2023, 04:04 PM

So got a chart autoscale Y working.  My code is complex, but the basic is to set the Minimum and Maximum values of the Y axis with the desired values.  This is my code:

// Auto scale Y on chart event
private void ChartAutoScale()
{
    var oldYMin = this.chartYAxis.Minimum;
    var oldYMax = this.chartYAxis.Maximum;

    var newYMin = this.chartData != null && this.chartData.Any(t => t.Category >= this.minPeriod && t.Category <= this.maxPeriod)
        ? (double)this.chartData.Where(t => t.Category >= this.minPeriod && t.Category <= this.maxPeriod).Min(t => t.Value)
        : 0;
    if (newYMin != oldYMin)
        this.chartYAxis.Minimum = newYMin;

    var newYMax = this.chartData != null && this.chartData.Any(t => t.Category >= this.minPeriod && t.Category <= this.maxPeriod)
        ? (double)this.chartData.Where(t => t.Category >= this.minPeriod && t.Category <= this.maxPeriod).Max(t => t.Value)
        : 0;

    if (newYMax != oldYMax)
        this.chartYAxis.Maximum = newYMax;
}

My problem now is I cannot attach this method to the mouse wheel zoom or pan behavior of the chart.  It seems the OnManipulationDelta and OnPointerWheelChanged Methods contained in the API doc are not supported, or I cannot find a way to use them:

<tchart:RadCartesianChart.Behaviors>
    <tchart:ChartPanAndZoomBehavior ZoomMode="Horizontal" PanMode="Both"/>
</tchart:RadCartesianChart.Behaviors>

Error XLS0413 The property 'OnPointerWheelChanged' was not found in type 'ChartPanAndZoomBehavior'.

Error XLS0413 The property 'OnManipulationDelta' was not found in type 'ChartPanAndZoomBehavior'.

Thanks!

Martin Ivanov
Telerik team
commented on 05 Jul 2023, 08:18 PM

You can try the PointerWheelChanged event of the RadCartesianChart, instead of the ChartPanAndZoomBehavior (which is not a visual element).
Rick
Top achievements
Rank 1
Iron
commented on 06 Jul 2023, 12:19 PM

Hi Martin, thanks for your help.  I tried a few things but I am not sure what I should do exactly...  I tried to trigger my ChartAutoScale Method from the PointerWheelChanged event of the RadCartesianChart but it didn't do anything, I did not troubleshoot too far though.

 

I was hoping by the doc that I could handle this with the ChartPanAndZoomBehavior and its API methods, because I needed to implement another method on my parent Grid container to prevent a double scroll.  The RadCartesianChart is in a scrollView page and if you reach the end of the wheel zoom on the chart it scrolls your page very quickly.  This was super annoying and I had to prevent this behavior with this:

private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
        {
            e.Handled = true;
        }

I would also suggest that the Telerik Charts have something like this to prevent double scrolling the page.

 

Finally, even if I disabled my scrollView lock and tried to use the PointerWheelChanged of the RadCartesianChart I couldn't find a way to use it properly.  I will revisit this later as at least I have a working setup even if the chart wheel does not autozoom.

 

Thanks!

Martin Ivanov
Telerik team
commented on 28 Jul 2023, 11:20 AM

Can you tell me what do you mean that the PointerWheelChanged of the chart doesn't do anything? Do you mean the event wasn't invoked or just your ChartAutoScale wasn't updating the Minimum and Maximum properties of the chart?
Can you also send over few drawings of the expected result on zoom? Why do you need to recalculate the same Minimum and Maximum on zoom changed?
If you send over a sample project that shows your setup I can take a look and see if there is something proper to suggest.

No answers yet. Maybe you can help?

Tags
Chart
Asked by
Rick
Top achievements
Rank 1
Iron
Share this question
or