0

I am facing issue while plotting line chart using chart-js lib.

Here is the codepen : https://codepen.io/bhupendra1011/pen/gObEpJQ, where I set the min Y value as below:

    yAxes: [{
          ticks: {
            min: minY,          
            maxTicksLimit:5
                    
                },
            gridLines: {
                display:false
            }   
        }]

However if values which are less than minY, then plotted values are not possible , if I remove minY option , then all line graphs are visible, but in my scenario , I want graph to have some initial value.

I also tried using below code instead of setting minY :

afterBuildTicks: function(scale, ticks) {
    return [minY].concat(ticks.filter(tick => tick >= minY));
}

although all plotted lines are visible but graph's initial position changes on selecting different series options.Here is the codepen for same: https://codepen.io/bhupendra1011/pen/bGNJNBw

I want chart to start from some initial value , values less than initial values should also be plotted and on updating chart , graph's initial position should not change .

Thanks

Community
  • 1
  • 1
Bhupendra
  • 1,196
  • 16
  • 39

1 Answers1

0

set your minY to the smallest element in your data array:

Array.min = function( array ){
    return Math.min.apply( Math, array );
};
DadyByte
  • 894
  • 6
  • 18
  • 30
  • hi @DadyByte ,I want initial value to be fixed as first item in array. as in https://codepen.io/bhupendra1011/pen/gObEpJQ . if there are any values less than initial value , it should also be be plotted below it – Bhupendra Feb 04 '20 at 08:47
  • @Bhupendra, I saw your code, in your code you are taking 0th element of the array as minY due to which values below minY are not showing. minY means that Y axis will start from that number if you want to display smaller numbers then change minY accordingly. Hope this helps. – DadyByte Feb 04 '20 at 09:54
  • I have created one more example - https://codepen.io/bhupendra1011/pen/bGNJNBw. Here I am filtering the ticks using afterBuildTicks . In this scenario , all values are visible , but graph's initial position changes when changing the series options: high/low/medium. Is it possible to have graph's position fixed , graph's get updated without changing its position just like it's in https://codepen.io/bhupendra1011/pen/gObEpJQ – Bhupendra Feb 04 '20 at 10:08