2014-02-07 37 views
0

我一直在试图用flot做一个图表,并且遇到了问题。我使用开发人员工具查看错误的位置,以及JSlint检查我的JavaScript,但都表示没有“错误”。除了图表没有显示,所以我一定做错了什么。以下是图表代码:Flot图不显示。没有错误代码

 $(document).ready(function(){ 
      var graphdata = {"label":"MMR Over time","data":{"Rubick":6524,"Lion":6550,"Magnus":6565,"Keeper of the Light":6566}}; 
      var options = { 
       series: { 
        lines: { show: true }, 
        points: { 
         radius: 3, 
         show: true 
        } 
       } 
      }; 

     $.plot($(".graph_holder"), 
       graphdata, 
         options); 
     }); 
+0

您如何看待图形的外观?如果你想要一个线形图,那么数据应该是数组格式,x值是数字,而不是一个字符串。 IIRC。 – Sergio

回答

1

您需要重新阅读Data Format上的flot api部分。

"data":{"Rubick":6524,"Lion":6550,"Magnus":6565,"Keeper of the Light":6566} 

无效。该数据应该是一个数组的数组的形式:

"data": [[0,6524],[1,6550],[2,6565]] //etc... 

如果您使用的是categories插件,你的数据几乎是正确的,但它是:

"data":[["Rubick",6524],["Lion",6550],["Magnus",6565],["Keeper of the Light",6566]] 

,当然还有,如果您正在使用该插件,则需要启用该插件:

xaxis: { 
    mode: "categories" 
}