Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to subscribe to DataZoom value changes? #314

Closed
HajiyevEl opened this issue Apr 11, 2024 · 2 comments
Closed

Question: How to subscribe to DataZoom value changes? #314

HajiyevEl opened this issue Apr 11, 2024 · 2 comments

Comments

@HajiyevEl
Copy link

HajiyevEl commented Apr 11, 2024

Hi again!
When using DataZoom, how should i get currently displayed candlesticks data?

I want to be able to set yAxis min-max values (Min-Max Type: Custom) depending on currently displayed min-max values of candlesticks on screen (from series data), and subscribe to OnDataZoomRangeChanged for further updates.
Tried using Min-Max Type: Auto, but it seems it gets min-max values from all serie data, not currently displayed (on-screen)

@HajiyevEl
Copy link
Author

HajiyevEl commented Apr 11, 2024

Alright, i found how to get data from DataZoom:

        // Set custom Y axis min-max values as +/- 1% of max/min values on screen candles
        private void UpdateYAxisMinMaxValues()
        {
            var serie = chart.GetSerie(0);
            chart.GetDataZoomOfSerie(serie, out DataZoom xDataZoom, out DataZoom yDataZoom);

            // Returns timestamp as max value
            //SerieHelper.GetMinMaxData(serie, out serieMinValue, out serieMaxValue, xDataZoom);

            var serieDataList = serie.GetDataList(xDataZoom);

            double serieMinValue = double.MaxValue;
            double serieMaxValue = double.MinValue;

            for (int i = 0; i < serieDataList.Count; i++)
            {
                var serieData = serieDataList[i];
                var serieDataValues = serieData.data;

                // serieDataValues[0] - Timestamp
                // serieDataValues[1] - OpenPrice
                // serieDataValues[2] - ClosePrice
                // serieDataValues[3] - LowPrice
                // serieDataValues[4] - HighPrice

                var min = serieDataValues[3];
                var max = serieDataValues[4];

                if (min < serieMinValue) serieMinValue = min;
                if (max > serieMaxValue) serieMaxValue = max;

            }

            var yAxis = chart.GetChartComponent<YAxis>(serie.yAxisIndex);
            yAxis.type = Axis.AxisType.Value;
            yAxis.minMaxType = Axis.AxisMinMaxType.Custom;
            yAxis.ceilRate = (double)ceilRate;

            serieMinValue = serieMinValue - (yAxisMinMaxOffsetInPercent / 100 * serieMinValue);
            serieMaxValue = serieMaxValue + (yAxisMinMaxOffsetInPercent / 100 * serieMaxValue);

            yAxis.min = ChartHelper.GetMinDivisibleValue(serieMinValue, ceilRate);
            yAxis.max = ChartHelper.GetMaxDivisibleValue(serieMaxValue, ceilRate);

            // Does not set min-max values, because initial values of min max is 0, AdjustMinMaxValue skips them on this line 'if (axis.min != 0 || axis.max != 0)'
            //AxisHelper.AdjustMinMaxValue(yAxis, ref serieMinValue, ref serieMaxValue, true, yAxis.ceilRate);
        }

Now how i should subscribe to OnDataZoomRangeChanged for updates when zoom changes?
For now i just check difference between previous and current values of DataZoom.start and DataZoom.end in update method, is there any other way? Delegate to subscribe for zoom updates maybe?

@HajiyevEl HajiyevEl changed the title Question: How to get only currently displayed candlesticks? Question: ~~How to get only currently displayed candlesticks?~~ Apr 11, 2024
@HajiyevEl HajiyevEl changed the title Question: ~~How to get only currently displayed candlesticks?~~ Question: How to get only currently displayed candlesticks? Apr 11, 2024
@HajiyevEl HajiyevEl changed the title Question: How to get only currently displayed candlesticks? Question: How to subscribe to DataZoom value changes? Apr 11, 2024
@HajiyevEl HajiyevEl changed the title Question: How to subscribe to DataZoom value changes? Question: ~How to subscribe to DataZoom value changes?~ Apr 11, 2024
@HajiyevEl HajiyevEl changed the title Question: ~How to subscribe to DataZoom value changes?~ Question: How to subscribe to DataZoom value changes? Apr 11, 2024
@monitor1394
Copy link
Collaborator

The startEndFunction of DataZoom is a callback for when the start and end values of a DataZoom change. You can try using this function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants