同一系列的 jqPlot 数据相互重叠

发布于 2024-12-09 15:07:10 字数 1486 浏览 2 评论 0原文

我尝试创建的 jqplot 图表有一个小问题。

我想将 2008 年的所有数据放入一个类别,并使用某种颜色对其进行样式设置,然后对 2009 年执行相同的操作。

目前我有以下输出:

当前图表的外观(imgur 链接)

使用此代码:

$(document).ready(function(){
    // For horizontal bar charts, x an y values must will be "flipped"
    // from their vertical bar counterpart.
    var plot2 = $.jqplot('tableTest', [
        [[10,2008], [12,2008], [11,2008], [13,2008]],
        [[2,2009], [4,2009], [6,2009], [3,2009],]
        ], {
        seriesDefaults: {
            renderer:$.jqplot.BarRenderer,
            // Show point labels to the right ('e'ast) of each bar.
            // edgeTolerance of -15 allows labels flow outside the grid
            // up to 15 pixels.  If they flow out more than that, they
            // will be hidden.
            pointLabels: { show: true, location: 'e', edgeTolerance: -15 },
            // Rotate the bar shadow as if bar is lit from top right.
            shadowAngle: 135,
            // Here's where we tell the chart it is oriented horizontally.
            rendererOptions: {
                barDirection: 'horizontal'
            }
        },
        axes: {
            yaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,

                /*rendererOptions: {
                    groupLabels:['Fruits', 'Vegetables']
                }*/

            }
        }
    });
});

有人知道如何分离柱形图吗?

先感谢您

I have a small issue with a jqplot chart im trying to create.

I want to put all 2008 data into one category and style it with a certain colour, then do the same for 2009.

Currently I have this output:

how current chart looks (imgur link)

Using this code:

$(document).ready(function(){
    // For horizontal bar charts, x an y values must will be "flipped"
    // from their vertical bar counterpart.
    var plot2 = $.jqplot('tableTest', [
        [[10,2008], [12,2008], [11,2008], [13,2008]],
        [[2,2009], [4,2009], [6,2009], [3,2009],]
        ], {
        seriesDefaults: {
            renderer:$.jqplot.BarRenderer,
            // Show point labels to the right ('e'ast) of each bar.
            // edgeTolerance of -15 allows labels flow outside the grid
            // up to 15 pixels.  If they flow out more than that, they
            // will be hidden.
            pointLabels: { show: true, location: 'e', edgeTolerance: -15 },
            // Rotate the bar shadow as if bar is lit from top right.
            shadowAngle: 135,
            // Here's where we tell the chart it is oriented horizontally.
            rendererOptions: {
                barDirection: 'horizontal'
            }
        },
        axes: {
            yaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,

                /*rendererOptions: {
                    groupLabels:['Fruits', 'Vegetables']
                }*/

            }
        }
    });
});

Does anyone have an idea how I can seperate out the bars?

Thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我喜欢麦丽素 2024-12-16 15:07:10

您添加自己的自定义刻度,并且数据格式略有不同。我对 jsFiddle 中的代码进行了调整:

$(document).ready(function(){
    // For horizontal bar charts, x an y values must will be "flipped"
    // from their vertical bar counterpart.

    var ticks = ['2008', '2009'];

    var plot2 = $.jqplot('tableTest', [[10, 2], [12, 3], [11, 6], [13, 3]], {
        seriesDefaults: {
            renderer:$.jqplot.BarRenderer,
            // Show point labels to the right ('e'ast) of each bar.
            // edgeTolerance of -15 allows labels flow outside the grid
            // up to 15 pixels.  If they flow out more than that, they
            // will be hidden.
            pointLabels: { show: true, location: 'e', edgeTolerance: -15 },
            // Rotate the bar shadow as if bar is lit from top right.
            shadowAngle: 135,
            // Here's where we tell the chart it is oriented horizontally.
            rendererOptions: {
                barDirection: 'horizontal'
            }
        },
        axes: {
            yaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: ticks
            }
        }
    });
});

You add your own custom ticks, and format the data slightly differently. I've made the adjustments to the code in a jsFiddle:

$(document).ready(function(){
    // For horizontal bar charts, x an y values must will be "flipped"
    // from their vertical bar counterpart.

    var ticks = ['2008', '2009'];

    var plot2 = $.jqplot('tableTest', [[10, 2], [12, 3], [11, 6], [13, 3]], {
        seriesDefaults: {
            renderer:$.jqplot.BarRenderer,
            // Show point labels to the right ('e'ast) of each bar.
            // edgeTolerance of -15 allows labels flow outside the grid
            // up to 15 pixels.  If they flow out more than that, they
            // will be hidden.
            pointLabels: { show: true, location: 'e', edgeTolerance: -15 },
            // Rotate the bar shadow as if bar is lit from top right.
            shadowAngle: 135,
            // Here's where we tell the chart it is oriented horizontally.
            rendererOptions: {
                barDirection: 'horizontal'
            }
        },
        axes: {
            yaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: ticks
            }
        }
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文