我有以下代码:
HTML代码
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
的JavaScript
$(function () {
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: 1,//null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2014'
},
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: [
['Firefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true
},
]
}]
});
});
此代码的输出是一个饼图,其值为div(15),IE(31)和Firefox(53)。
这是一组文本框和一个按钮:
Number of Arson: <input type="text" id="arson" name="arson">
Number of Homicide: <input type="text" id="homicide" name="homicide">
Number of Physical Injuries: <input type="text" id="physicalinjuries" name="physicalinjuries">
Number of Carnapping: <input type="text" id="carnapping" name="carnapping">
Number of Ethical Law Violation: <input type="text" id="elv" name="elv">
<input type="submit" id = "chart" value="Submit">
单击按钮时,是否可以传递文本框的值并将其用作图表(PIE)中的自定义百分比(切片)?
我的目标是调用一个PHP函数,它将使用tablename中的select(count)并将其传递给文本框,然后当按下该按钮时,该值将被发送到PIE图表。
答案 0 :(得分:0)
$('#chart').on('click', function() {
var value = Number($('#arson').val());
var myChart = $('#container').highcharts();
myChart.series[0].data[0].update(value);
});