凹坑js x轴日期问题与条形图

时间:2014-04-10 13:46:37

标签: javascript jquery d3.js data-visualization dimple.js

我在x轴上的条形图条添加到正确的位置但是x轴刻度在凹坑js中重复了月份和年份。如何调整x轴,因为此数据中只有三个值?这是jfiddle:http://jsfiddle.net/Ra2xS/17/

有什么建议吗?

var dim = {"width":590,"height":450}; //chart container width
var data = [{"date":"01-02-2010","cost":"11.415679194952766"},{"date":"01-03-2010","cost":"10.81875691467018"},{"date":"01-04-2010","cost":"12.710197879070897"}];


function barplot(id,dim,data)
{
    keys = Object.keys(data[0]);
    var xcord = keys[0];
    var ycord = keys[1];
    var svg = dimple.newSvg(id, dim.width, dim.height);

    var myChart = new dimple.chart(svg,data);
    myChart.setBounds(60, 30, 505, 305);        

    //var x = myChart.addCategoryAxis("x", xcord);
    var x = myChart.addTimeAxis("x", xcord, "%d-%m-%Y","%b %Y");
    x.addOrderRule(xcord);
    x.showGridlines = true;

    var y = myChart.addMeasureAxis("y", ycord);
    y.showGridlines = true;
    y.tickFormat = ',.1f';    

    var s = myChart.addSeries(null, dimple.plot.bar);
    var s1 = myChart.addSeries(null, dimple.plot.line);
    s1.lineWeight = 3;
    s1.lineMarkers = true;

    myChart.draw(1500);

}

barplot("body",dim,data);

1 个答案:

答案 0 :(得分:0)

您可以通过将轴的时间段设置为月份来阻止多余的刻度/标签:

x.timePeriod = d3.time.months;

完整演示here