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











up vote
0
down vote

favorite












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


























    up vote
    0
    down vote

    favorite












    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
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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 at 3:26









      Crazy

      395112




      395112
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          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






























            up vote
            0
            down vote













            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',
              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








              up vote
              0
              down vote













              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



























                up vote
                0
                down vote













                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

























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  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 at 8:40

























                  answered Nov 13 at 8:28









                  ewolden

                  3,97431125




                  3,97431125
























                      up vote
                      0
                      down vote













                      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

























                        up vote
                        0
                        down vote













                        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























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          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 at 13:24









                          ppotaczek

                          3,278129




                          3,278129






























                               

                              draft saved


                              draft discarded



















































                               


                              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

                              How to send String Array data to Server using php in android

                              Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                              Is anime1.com a legal site for watching anime?