yogk
yogk

Reputation: 381

Fix categories in categoriaxis in dimple js

I am using Dimple js to make a bar chart with one bar for each day (Sunday, Monday...). The problem is that sometimes there won't be data for a few days but I would still want my chart to show all the days with a value 0.

How do I fix all the categories which should be shown on the axis?

Edit: Here's a demo: jsfiddle.net/neme8got/ I want the chart to show the days not shown now with a volume 0.

Upvotes: 1

Views: 144

Answers (1)

ne8il
ne8il

Reputation: 2427

I don't believe there's an easy way to do this with Dimple. The values shown on the x axis are provided by axis._scale.domain(). Unfortunately even if you set this to the full array of values, dimple overrides this during the draw method, using the values plucked from the data from the category field string.

Your best bet is to change the data (on client side or server side) to add values for all the missing days. I've updated the example (using Underscore.js) to put in 0 values for the missing days :

var allDays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
var missing = _.difference(allDays, _.pluck(avg_by_day, 'Day'));
_.each(missing, function(missingDay){
    avg_by_day.push({'Avg Volume' : 0, 'Day' : missingDay}); 
});

http://jsfiddle.net/neme8got/1/

Upvotes: 1

Related Questions