Home  >  Q&A  >  body text

javascript - How to modify the color of a specified bar in chart.js

I am using chart.js to make a bar chart, and I hope to modify the color of a certain data bar. Does anyone know how to do it?
My code is as follows

function drawChart(chartid,datalist,label){
var ctx = document.getElementById(chartid).getContext("2d");
var myChart = new Chart(ctx, {
    type: 'bar',
    data: {
        labels: label,
        datasets: [{
            label:'访问次数',
            data: datalist,
            backgroundColor: [
                'rgba(54, 162, 235, 0.5)'
            ],
        }]
    },
    options
});    
}

For example, if I want to modify the color of the first data, how should I write it in js? Thank you all.

曾经蜡笔没有小新曾经蜡笔没有小新2662 days ago750

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-07-05 11:07:48

    Declare the variable array externally, then write the color you set in it, and then pass the parameters into the setting item

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-07-05 11:07:48

    fillColor property

    reply
    0
  • Cancelreply