我正在使用谷歌饼图我的json
值为:
[
["Exhibitor Fee", 21],
["Attendee Registration", 400],
["Hotel Cost Per Night", 21212],
["Sponsorship", 435],
["Shippng", 456]
]
我的代码是:
var jsonValues = '<?php echo $staticEvent; ?>'
var pieValues = $.parseJSON(jsonValues);
console.log(pieValues);
google.charts.load('current', {'packages': ['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable(pieValues);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
答案 0 :(得分:0)
通过事物here的外观,饼图期望第一个数组成为图表的标题,我想这应该是字符串,而你的第一个数组是string, int
尝试将您的json更改为:
[
["Activity", "Cost"],
["Exhibitor Fee", 21],
["Attendee Registration", 400],
["Hotel Cost Per Night", 21212],
["Sponsorship", 435],
["Shippng", 456]
]
答案 1 :(得分:0)
你好吗,
试一试:
在你的php var $ staticEvent中;你改成:<?php
$staticEvent = json_encode($staticEvent, JSON_UNESCAPED_UNICODE);
?>
你的JS:
var jsonValues = '<?php echo $staticEvent; ?>';
var pieValues = $.parseJSON(jsonValues);
console.log(pieValues);
google.charts.load('current', {'packages': ['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable(pieValues);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}