Chart.js different color for negative / positive chart bars

0

Chart.js : Trying to put a color for positive values and another color for negative values on the chart.

Works well if there is at least one negative value:

See link

But something goes wrong if all values are positive (no negative value):

See link

What's wrong with this code?

Thanks for the help!

    
asked by anonymous 13.03.2018 / 22:05

1 answer

1

Actually, everything is fine, except that the graph is starting from the lowest value, it has an option to set the minimum value of the Y axis as 0 :

options: {
    legend: {
        display: false
    },
    //Escalas
    scales: {
          yAxes: [{ //Eixo Y
              display: true,
              ticks: {
                  beginAtZero: true   //Começa no zero
              }
          }]
    }
  }
    
14.03.2018 / 13:20