Skip to content

using log() scale for bar chart y-axis #477

@jjguy

Description

@jjguy

Using 2.0.0-dev pulled on or about 1 Dec.

I've got a working chart with y-axis defined as

 .y(d3.scale.linear().domain([0, max_y_value]))

but the range of values are too diverse for the height of the graph. I changed to log scale:

 .y(d3.scale.log().domain([0, max_y_value]))

and the graph disappears - each bar is plotted with y=0 and height=0:

<rect class="bar" fill="#CFEAF3" x="92.96428571428571" y="0" width="47" height="0"></rect>

I presume this is since log(0) == -Infinity, so I convert the domain lower bound to 1:

.y(d3.scale.log().domain([1, max_y_value]))

that results in seemingly-accurate y-values but a height of Infinity:

<rect class="bar" fill="#CFEAF3" x="92.96428571428571" y="24.240901843984844" width="47" height="Infinity"></rect>

Infinity is from this block of code:

function barHeight(d) {
    return dc.utils.safeNumber(Math.abs(_chart.y()(d.y + d.y0) - _chart.y()(d.y0)));
}

_chart.y() is log() and d.y0 is always 0 - resulting in height="Infinity" for each bar.

I can't find any docs on y0, nor any assignment in the source. Is it a bug? Do I have to set the domain/range elsewhere?

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions