google charts graph

0

I'm getting a json where I keep the following fields, but the graphic generates me the same colors and should not

$table = array()
$rows = array();
$table['cols'] = array(      
    array('label' => 'Nome', 'type' => 'string'),
    array('label' => 'valor', 'type' => 'number'),
   );
$stmt->execute();
$result = $stmt->fetchAll();
foreach ($result as $row) {
    $temp = array();
    $temp[] = array('v' => (string) $row['Nome']);
    $temp[] = array('v' => (float) $row['valor']);
    $rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;

// Carregue o API Visualization e o pacote piechart.
google.load('visualization', '1', {'packages': ['corechart']});

// Defina um callback a ser executado quando o API de visualização do Google é carregado.
google.setOnLoadCallback(drawChart);

function drawChart() {
    var jsonData = $.ajax({
        url: "getdados.php",
        dataType: "json",
        async: false
    }).responseText;

    // Coloque aqui as configurações do gráfico, acesse a documentação para mais opções
    var options = {'title': 'valores',
        'width': 1000,
        'height': 680,

        visibleInLegend: true,
        is3D: true,
    };

    // Create our data table out of JSON data loaded from server.

    var wrapper = new google.visualization.ChartWrapper({
        chartType: 'ColumnChart',
        dataTable: jsonData,
        options: options,
        containerId: 'chart_div'
    });
    wrapper.draw();

    var formatter = new google.visualization.NumberFormat(
            {prefix: '€ ', negativeColor: 'red', negativeParens: false});

    formatter.format(wrapper, 1);
    //Desenha o gráfico

}
    
asked by anonymous 30.10.2015 / 11:54

1 answer

0

Oops, beauty? Dude, I saw you just need to include an array of colors in your "options" object:

var options = {'title': 'valores',
         width: 1000,
         height: 680,
         colors: ['#e0440e', '#e6693e', '#ec8f6e', '#f3b49f', '#f6c7b6'],
         visibleInLegend: true,
         is3D: true,
    };
    
30.10.2015 / 13:12