带有浮动的多条形图,带有x轴字符串

时间:2013-04-30 06:43:29

标签: flot

我正在使用float图表。我遇到了multiplebar图表的问题。当我试图将x轴设为“string”时,它只显示单个条形。我需要在形式上显示x轴刻度,以便像城市名称一样刺痛。我如何使用X-AXIS作为字符串获取多个条形码?

my code:
$(function () {
var previousPoint;


 var d1 = [ ["January", 10], ["February", 8], ["March", 4], ["April", 13], ["May", 17], ["June", 9] ];
 var d2 = [ ["January", 5], ["February", 2], ["March", 11], ["April", 2], ["May", 5], ["June", 12] ];
 var d3 = [ ["January", 11], ["February", 12], ["March", 6], ["April",8], ["May", 11], ["June",16] ];
 var ds = new Array();

ds.push({
    data:d1,
    bars: {
        show: true, 
        barWidth: 0.2, 
        order: 1,
        lineWidth : 2
    }
});
ds.push({
    data:d2,
    bars: {
        show: true, 
        barWidth: 0.2, 
        order: 2
    }
});
ds.push({
    data:d3,
    bars: {
        show: true, 
        barWidth: 0.2, 
        order: 3
    }
});

//tooltip function
function showTooltip(x, y, contents, areAbsoluteXY) {
    var rootElt = 'body';

    $('<div id="tooltip" class="tooltip-with-bg">' + contents + '</div>').css( {
        position: 'absolute',
        display: 'none',
        'z-index':'1010',
        top: y,
        left: x
    }).prependTo(rootElt).show();
}


//Display graph
$.plot($("#placeholder"), ds, {
xaxis: { mode: "categories",
      tickLength: 0


} ,
    grid:{
        hoverable:true
    },

});
});

1 个答案:

答案 0 :(得分:0)

我认为你不能在月份数据中传递字符串。如果您想使用月份,请查看flot api - https://github.com/flot/flot/blob/master/API.md

这个小提琴也可以帮助你 - http://jsfiddle.net/jSQ2Y/3/

var m1 = {
data : [[1356998400000,14.72]],    
bars: { barWidth: 60*60*24*31*1000 }
};

var m2 = {
data : [[1359676800000,30.74]],
bars: { barWidth: 60*60*24*1000 *28 }
};

var m3 = {
data : [[1362096000000,18.57]],
bars: { barWidth: 60*60*24*31*1000 }
};