jquery - 如何更改 jqplot 堆叠水平条形图上的标签

标签 jquery jqplot bar-chart

我正在使用 jqplot 使用此处显示的代码创建堆叠水平条形图:

perc_data = [[[6, "1"]], [[92, "1"]], [[1, "1"]], [[1, "1"]]];
series_array = [ { label: "Mud", color: "#ccaa00"}, { label: "Sand", color: "#ffeecc"}, 
                 { label: "Gravel", color: "#dddddd"}, { label: "Rock", color: "#664400"} ];
var perc_chart = $.jqplot('perc_div', perc_data, {
    stackSeries: true,
    seriesDefaults: {
        renderer:$.jqplot.BarRenderer,
        shadowAngle: 135,
        rendererOptions: {  barWidth: 25,
                            barDirection: 'horizontal',
        }
    },
    series: series_array,
    axes: {
        yaxis: {
            renderer: $.jqplot.CategoryAxisRenderer,
            rendererOptions: {  tickRenderer: $.jqplot.AxisTickRenderer, 
                                tickOptions: {  mark: null,
                                                fontSize: 12
                                             }
            }
        },
        xaxis: {
            min: 0,
            max: 100,
            numberTicks: 6
        }
    },
    grid: {
        drawGridlines: false,
        drawBorder: false,
        shadow: false
    }
});

生成的条形图如下所示:

enter image description here

接下来我想做的是将栏的标签从“1”更改为“我的标签”。 我本以为我可以简单地将 perc_data 从其原始值更改为以下值:

perc_data = [[[6, "My Label"]], [[92, "My Label"]], [[1, "My Label"]], [[1, "My Label"]]];

但这会导致一个空的条形图:

enter image description here

有人可以告诉我我做错了什么以及如何调整这个标签。

谢谢。

最佳答案

使用ticks option (2nd example on this page) :

perc_data = [[[6, "1"]], [[92, "1"]], [[1, "1"]], [[1, "1"]]];
ticks = ["My Label"];

series_array = [ { label:'Mud', color:"#ccaa00"}, { label:"Sand", color:"#ffeecc"}, { label:"Gravel", color:"#dddddd"}, { label:"Rock", color:"#664400"} ];

var perc_chart = $.jqplot('chart1', perc_data, {
    stackSeries: true,
    seriesDefaults: {
        renderer:$.jqplot.BarRenderer,
        shadowAngle: 135,
        rendererOptions: {  barWidth: 25,
                            barDirection: 'horizontal',
        }
    },
    series: series_array,
    axes: {
        yaxis: {
            renderer: $.jqplot.CategoryAxisRenderer,
            rendererOptions: {  tickRenderer: $.jqplot.AxisTickRenderer, 
                                tickOptions: {  mark: null,
                                                fontSize: 12
                                             }
            },
            ticks: ticks
        },
        xaxis: {
            min: 0,
            max: 100,
            numberTicks: 6
        }
    },
    grid: {
        drawGridlines: false,
        drawBorder: false,
        shadow: false
    }
});

enter image description here

顺便说一句,{ label="Mud", color="#ccaa00"} 无效 javascript 应该是 { label:"Mud", color:"#ccaa00"}

关于jquery - 如何更改 jqplot 堆叠水平条形图上的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8749892/

相关文章:

plot - 使用 R 创建重叠条形图

jquery - 带偏移量的滚动顶部动画

javascript - 需要恢复点击间隔

javascript - 在 jqPlot 中滚动

javascript - jqPlot:重叠系列

javascript - 如何在 Highcharts 中的镜像条形图上叠加散点图?

javascript - 多个类的选择器

javascript - 使用 javascript(不是 jquery)将值 append 到元素

javascript - jqplot 单杠问题

r - ggplot : change the order of stacked bars based on the a name within the bar