JQPlot Ajax-рендеринг проблемы - PullRequest
1 голос
/ 14 декабря 2011

Я пытаюсь визуализировать график jqplot, извлекая данные с помощью Ajax xml.

  $.ajax({
        type: "POST",
        url: "/ajaxXML.jsp",
        data: ({cmd: "report"}),
        dataType: "xml",
        success: function(xml) {
                var data= new Array();
                $(xml).find('graph').each(function(){
                var points = new Array()
                var x = $(this).attr('x');
                var y = $(this).attr('y');
                points.push(x);
                points.push(y);
                data.push(points);
            });

            plotGraph(data);

        }
    });             


function plotGraph( data){
     var line1=[['11-01-11',2052], ['11-02-11',2205], ['11-03-11',1910], ['11-04-11',2085], ['11-05-11',2261],  ['11-06-11',1714],  ['11-07-11',3123], ['11-08-11',3369], ['11-09-11',3515], ['11-10-11',3380], ['11-11-11',3476], ['11-12-11',3954], ['11-13-11',2799], ['11-14-11',3166], ['11-15-11',2932] ,['11-16-11',3289]];
     alert(data);
     alert(line1);
  $.jqplot('chart1', [data], {
        title:'Margin vs Date',
        axes:{
            xaxis:{
                renderer:$.jqplot.DateAxisRenderer
            },
            yaxis:{autoscale:true}
        },
        series:[{lineWidth:4}]

      });
}

XML выглядит как

     <graphs>
       <graph x="11-28-2011" y="48973"></graph>
       <graph x="11-29-2011" y="41981"></graph>
        <graph x="11-30-2011" y="45562"></graph>
       <graph x="12-01-2011" y="82437"></graph>
         <graph x="12-02-2011" y="83979"></graph>
       <graph x="12-03-2011" y="64444"></graph>
   </graphs>

, но некоторые, как эта стратегия не работает только хось заполняется без точек данных или оси Y на графике.

однако, когда я пытаюсь увидеть пример данных, например, line1, он работает, даже если данные, полученные с помощью вызова ajax, почти аналогичны

1 Ответ

2 голосов
/ 14 декабря 2011

Когда вы анализируете xml, ваши значения y помещаются в массив как строки, а не целые числа.Попробуйте:

$(xml).find('graph').each(function(){
  var points = new Array()
  var x = $(this).attr('x');
  var y = $(this).attr('y');
   points.push(x);
   points.push(parseInt(y)); //modified line!
   data.push(points);
});
...