Chart.js Different color for Negative/Positive Chart bars

Asked

Viewed 365 times

0

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

Works well if there is at least one negative value:

Behold https://jsfiddle.net/c1w5Laee/78/

But there is something wrong if all values are positive (with no negative value):

Behold https://jsfiddle.net/c1w5Laee/80/

What’s wrong with this code?

Thanks for the help!

1 answer

1


In reality it’s all right, only that the chart is starting from the lowest value, has an option to set as 0 the minimum value of the y-axis:

options: {
    legend: {
        display: false
    },
    //Escalas
    scales: {
          yAxes: [{ //Eixo Y
              display: true,
              ticks: {
                  beginAtZero: true   //Começa no zero
              }
          }]
    }
  }
  • Thank you so much for your help. I really wasn’t wrong... but I looked at it over and over again and I hadn’t seen the Y-axis values (laughs!). Thank you! + 1

  • No problem ! , it’s normal for these things to go unnoticed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.