Pre loader

ChartSurface.XAxis is created (always null)

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

1
0

Hi All,

Newby question here – we’re just getting our heads around SciChart at the moment so please bear with me.

Having acquired our data the chartSurface is populated using a RenderableSeries with an XyDataSeries consisting of DateTime/double datapairs. Everything is fine and we can do lots of panning and zooming etc.

The problem comes when I attempt to put a VerticalLineAnnotation on the graph on a response from a mouseclick (as per the example code). When I attempt to get coordinate calculator with
var coordinateCalculator = this.sciChartSurface.XAxis.GetCurrentCoordinateCalculator();
It throws an exception as XAxis is null!

Can someone explain what we are missing or point us in the right direction in general.

Thanks in advance
/Stu

  • You must to post comments
0
0

Hi Stuart,

OK I have enough information to post an ‘answer’ now – so yes as you’ve mentioned in the comments, if you have defined Axis via the SciChartSurface.XAxes (Axis Collection) then XAxis may be null, just get the axis from wherever you set it from.

In brief

Single Axis charts

<s:SciChartSurface.XAxis>
    <s:DateTimeAxis AxisTitle="Date" Id="DefaultAxisId" AxisAlignment="Bottom">
    </s:DateTimeAxis>
</s:SciChartSurface.XAxis>

Multiple Axis Charts

<s:SciChartSurface.XAxes>
    <s:DateTimeAxis AxisTitle="Date" Id="DefaultAxisId" AxisAlignment="Bottom">
    </s:DateTimeAxis>
    <s:DateTimeAxis AxisTitle="Date 2" Id="SecondAxisId" AxisAlignment="Bottom">
    </s:DateTimeAxis>
</s:SciChartSurface.XAxes>

Regarding Coordinate Calculator null

From our API docs Convert Pixel to Data Coordinates

NOTE: Because the CoordinateCalculator is created on the beginning of
rendering pass, the GetCurrentCoordinateCalculator method will return
NULL if called before the chart is being rendered.

However, in v3.3.2 (currently only available on our Nightly Build NuGet Feed) we are working on improving this so that GetCurrentCoordinateCalculator() always returns a valid coordinate calculator. Please try v3.3.2 and let me know if this second problem is resolved.

Best regards,
Andrew

  • Stuart McCullough
    I clearly need to learn more about the basics of SciChart - which I'll be doing over the next few months. The objective here was to recreate the "Series Vertical Slices" Demo but on a right button click which I have now done - including the XAxis date value for which I used this:- DateTime XMousePositionDate = (DateTime) this.sciChartSurface.XAxis.GetDataValue(mousePoint); var slice = new VerticalLineAnnotation() { X1 = XMousePositionDate, Style = (Style)Resources["trackBarStyle"] }; this.sliceModifier.VerticalLines.Add(slice); Is this bad and if so, why? Oh! and I'll see if I can get a chance to try 3.3.2 at some point today :-)
  • Andrew Burnett-Thompson
    I dont think this is bad - why is it giving you any problems? Sometimes you guys show us deficiencies in the API that we have not thought about, or a combination we have not tried, so feel free to ask questions & post code samples, we learn as much as you do!
  • Stuart McCullough
    No - it seems to work perfectly. I was just concerned that all examples I've seen use a coordinate converter - and my solution obviously doesn't :-)
  • Andrew Burnett-Thompson
    Axis.GetDataValue() does the same as Axis.GetCurrentCoordinateCalculator().GetDataValue(). Just the getting of a coord-calculator means this setup is done once and is a little bit faster in tight loops e.g. rendering. Also VerticalLineAnnotation.X1 works just fine if you set a date (for DateTimeAxis) or double (for NumericAxis) or int (integer index to data for CategoryDateTimeAxis). Glad you're all set and up and running! Best regards, Andrew
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies