我有一个程序,当您在文本框中输入值时,它将显示高图表中的百分比。这是我的代码
<!DOCTYPE html>
<head>
<script src="https://code.jquery.com/jquery-2.1.3.js" type="text/javascript"></script>
<script src="http://code.highcharts.com/highcharts.js" type="text/javascript"></script>
<script src="http://code.highcharts.com/modules/exporting.js" type="text/javascript"></script>
</head>
<body>
<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
<br>Number of Arson:
<input type="text" id="arson" name="arson">
<br>Number of Homicide:
<input type="text" id="homicide" name="homicide">
<br>Number of Physical Injuries:
<input type="text" id="physicalinjuries" name="physicalinjuries">
<br>Number of Carnapping:
<input type="text" id="carnapping" name="carnapping">
<br>Number of Ethical Law Violation:
<input type="text" id="elv" name="elv">
<br>
<input type="submit" id="chart" value="Submit">
<script>
$(document).ready(function() {
('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: 1, //null,
plotShadow: false
},
title: {
text: 'Crimes for this Year'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
}
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Arson', 0],
['Homicide', 0],
['Physical Injuries', 0],
['Carnapping', 0],
['Ethical Law Violation', 0]
]
}]
});
$('#chart').on('click', function() {
var myChart = $('#container').highcharts();
var wrongValue = false;
function setValue(type, slot) {
var value = Number($('#' + type).val());
if (isNaN(value) || value === undefined) {
wrongValue = true;
value = 0;
}
myChart.series[0].data[slot].update(value);
}
setValue('arson', 0);
setValue('homicide', 1);
setValue('physicalinjuries', 2);
setValue('carnapping', 3);
setValue('elv', 4);
if (wrongValue) {
// warn the user.
}
});
});
</script>
</body>
</html>
然后我将其保存为chart.html,但是当我使用谷歌浏览器运行它时,图表没有显示,我得到了Uncaught ReferenceError的错误:$未定义我的代码有什么问题?