How to format y-axis values ​​in rickshaw charts

I want to use Javascript graphics    http://code.shutterstock.com/rickshaw/

and I got it for one exception, when my values ​​are less than 0.00000100, then the y axis values ​​are shown in scientific format, for example. 2e-7 for a value of 0.00000020

How do I make it show 0.00000020 instead of 2e-7?

+5
source share
2 answers

I have not used a rickshaw, but look at this example on the main page:

var y_axis = new Rickshaw.Graph.Axis.Y( {
        graph: graph,
        orientation: 'left',
        tickFormat: Rickshaw.Fixtures.Number.formatKMBT,
        element: document.getElementById('y_axis'),
} );

It looks like you can pass the tickMormat function. In this case, formatKMBT is passed, and it looks like this:

Rickshaw.Fixtures.Number.formatKMBT = function(y) {
    var abs_y = Math.abs(y);
    if (abs_y >= 1000000000000)   { return y / 1000000000000 + "T" }
    else if (abs_y >= 1000000000) { return y / 1000000000 + "B" }
    else if (abs_y >= 1000000)    { return y / 1000000 + "M" }
    else if (abs_y >= 1000)       { return y / 1000 + "K" } 
    ...ect

Here you can use the d3 built-in number formatters or collapse your own. For instance:

function yAxisFormat(d){ return d.toFixed(8); }
+4

:

var yAxis = new Rickshaw.Graph.Axis.Y( {
            graph: graph,
            tickFormat: function(y){return y.toPrecision(3)}
        } );

, .

+4

All Articles