1

在此处输入图像描述

我正在使用 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'
            }
        ],
      });
4

1 回答 1

0

这是发生的,因为您将数据作为string. 因此,当您堆叠条形图时,逻辑会将两个值相加以显示堆叠条形图。但在您的情况下,“1”和“2”,它们被连接起来,因为您将它们作为字符串传递以形成“21”,然后将其转换为整数以进行绘图。这就是为什么你看到 21 被绘制出来的原因。

JsFiddle 链接

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

这将解决您的问题。

于 2013-10-22T02:53:28.873 回答