简体   繁体   English

谷歌饼图php mysql

[英]Google Pie Chart php mysql

** **

I used Google Pie chart using PHP MySQL. 我使用PHP MySQL使用Google Pie图表。 If I put my mouse on the chart it only shows 2 column data from the row. 如果将鼠标放在图表上,它将仅显示该行中的2列数据。 But there are three columns in that table & I want to show all the columns from the row. 但是该表中有三列,我想显示该行中的所有列。 I have written this code to show 3rd column but it doesn't work. 我已经编写了这段代码来显示第3列,但是它不起作用。

** **

var data = google.visualization.arrayToDataTable([
            ['Problems', 'Sufferer', 'Solutions'],

            <?php

            while($row = $res->fetch_assoc()){
                echo "['".$row['Problems']."',".$row['sum(Sufferer)'].", '".$row['Solutions']."'],";
            }

            ?>

        ]);

How can I solve this problem? 我怎么解决这个问题? picture of my Pie Chart output example 我的饼图输出示例的图片

Google Pie chart only supports 2 columns refer Google Pie Chart Google饼图仅支持2列,请参阅Google饼图

The first one is the slice label and the second one is the slice value. 第一个是切片标签,第二个是切片值。

If you wish to add more information to your chart, you can make use of the tooltip which is displayed on hover. 如果要向图表添加更多信息,可以使用悬停时显示的工具提示。

For more information on columns and roles, refer Column Roles 有关列和角色的更多信息,请参阅列角色

By default only the slice label and slice value with percentage will be shown in the tooltip of the chart. 默认情况下,图表的工具提示中只会显示切片标签和带有百分比的切片值。

This can be customized by passing data in the below format 可以通过以下格式传递数据进行自定义

Data format 资料格式

    var data = google.visualization.arrayToDataTable([
      ['Pizza', 'Popularity', {type:'string', role:'tooltip'}],
      ['Pepperoni', 33, "Most popular"],
    ]);

If you wish to customize the rendering of the tooltip, it can be achieved by passing HTML data as the content of the tooltip. 如果您希望自定义工具提示的呈现,可以通过将HTML数据作为工具提示的内容进行传递来实现。

For more information on tooltips and customizing HTML content, refer Tooltips 有关工具提示和自定义HTML内容的更多信息,请参阅工具提示

Example

 google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Pizza', 'Popularity', {type:'string', role:'tooltip'}], ['Pepperoni', 33, "Most popular"], ['Hawaiian', 26, "Popular"], ['Mushroom', 22, "Somewhat popular"], ['Sausage', 10, "Less popular"] ]); var options = { title: 'Pizza Popularity' }; var chart = new google.visualization.PieChart(document.getElementById('piechart')); chart.draw(data, options); } 
 <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <div id="piechart" style="width: 900px; height: 500px;"></div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM