轴显示无序值,列总结我不知道为什么。
数据以百分比表示,但如果成绩优于目标,则数据可能超过100%。
这是我的代码(在它之前有一个Foreach):
$vttCloud = number_format((($CountryCloudAchieved)*pow(($CountryTarget*0.25 ), -1))*100, 2, ",", ".");
$vtt = number_format((($CountryAchieved)*pow(($CountryTarget), -1))*100, 2, ",", ".");
if ($vttCloud == 0 && $vtt == 0) {} else {
?>
['<?php echo $Country; ?>', '<?php echo $vtt; ?>', '<?php echo $vttCloud; ?>'],
<?php } } ?>
答案 0 :(得分:1)
为第1列和第1列使用数字而不是字符串2(丢失单引号)......
['<?php echo $Country; ?>', <?php echo $vtt; ?>, <?php echo $vttCloud; ?>],
奇怪的是它会让你用字符串作为值绘制图表,
请参阅以下两个示例,一个带数字,另一个带字符串......
google.charts.load('current', {
callback: function () {
drawChartGood();
drawChartBad();
},
packages:['bar']
});
function drawChartGood() {
var dataTable = google.visualization.arrayToDataTable([
['Country', 'vtt', 'vttCloud'],
['Czech Republic', 50, 60],
['Italy', 75, 80],
['Croatia', 28, 40]
]);
var options = {
bars: 'horizontal'
};
var chart = new google.charts.Bar(document.getElementById('chart_good'));
chart.draw(dataTable, google.charts.Bar.convertOptions(options));
}
function drawChartBad() {
var dataTable = google.visualization.arrayToDataTable([
['Country', 'vtt', 'vttCloud'],
['Czech Republic', '50', '60'],
['Italy', '75', '80'],
['Croatia', '28', '40']
]);
var options = {
bars: 'horizontal'
};
var chart = new google.charts.Bar(document.getElementById('chart_bad'));
chart.draw(dataTable, google.charts.Bar.convertOptions(options));
}
&#13;
div {
padding-bottom: 24px;
}
&#13;
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div>Numbers</div>
<div id="chart_good"></div>
<div>Strings</div>
<div id="chart_bad"></div>
&#13;