score:1

the link https://www.chartjs.org/docs/latest/developers/updates.html has pretty up to date information. the keey is to recognise what the chart object is. :) i struggled for half a day reading various pages until i found the right way

  1. use the basechartdirective to access the chart directly by doing this -> this.chart
  2. to update scales do this:
 var barchartoptions =  {
      legend: { display: true },
      scales: { yaxes: [{ id: 'yaxis', type: 'linear', position: 'left', ticks: { min: 0, max: maxscale } }]}  };  
 this.chart.chart.options = barchartoptions;
  1. then update the chart:

this.chart.chart.update();

you can pretty much update everything. just need to realise what the chart object means in this page: https://www.chartjs.org/docs/latest/developers/updates.html :)

score:5

this is my solution for line chart.

you can use 'beforefit' callback function that you can find here in the docs http://www.chartjs.org/docs/latest/axes/

  1. in scale.chart.config.data.datasets you have the chart dataset
  2. you must set the scale.options.ticks.max

example:

scales: {
        yaxes: [{
          beforefit: function (scale) {

            // see what you can set in scale parameter
            console.log(scale)

            // find max value in your dataset
            let maxvalue = 0
            if (scale.chart.config && scale.chart.config.data && scale.chart.config.data.datasets) {
              scale.chart.config.data.datasets.foreach(dataset => {
                if (dataset && dataset.data) {
                  dataset.data.foreach(value => {
                    if (value > maxvalue) {
                      maxvalue = value
                    }
                  })
                }
              })
            }

            // after, set max option !!!
            scale.options.ticks.max = maxvalue
          }
        }

i hope i've been helpful.

score:13

found the solution myself.

to change any options of the chart:

mybar.config.options

in my case

mybar.config.options.scales.yaxes[0].ticks.max = newvalue

after this you have to call

window.mybar.update();

Related Query

More Query from same tag