2

I'm trying to set up a horizontal bar graph using jqplot as follows:

var plot1 = $.jqplot('graph', [gData], {
    seriesDefaults: {
        renderer:$.jqplot.BarRenderer,
        rendererOptions: {
            barDirection: 'horizontal'
        }
    },
    axes: {
        yaxis: {
            renderer: $.jqplot.CategoryAxisRenderer,
            ticks: gTicks
        }
    }
});

This code works fine with vertical bars, like:

var plot1 = $.jqplot('graph', [gData], {

    seriesDefaults: {
        renderer:$.jqplot.BarRenderer
    },
    axes: {
        xaxis: {
            renderer: $.jqplot.CategoryAxisRenderer,
            ticks: gTicks
        }
    }
});

But when I go to make it horizontal, suddenly the bars no longer line up with the ticks. For example, for some ticks, there may be two or more overlapping bars. And for some, there may be none at all. Finally, there is an additional 'undefined' tick that seems to have tons of bars overlapping.

gData and gTicks are both javascript arrays.

Any thoughts?

EDIT: The undefined category is actually my own creation, but the problem remains unchanged.

4

1 に答える 1

0

あなたにとってうまくいかない理由は、グラフの向きを水平に変更するときに、それに応じてデータを変更していないからです。したがって、これが問題であると仮定すると、チャートのデータは、の Web ページ の例のようjqPlotに、次の形式にする必要があります。

   [[[2,1], [4,2], [6,3], [3,4]],
    [[5,1], [1,2], [3,3], [4,4]],
    [[4,1], [7,2], [1,3], [2,4]]]

上記 (ポイントの配列) とは対照的に、値配列表記 (以下) を使用してシリーズを表現することもできます。

  [[200, 600, 700, 1000],
   [460, -210, 690, 820],
   [-260, -440, 320, 200]]

この表記法を使用すると、以下の例に示すように、データ形式を気にせずにチャートの向きを変更できます。データは同じままで、適切なグラフのパラメーターのみが変更されます。

于 2012-07-12T08:55:10.630 に答える