Code Monkey home page Code Monkey logo

Comments (2)

monitor1394 avatar monitor1394 commented on July 30, 2024 1

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

from xcharts.

HajiyevEl avatar HajiyevEl commented on July 30, 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?

from xcharts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.