嗨,这是我的 html 代码
<select id="difques">
<option value="firstfivemonth">firstfivemonth</option>
<option value="nextfivemonth">nextfivemonth</option>
</select>
这是我在 jquery 中使用 ajax 调用服务器的代码............
$('#difques').change(function(){
$.ajax({
type: "GET",
url: "ManyQuestionGraph",
data: "graphfor="+$('#difques :selected').val()+"&value="+${value},
success: function(data){
var obj=jQuery.parseJSON(data);
options.series[0].color='red';
options.xAxis.categories=obj.value;
options.series[0].data=obj.month;
chart = new Highcharts.Chart(options);
}
});
});
我的highchart代码是
var chart;
$(document).ready(function() {
var options = {
chart: {
renderTo: 'graphreport',
type: 'column'
},
title: {
text: 'Rating'
},
xAxis: {
categories: ['jan','feb','mar','apr','may']
},
yAxis: {
min: 0,
max: 5,
title: {
text: ''
}
},
tooltip: {
formatter: function() {
return ''+
this.series.name +': '+ this.y +'';
}
},
credits: {
enabled: false
},
series: [{
name: 'Rating',
data: [1,2,3,4,5],
color: '#77c4d3'
}]
}
chart = new Highcharts.Chart(options);
我的servlet代码是
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
JSONObject jsonobject = new JSONObject();
jsonobject.put("value",[5,4,3,2,1]);
jsonobject.put("month",['jun','jul','aug','sep','oct']);
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(jsonobject.toString());
}
我的网页看起来像这样......
但是当我在选择组合框中选择下五个月时,它使用 ajax 调用服务器,我可以在 ajax 成功期间从服务器获取 json 数据但是当我将数据传递给 highchart 时,它看起来像这样...... .
是我做错了还是我在编码中犯了一些错误......
帮我...........