Search code examples
javascriptd3.jsdimple.js

Dimple.js bar length


I'm trying to draw a simple histogram on dimple.js

The thing is the bars doesn't reach the x axis, they just look like small boxes floating around.

a histogram

var svg = dimple.newSvg("body", 2024, 760);
d3.csv("data/data.csv", function(d){
    data = d.filter(function(x){return x['Origin'] == 'AK' && x['Year'] == '2006'});
    for(i=0;i<data.length;i++){
        data[i]['Count'] = +data[i]['Count']
    }
    console.log(data[10])

    chart = new dimple.chart(svg, data);
    chart.addCategoryAxis("x", ["Destination"]);
    chart.addCategoryAxis("y", ["Count"]);
    chart.addSeries(null, dimple.plot.bar);
    chart.draw();

My data is an array of rows like this:

Object { Year: "2006", Origin: "AK", Destination: "OH", Count: 68 }

How can I make it look like a histogram? I want to see the full lenght of the bars.

Thanks


Solution

  • You should change type for y axis (from "category" into "measure"):

    ...
    chart = new dimple.chart(svg, data);
    chart.addCategoryAxis("x", ["Destination"]);
    chart.addMeasureAxis("y", ["Count"]);
    chart.addSeries(null, dimple.plot.bar);
    

    See on dimple documentation for differect axis types: