jqplot在堆积条形图中为每个系列使用不同的y比例

时间:2013-10-22 01:21:30

标签: jqplot

enter image description here

我正在使用jqplot,为什么每个系列的堆叠条形图使用不同的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'
            }
        ],
      });

1 个答案:

答案 0 :(得分: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];

这可以解决您的问题。