SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components
I currently have a DateTime X axis on my SciChart and a Numeric Y Axis.
When I call YAxis.DataSet.YRange, I get correct values based on the data tied to the axis.
If I do the same with the X axis, XAxis.DataSet.XRange, I get the following value for both the Min and Max: ~6.34E+17.
Is this a bug, or is there a better way to get the correct values for the extents of the axes?
The intention is to implement ZoomToFit type function only related to that axis. I did not see this in the API. Is there an easier way to do it for all axis types?
Thanks for your enquiry! Yes the DataSet.XRange / YRange properties return the extents of the data for the entire DataSet in X or Y (it does not discriminate between series on different axes). Also XRange, YRange are of type DoubleRange regardless of the type of the TX,TY in the DataSet.
The DataSet.XRange is returning a DoubleRange with tick values corresponding to your DateTimes. E.g. +6.34E+17 corresponds to approx January 2010, therefore new DateTime((long)DataSet.XRange.Min) is equal to the min date.
There are functions throughout the API which can assist in getting axis ranges to perform zoom to fit. For instance:
/// <summary> /// Gets the Maximum Range of the axis, which is equal to the DataRange including any GrowBy factor applied /// </summary> /// <returns></returns> public abstract IRange GetMaximumRange();
/// <summary> /// Gets the YRange of the data (min, max of the series) in the input visible range point range, where the input range is the <see cref="IAxis.VisibleRange"/> /// </summary> /// <param name="xRange">The X-Axis Range currently in view</param> /// <returns>The YRange of the data in this window</returns> /// <exception cref="System.ArgumentNullException">xRange</exception> /// <exception cref="System.InvalidOperationException">Invalid Range Type. Please ensure you are using DateTimeAxis where the X-Data is DateTime, and NumericAxis where the X-Data is Double, Float, Int, Long</exception> public IRange GetWindowedYRange(IRange xRange);
/// <summary> /// Gets the YRange of the data (min, max of the series) in the input IndexRange, where indices are point-indices on the DataSeries columns /// </summary> /// <param name="xIndexRange">The X-Axis Indices currently in view</param> /// <returns> /// The YRange of the data in this window /// </returns> public IRange GetWindowedYRange(IndexRange xIndexRange);
Also if you’re interested in writing custom zoom to fit, I would suggest looking at the source code (which you have access to), SciChartSurface.ZoomExtents(), ZoomExtentsY() methods as these have custom logic in them to determine zoom to fit on a per-axis basis.
Hope this helps!
Please login first to submit.