Timeseries Update

language: Javascript
license: Other

Code for Snippet:

                
var formatter;
function updateFormatter(byMonth) {
  formatter = d3.time.format(byMonth ? '%Y-%m' : '%Y-%m-%d')
}
 
updateFormatter();
 
var chart = c3.generate({
    data: {
        x: 'date',     
        columns: [
            ['date', '2014-01-01', '2014-01-02', '2014-01-03'],
            ['data1', 100, 200, 300],
        ]
    },
    axis: {
      x: {
        type: 'timeseries',
        tick: {
            format: function (x) { // x comes in as a time string.
              return formatter(x);
            }
        }
      }
    }
});
 
d3.select('#btnByMonth').on('click', function () {
  updateFormatter(true);
  chart.flush();            
});
d3.select('#btnByWeek').on('click', function () {
  updateFormatter(false);
  chart.flush();            
});
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 216
Date Added: 2015-06-04 21:24:42
Last Modified: 2015-06-04 15:24:55

Web Analytics