2013-01-23 32 views
1

我正在使用jqPlot作为条形图,我想将x轴显示为图例。jqPlot - 无法在右侧显示x轴为图例

截图附...

enter image description here

代码:

var s1 = [2.5, 6.3, 7.4, 10]; 
var ticks = ['a', 'b', 'c', 'd']; 
plot2 = $.jqplot('chart2', [s1], { 
seriesDefaults: { 
    renderer:$.jqplot.BarRenderer, rendererOptions:{ varyBarColor : true }, 
    pointLabels: { show: true }, showLabel: true, }, 
    series: [ {label: 'Cups'}, {label: 'Dishes'}, ], 
    legend: { show: true, placement: 'outside', //rendererOptions: {numberColumns: 2} }, 
    axes: { xaxis: { renderer: $.jqplot.CategoryAxisRenderer, ticks: ticks }, 
      yaxis:{ tickOptions:{ formatString:'%.2f%' } } } 
+0

你可以发布你的代码 – Nandu

+0

代码是登录发表评论... – Kiran

回答

3

下面是如何做到这一点的example

var s1 = [2.5, 6.3, 7.4, 10]; 
var ticks = ['a', 'b', 'c', 'd']; 
plot2 = $.jqplot('chart1', [s1,[],[],[]], { //give it extra blank series 
seriesDefaults: { 
     renderer: $.jqplot.BarRenderer, 
     rendererOptions: { varyBarColor : true }, 
     pointLabels: { show: true }, 
     showLabel: true 
    }, 
    series: [ {}, 
       {renderer: $.jqplot.LineRenderer}, // set our empty series to the lineRenderer, so the bar plot isn't padded for room 
       {renderer: $.jqplot.LineRenderer}, 
       {renderer: $.jqplot.LineRenderer} ], 
    legend: { show: true, placement: 'outside', labels: ticks}, // give the legend the tick labels 
    axes: { xaxis: { renderer: $.jqplot.CategoryAxisRenderer, ticks: ticks }}, 
    yaxis: { tickOptions:{ formatString:'%.2f%' } } 
}); 

产地:

enter image description here

+0

尼斯解决方案马克。但是,我仍然想知道为什么用户想要这样做。在图例中放置x轴值是多余的,不是吗? –

+0

是的谢谢马克.. 这是工作。 – Kiran

+0

伟大的解决方案Mark.but如果我们将鼠标悬停在第二个或第三个栏上颜色已更改,以防止此问题? – Nandu