2
Good afternoon!
I’m creating a circular graph, the data I search from the database.
However I do not know how to change the colors of the circular graphic sectors, to make it clearer I will show here what I intend.
The code is as follows::
include "../classif/BD/ligabd.php";
...
`
google.charts.load("current", {packages:["corechart"]});;
google.charts.setOnLoadCallback(drawChart);
function drawChart()
{
var data = google.visualization.arrayToDataTable([
['classificacao','Number'],
<?php
while ($row=mysqli_fetch_array($result))
{
echo "['".$row["classificacao"]."', ".$row["number"]."],";
}
?>
]);
var options = {
title:'Classificações do refeitório',
is3D:true
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data,options);
}
Chart of the cafeteria classifications
`
The output is as follows::
What I intended was instead of "yellow" being the color blue, the color was yellow, where it says green, instead of being red that was green, so on...
But how do I say that I want red to be red, yellow to be yellow, etc... ?
– Ana
It’s the same order as in
data
– Leite
Heheh, thank you!
– Ana
I put an example of how you can control colors if you can’t control the order of what’s in
data
– Leite
Perfect! Very good!
– Ana
By the way, to change the name of the "subtitles" would need to change the
query
and change invar data...
?– Ana
Yes. Since I don’t see the code where you add those pins, I assume that’s the value you have in
$row["classificacao"]
, the first array item you pass toarrayToDataTable
is the label, the second is the value of that label– Leite