How to get max value by comparing dual y-axis in highchart?












0














I have a chart with dual y-axis, how can i get the min and max value from both?



load: function () {
var series = this.series,
max = series[0].dataMax,
min = series[0].dataMin;

series.forEach(function (serie) {
if (serie.dataMax > max) {
max = serie.dataMax;
}

if (serie.dataMin < min) {
min = serie.dataMin;
}
});

this.yAxis[0].update({
min: min,
max: max
});


I am trying the method above, but it will only get either one side got max value and update the axis value.



How can i make both y axis using the same max value?










share|improve this question



























    0














    I have a chart with dual y-axis, how can i get the min and max value from both?



    load: function () {
    var series = this.series,
    max = series[0].dataMax,
    min = series[0].dataMin;

    series.forEach(function (serie) {
    if (serie.dataMax > max) {
    max = serie.dataMax;
    }

    if (serie.dataMin < min) {
    min = serie.dataMin;
    }
    });

    this.yAxis[0].update({
    min: min,
    max: max
    });


    I am trying the method above, but it will only get either one side got max value and update the axis value.



    How can i make both y axis using the same max value?










    share|improve this question

























      0












      0








      0







      I have a chart with dual y-axis, how can i get the min and max value from both?



      load: function () {
      var series = this.series,
      max = series[0].dataMax,
      min = series[0].dataMin;

      series.forEach(function (serie) {
      if (serie.dataMax > max) {
      max = serie.dataMax;
      }

      if (serie.dataMin < min) {
      min = serie.dataMin;
      }
      });

      this.yAxis[0].update({
      min: min,
      max: max
      });


      I am trying the method above, but it will only get either one side got max value and update the axis value.



      How can i make both y axis using the same max value?










      share|improve this question













      I have a chart with dual y-axis, how can i get the min and max value from both?



      load: function () {
      var series = this.series,
      max = series[0].dataMax,
      min = series[0].dataMin;

      series.forEach(function (serie) {
      if (serie.dataMax > max) {
      max = serie.dataMax;
      }

      if (serie.dataMin < min) {
      min = serie.dataMin;
      }
      });

      this.yAxis[0].update({
      min: min,
      max: max
      });


      I am trying the method above, but it will only get either one side got max value and update the axis value.



      How can i make both y axis using the same max value?







      javascript jquery highcharts






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 3:26









      Crazy

      407114




      407114
























          2 Answers
          2






          active

          oldest

          votes


















          0














          To get min/max values from an axis, use getExtremes which returns an ExtremesObject. The ExtremesObject has the following properties:




          dataMax, dataMin, max, min, userMax, userMin




          If you want to set a new min/max value you should use setExtremes




          setExtremes( [newMin] [, newMax] [, redraw] [, animation] [, eventArguments])



          Set the minimum and maximum of the axes after render time. If the startOnTick and endOnTick options are true, the minimum and maximum values are rounded off to the nearest tick. To prevent this, these options can be set to false before calling setExtremes. Also, setExtremes will not allow a range lower than the minRange option, which by default is the range of five points.




          So the get the min and max from both axis, you could do something like this for the min value (if you want to tailor your view to the data and not manually set extremes):



          let firstAxisExtremes = chart.yAxis[0].getExtremes(),
          secondAxisExtremes = chart.yAxis[1].getExtremes(),
          min, max;
          if(firstAxisExtremes.dataMin <= secondAxisExtremes.dataMin) {
          min = firstAxisExtremes.dataMin
          } else {
          min = secondAxisExtremes.dataMin
          }


          API references: getExtremes, setExtremes, ExtremesObject






          share|improve this answer































            0














            Also, you can use your current code and set yAxis.linkedTo property:




            ...



            When an axis is linked to a master axis, it will take the same
            extremes as the master, but as assigned by min or max or by
            setExtremes. (...)




            yAxis: [{}, {
            linkedTo: 0,
            opposite: true
            }]


            Live demo: http://jsfiddle.net/BlackLabel/n5bzrqs8/



            API: https://api.highcharts.com/highcharts/yAxis.linkedTo






            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273345%2fhow-to-get-max-value-by-comparing-dual-y-axis-in-highchart%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              To get min/max values from an axis, use getExtremes which returns an ExtremesObject. The ExtremesObject has the following properties:




              dataMax, dataMin, max, min, userMax, userMin




              If you want to set a new min/max value you should use setExtremes




              setExtremes( [newMin] [, newMax] [, redraw] [, animation] [, eventArguments])



              Set the minimum and maximum of the axes after render time. If the startOnTick and endOnTick options are true, the minimum and maximum values are rounded off to the nearest tick. To prevent this, these options can be set to false before calling setExtremes. Also, setExtremes will not allow a range lower than the minRange option, which by default is the range of five points.




              So the get the min and max from both axis, you could do something like this for the min value (if you want to tailor your view to the data and not manually set extremes):



              let firstAxisExtremes = chart.yAxis[0].getExtremes(),
              secondAxisExtremes = chart.yAxis[1].getExtremes(),
              min, max;
              if(firstAxisExtremes.dataMin <= secondAxisExtremes.dataMin) {
              min = firstAxisExtremes.dataMin
              } else {
              min = secondAxisExtremes.dataMin
              }


              API references: getExtremes, setExtremes, ExtremesObject






              share|improve this answer




























                0














                To get min/max values from an axis, use getExtremes which returns an ExtremesObject. The ExtremesObject has the following properties:




                dataMax, dataMin, max, min, userMax, userMin




                If you want to set a new min/max value you should use setExtremes




                setExtremes( [newMin] [, newMax] [, redraw] [, animation] [, eventArguments])



                Set the minimum and maximum of the axes after render time. If the startOnTick and endOnTick options are true, the minimum and maximum values are rounded off to the nearest tick. To prevent this, these options can be set to false before calling setExtremes. Also, setExtremes will not allow a range lower than the minRange option, which by default is the range of five points.




                So the get the min and max from both axis, you could do something like this for the min value (if you want to tailor your view to the data and not manually set extremes):



                let firstAxisExtremes = chart.yAxis[0].getExtremes(),
                secondAxisExtremes = chart.yAxis[1].getExtremes(),
                min, max;
                if(firstAxisExtremes.dataMin <= secondAxisExtremes.dataMin) {
                min = firstAxisExtremes.dataMin
                } else {
                min = secondAxisExtremes.dataMin
                }


                API references: getExtremes, setExtremes, ExtremesObject






                share|improve this answer


























                  0












                  0








                  0






                  To get min/max values from an axis, use getExtremes which returns an ExtremesObject. The ExtremesObject has the following properties:




                  dataMax, dataMin, max, min, userMax, userMin




                  If you want to set a new min/max value you should use setExtremes




                  setExtremes( [newMin] [, newMax] [, redraw] [, animation] [, eventArguments])



                  Set the minimum and maximum of the axes after render time. If the startOnTick and endOnTick options are true, the minimum and maximum values are rounded off to the nearest tick. To prevent this, these options can be set to false before calling setExtremes. Also, setExtremes will not allow a range lower than the minRange option, which by default is the range of five points.




                  So the get the min and max from both axis, you could do something like this for the min value (if you want to tailor your view to the data and not manually set extremes):



                  let firstAxisExtremes = chart.yAxis[0].getExtremes(),
                  secondAxisExtremes = chart.yAxis[1].getExtremes(),
                  min, max;
                  if(firstAxisExtremes.dataMin <= secondAxisExtremes.dataMin) {
                  min = firstAxisExtremes.dataMin
                  } else {
                  min = secondAxisExtremes.dataMin
                  }


                  API references: getExtremes, setExtremes, ExtremesObject






                  share|improve this answer














                  To get min/max values from an axis, use getExtremes which returns an ExtremesObject. The ExtremesObject has the following properties:




                  dataMax, dataMin, max, min, userMax, userMin




                  If you want to set a new min/max value you should use setExtremes




                  setExtremes( [newMin] [, newMax] [, redraw] [, animation] [, eventArguments])



                  Set the minimum and maximum of the axes after render time. If the startOnTick and endOnTick options are true, the minimum and maximum values are rounded off to the nearest tick. To prevent this, these options can be set to false before calling setExtremes. Also, setExtremes will not allow a range lower than the minRange option, which by default is the range of five points.




                  So the get the min and max from both axis, you could do something like this for the min value (if you want to tailor your view to the data and not manually set extremes):



                  let firstAxisExtremes = chart.yAxis[0].getExtremes(),
                  secondAxisExtremes = chart.yAxis[1].getExtremes(),
                  min, max;
                  if(firstAxisExtremes.dataMin <= secondAxisExtremes.dataMin) {
                  min = firstAxisExtremes.dataMin
                  } else {
                  min = secondAxisExtremes.dataMin
                  }


                  API references: getExtremes, setExtremes, ExtremesObject







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 13 '18 at 8:40

























                  answered Nov 13 '18 at 8:28









                  ewolden

                  4,12131125




                  4,12131125

























                      0














                      Also, you can use your current code and set yAxis.linkedTo property:




                      ...



                      When an axis is linked to a master axis, it will take the same
                      extremes as the master, but as assigned by min or max or by
                      setExtremes. (...)




                      yAxis: [{}, {
                      linkedTo: 0,
                      opposite: true
                      }]


                      Live demo: http://jsfiddle.net/BlackLabel/n5bzrqs8/



                      API: https://api.highcharts.com/highcharts/yAxis.linkedTo






                      share|improve this answer


























                        0














                        Also, you can use your current code and set yAxis.linkedTo property:




                        ...



                        When an axis is linked to a master axis, it will take the same
                        extremes as the master, but as assigned by min or max or by
                        setExtremes. (...)




                        yAxis: [{}, {
                        linkedTo: 0,
                        opposite: true
                        }]


                        Live demo: http://jsfiddle.net/BlackLabel/n5bzrqs8/



                        API: https://api.highcharts.com/highcharts/yAxis.linkedTo






                        share|improve this answer
























                          0












                          0








                          0






                          Also, you can use your current code and set yAxis.linkedTo property:




                          ...



                          When an axis is linked to a master axis, it will take the same
                          extremes as the master, but as assigned by min or max or by
                          setExtremes. (...)




                          yAxis: [{}, {
                          linkedTo: 0,
                          opposite: true
                          }]


                          Live demo: http://jsfiddle.net/BlackLabel/n5bzrqs8/



                          API: https://api.highcharts.com/highcharts/yAxis.linkedTo






                          share|improve this answer












                          Also, you can use your current code and set yAxis.linkedTo property:




                          ...



                          When an axis is linked to a master axis, it will take the same
                          extremes as the master, but as assigned by min or max or by
                          setExtremes. (...)




                          yAxis: [{}, {
                          linkedTo: 0,
                          opposite: true
                          }]


                          Live demo: http://jsfiddle.net/BlackLabel/n5bzrqs8/



                          API: https://api.highcharts.com/highcharts/yAxis.linkedTo







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 19 '18 at 13:24









                          ppotaczek

                          3,986129




                          3,986129






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273345%2fhow-to-get-max-value-by-comparing-dual-y-axis-in-highchart%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Xamarin.iOS Cant Deploy on Iphone

                              Glorious Revolution

                              Dulmage-Mendelsohn matrix decomposition in Python