google Graphical software

Asked

Viewed 435 times

0

I’m getting a json where I store the following fields, but the graph gives me equal 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

}

1 answer

0

Whoa, whoa, what’s up? Dude, from what I’ve seen you just need to include an array of colors in your object "options":

var options = {'title': 'valores',
         width: 1000,
         height: 680,
         colors: ['#e0440e', '#e6693e', '#ec8f6e', '#f3b49f', '#f6c7b6'],
         visibleInLegend: true,
         is3D: true,
    };
  • is red because the way I am grouping the data. I have to adapt my code to look like this . http://www.webcodefree.com.br/blog/? s=Google+Chart+API

  • Pass the JSON that getdados.php returns please.

  • this {"date ":[{"ref":"ACD PESS","value":"2.9300"},{"ref":"ACD TRAB","value":"222.9900"},{"ref":"AUTO","value":"1460.1000"},{"ref":"MISCELLANEOUS","value":"125.6800"},{"ref":"MR HABITA u00c7AO","value":"68.2300"},{"ref":"MR INDUST/COMER","value":"210.3500"},{"ref":"MULTI","value":"16.4300"},{"ref":"PROT JURIDICA","value":"5.4900"}]}

Browser other questions tagged

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