Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart.js Text color

So im using chart.js http://www.chartjs.org/docs/ and i cant change the color of the text in the bottom

ex: "January","February","March","April","May","June","July" and the numbers in the left side

i tried all these options: scaleFontColor: "#FFFFFF" pointLabelFontColor : "#FFFFFF"

my full code:

<script>
    var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
    var lineChartData = {
        labels : ["January","February","March","April","May","June","July"],
        datasets : [
            {
                label: "My Second dataset",
                fillColor : "rgba(255, 89, 114, 0.6)",
                strokeColor : "rgba(51, 51, 51, 1)",
                pointColor : "rgba(255, 89, 114, 1)",
                pointStrokeColor : "#fff",
                pointHighlightFill : "#fff",
                pointHighlightStroke : "rgba(151,187,205,1)",
                maintainAspectRatio: false,
                scaleFontColor: "#FFFFFF",
                pointLabelFontColor : "#FFFFFF",
                pointLabelFontSize : 30,
                data : [1,2,10,7,3,1]
            }
        ]

    }

window.onload = function(){
    var ctx = document.getElementById("canvas").getContext("2d");

    window.myLine = new Chart(ctx).Line(lineChartData, {
        responsive: true
    });
}


</script>
like image 595
downrep_nation Avatar asked Feb 16 '15 17:02

downrep_nation


People also ask

What is chart legend Javascript?

The chart legend displays data about the datasets that are appearing on the chart.


2 Answers

For chart.js 3.x migration, text-labels on x and y axis are set this way:

Set options to the following:

scales: {
  x: {
    ticks: {
      color: "red"
    }
  },
  y: {
    ticks: {
      color: "green"
    }
  }
}

similar solution is found if you want to change color of grid lines, inside of x / y value write

grid: {
  color: "white"
}
like image 69
ellipsenotcircle Avatar answered Nov 15 '22 19:11

ellipsenotcircle


In Chart.js v3 it can be achieved with:

Chart.defaults.color = "#ff0000";
like image 36
André Claesson Avatar answered Nov 15 '22 19:11

André Claesson