javascript - 无法为谷歌饼图增加价值
问题描述
$(document).ready(function(){
name1= $("#party1_name").val();
count1=$("#party1_count").val();
name2= $("#party2_name").val();
var count2=$("#party2_count").val();
name3= $("#party3_name").val();
count3=$("#party3_count").val();
// Load google charts
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
// Draw the chart and set the chart values
function drawChart() {
alert("Value: " + count2);
var value1=count1;
var value2=2;
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
[name1, value1],
[name2, value2],
[name3, 4],
['Gym', 2],
['Sleep', 8]
]);
// Optional; add a title and set the width and height of the chart
var options = {'title':'Result Analysis', 'width':550, 'height':400};
// Display the chart inside the <div> element with id="piechart"
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
});
当 m 从输入字段中获取数据并将数据添加到 dataarray 时,例如 value1 变量。图表中不显示任何内容。但是当添加 value2 变量时它的工作。我已经使用警报进行了测试。我得到了正确的值,但没有显示数据。
这就是如何将数据添加到输入字段。
<input type="text" id="party1_name" value="<?=$party_name1?>">
<input type="number" id="party1_count" value="<?=$count_part1?>">
<input type="text" id="party2_name" value="<?=$party_name2?>">
<input type="text" id="party2_count" value="<?=$count_part2?>">
<input type="text" id="party3_name" value="<?=$party_name3?>">
<input type="text" id="party3_count" value="<?=$count_part3?>">
解决方案
推荐阅读
- python - 在 Google App Engine 中使用 Python 的私有存储库
- java - 批处理管道上的不同操作
- opengl-es - 使用“平面”着色器接口变量会导致性能大幅下降
- sql - Postgres 类似的查询需要不同的时间,不知道出了什么问题
- django - Django decimal SyntaxError:views.py 文件中的无效语法错误
- c++ - 在 C++ 中的“new”运算符之后使用“realloc”是否安全?
- android - GPIO 值总是在变化
- checkbox - 带有复选框和“a”元素的 ion-item - 单击“a”元素单击整个项目和复选框
- sql - 在 SQL 中选择不在当前表中的数字组合
- javascript - Webcodecamjs-QR 码扫描库在 Safari 浏览器中不起作用