Pre loader

How to get the Y value where line intersects with the Y axis

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

I’m trying to add an AxisMarkerAnnotations for some line series on my chart.

I was following these questions answered here:
https://www.scichart.com/questions/js/adding-axis-markers-to-fastlinerenderableseries
https://www.scichart.com/questions/js/price-indicators-on-yaxis

I managed to render the axis marker for my series. Now I’m trying to the set the Y value of the marker annotation as the value where the line intersects the Y Axis.
I want the marker value to be the last value of the series, only if the xAxis.visibleRange.max > series.XdataRange.max.

The two attached images show the desired feature.
One shows the marker annotation with the Y1 being the one where the line intersects the YAxis.
The other shows the marker annotation with the Y1 being the last value of the line, because it is visible.

I read some answers here on the forum about using the HitTest API to do this, but I couldn’t make it work on my JS app

Version
3.2.457
Images
  • You must to post comments
0
0

Hi Lucas,

@ the Community: see original question Price Indicators on Y-Axis with full codepen and background on the
requirement

The workflow to get the latest Y-value in the viewport as line intersects the viewport edge is as follows, (in pseudocode):

// 1. Get xMax = xAxis.visibleRange.max 
// 2. FindIndex: xMaxIndex = findIndexOf(xMax, dataSeries.getNativeXValues())
// 3. Get yValue = dataSeries.getNativeYValues().get(xMaxIndex);
// 4. Determine yValueOutsideViewport = xMaxIndex < dataSeries.count()

In SciChart.js code the only thing which is tricky is FindIndex. We wrote a helper function to FindIndex fast to do this (which we plan to include on dataSeries soon).

See question Add custom annotation with fixed x1 value and dynamically changed y1 value with the series data in a real time updated chart. This describes how to place an annotation Y1 at specific y datapoint which corresponds to an x-value.

Adapting the code for your situation, you’d do this:

const findIndex = (dataSeries, xValue) => {
    return wasmContext.NumberUtil.FindIndex(dataSeries.getNativeXValues(), 
         xValue, 
         wasmContext.SCRTFindIndexSearchMode.Nearest, 
         isDataSorted);
};

const xIndex = findIndex(xyDataSeries, xAxis.visibleRange.max); 
const yValue = xyDataSeries.getNativeYValues().get(xIndex);
annotation.y1 = yValue;

Putting this all together, the SeriesValueModifier code has been updated. I’ve done this in the original Codepen linked to on the Price Indicators on Y-Axis forum question.

BTW: If you have a feature request for us to add this functionality into core SciChart, let us know your exact and complete requirements.

Best regards
Andrew

  • You must to post comments
0
0

Thank you very much, Andrew, for the explanation and examples!
So much helpful, as always

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.