2013-03-08 47 views
0

海的响应改变高图表值,这是我的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()); 
} 

和我的网页看起来像这样..... enter image description here

,但是当我在选择组合框中选择未来五年一个月对其使用Ajax调用服务器,我可以得到JSON数据从服务器在阿贾克斯的成功,但是当我通过数据highchart它看起来像这样.......

enter image description here

我做错了还是我在编码犯了一些错误...... ...

帮我...........

+0

你能展现比如你返回的JSON的?另外,在创建新图表之前,请确保先前的图表被销毁。 – 2013-03-08 14:09:22

+0

{“rate”:“,3.5,0,0,0”,“month”:“'jun','jul','aug','sep','oct'”}这是我返回的json – Kumar 2013-03-09 04:25:52

回答

0

这一点看起来我错了:

options.xAxis.categories=obj.value; 
options.series[0].data=obj.month; 

是不是南辕北辙?月份是类别,价值是数据?尝试:

options.xAxis.categories=obj.month; 
options.series[0].data=obj.rate; 
+0

谢谢为回答我试过这也没有输出图 – Kumar 2013-03-09 04:26:54

+0

现在更新回答我已经看到你的jsom – SteveP 2013-03-09 05:46:45

0

你JSON是错误的Highcharts,从变化:

{ 
    "rate":",3.5,0,0,0", 
    "month":"'jun','jul','aug','sep','oct'" 
} 

为了这样的事情:

{ 
    "rate": [3.5,0,0,0], 
    "month": ['jun','jul','aug','sep','oct'] 
} 
相关问题