Is it possible to deactivate the auto scaling on an axis on the chart?

Charts for WPF Forum

Posted 2 years ago by Nerd22 - Germany
Version: 22.1.4
Avatar

Hello there,

I've a chart with a Y axis in a given fixed range between {0,10}. In that case my chart also shows some negative values and values above 10, which shouldn't.

When I also add a point inside my defined area, everything works fine, as long as, this new point is in the range of {0,10}, however, by adding a point outside of the range, the Y axis gets a new range automatically to make sure to display the modified line series.

So, I would like:

  • set a fixed Y axis range
  • deactivate the automatic axis update

Is there a way to realize that?

Thanks in advise.

Comments (3)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Are you are specifying the XYChartAxis.Minimum and Maximum properties to 0 and 10 respectively?  If so I would not expect the displayed axis range to be adjusted.  It seemed to work in a test I did here.

If you are setting those properties and still see the issue, please make a new simple sample project that shows the issue and send that to our support address.  Reference this thread in your email and be sure to exclude the bin/obj folders from the .zip you send so it doesn't get spam blocked.  Then we will debug with that and see what's going on.  Thanks!


Actipro Software Support

Posted 2 years ago by Nerd22 - Germany
Avatar

I found the solution, which is a bit weired.

To set up the minimum and maximum values for a chart, this can be done in the xaml file or, in my case, in C#, because the chart needed to be initialized on runtime.

So, I used the Ranges class, which comes with a Minimum and Maximum property. My chart was build like:

<charts:XYChart x:Name="chart">
	<charts:LineSeries XPath="X" YPath="Y" LineKind="Step"/>
</charts:XYChart>
chart.YAxes.First().Ranges.Add(AxisSetup());
private XYRange AxisSetup() {
	return new XYRange() {
		Minimum = Convert.ToDouble(0),
		Maximum = Convert.ToDouble(10),
		Background = Brushes.Transparent
	};
}

This allows to set up a minimum and maximum range, however, when a point outside of {0,10} cames in, the axis has been updated automatically, which caused a lot of bugs on runtime, followed by application freezing in combination with a loop and 100,000+ elements.

I also figured out, that this shall be used instead:

chart.YAxes.Add(AxisSetup());
private XYDoubleAxis AxisSetup() {
	XYDoubleAxis xyDA = new XYDoubleAxis() {
		Minimum = Convert.ToDouble(0),
		Maximum = Convert.ToDouble(10),
		Background = Brushes.Transparent
	};

	return xyDA;
}

With XYDoubleAxis my chart has a real fixed area and when a point outside of {0,10} comes in, the axis is not going to update automatically.

So, it seems, that there're two kind of classes, which could be used, where the Ranges class is maybe never planned to used for this.

Could you add a commentary in your documentation which could avoid this in the future? :o)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I'm sorry there was confusion with ranges vs. the axis min/max.  Ranges (per this documentation topic and the related sample) are simply a way to highlight an area on the chart within a min and max set of values.  For instance you may want a red background over an area where "bad" values are for a series.

Whereas the axis itself has min/max properties itself that govern what set of values will show up in the displayed chart.


Actipro Software Support

The latest build of this product (v24.1.3) was released 24 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.