2013-10-22 295 views
1

enter image description herejqplot在堆叠条形图

我使用jqplot使用每个系列不同y缩放比例,为什么使用不同的Y的比例为每个系列的堆叠条形图?

var ticks = ["test1", "test2", "test3", "test4", "test5", "test6", "test7", "test8", "test9"]; 
var s1 = ["3", "3", "1", "3", "2", "3", "30", "3", "3"]; 
var s2 = ["0", "0", "2", "0", "0", "0", "0", "0", "0"]; 

     plot3 = $.jqplot('daily-bookings-by-user', [s1, s2], { 
     // Tell the plot to stack the bars. 
     stackSeries: true, 
     seriesDefaults:{ 
      renderer:$.jqplot.BarRenderer, 
      rendererOptions: { 
       // Put a 30 pixel margin between bars. 
       barMargin: 20, 
       // Highlight bars when mouse button pressed. 
       // Disables default highlighting on mouse over. 
       highlightMouseDown: true 
      }, 
      pointLabels: {show: true} 
     }, 
     axes: { 
      xaxis: { 
       renderer: $.jqplot.CategoryAxisRenderer, 
       ticks: ticks 
      }, 
      yaxis: { 
      // Don't pad out the bottom of the data range. By default, 
      // axes scaled as if data extended 10% above and below the 
      // actual range to prevent data points right on grid boundaries. 
      // Don't want to do that here. 
      padMin: 0, 
      pad: 0, 
      min: 0, 
      }, 
     }, 
     legend: { 
      show: true, 
      location: 'e', 
      placement: 'outside' 
     }, 
     series:[ 
      { 
       label:'Test 1' 
      }, 
      { 
       label:'Test 2' 
      } 
     ], 
     }); 
+0

我无法得到图片上传抱歉。它只是显示为灰色方块 – jax

回答

0

这是因为你传递的数据为string。 所以当你堆叠酒吧,逻辑加起来这两个值来显示堆积酒吧。 但在你的情况下,“1”和“2”,它们会被连接,因为你将它们作为字符串传递给“21”,然后将其转换为整数来绘图。这就是为什么你看到21被绘制。

JsFiddle link

var s1 = [3, 3, 1, 3, 2, 3, 30, 3, 3]; 
var s2 = [0, 0, 2, 0, 0, 0, 0, 0, 0]; 

这将解决您的问题。

+0

好点,欢呼声。实际上,原始数据来自json数据源,所以我想我只是假设它们是数字。 – jax