凹坑js测量轴值

时间:2014-04-10 12:29:28

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

问题是将测量轴(y - 成本)的数据值视为整数的凹坑js,它们是十进制值。有任何建议如何解决这个问题?这是jsfiddle:http://jsfiddle.net/Ra2xS/7/

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

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);
    x.addOrderRule(xcord);
    x.showGridlines = true;

    var y = myChart.addMeasureAxis("y", ycord);
    y.showGridlines = true; 

    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 :(得分:8)

工具提示从轴获取数据,因此要获得更高的精度,您必须更改y轴的刻度格式:

y.tickFormat = ',.1f';

完整演示here