0

I have a simple c3js line chart w/3 different lines. When I "unselect" all 3 data sources, the x-axis tick values disappear. I was wondering if there was anyway to reverse this behavior? I'd like to show the x-axis tick values even when there is no data present.

The xaxis tick values are of a 'timeseries' type. Thanks!

Here is my c3 config for the line chart:

bindto: '#test',
data: {
  x: 'date',
  xFormat: '%m%d',
  columns: [],
},
legend: {
  position: 'bottom',
},
axis: {
  y: {
    tick: {
      format: function (d) { return d + '%'; },
      count: 5,
    },
    max: 100,
    padding: {
      top: 0,
      bottom: 0,
    },
  },
  x: {
    type: 'timeseries',
    tick: {
      culling: false,
    },
  },
},
color: {
  pattern: [testRateColor, firstRateColor, secRateColor],
},
Shail Patel
  • 1,764
  • 5
  • 30
  • 46
  • Please post some code! Specifically, how are you selecting / deselecting data sources? – thodic May 18 '15 at 18:32
  • The selecting/deselecting is the built in C3 JS, no special code. For example: http://c3js.org/samples/simple_xy.html -- if you look at that and click on all the legend elements, then the x-axis disappears. – Shail Patel May 18 '15 at 18:37
  • This functionality seems baked into c3js. I'll look at the source code and see you can override it. – thodic May 18 '15 at 18:48

1 Answers1

1

Unfortunately this functionality is baked into c3.js and the only way to change this (aside from working purely from d3) is monkey patching. You will find the offender on line 6814 of c3.js:

tickExit = tick.exit().remove(),

If you change this to:

tickExit = function() {},

The ticks are no longer removed.

thodic
  • 2,229
  • 1
  • 19
  • 35
  • Thanks for digging into the source! Yeah I think what I'll probably do is just not allow the client to deselect all data sources. I think that'll probably be cleaner than monkey patching. – Shail Patel May 18 '15 at 19:38
  • @ShailPatel Agreed, you also don't know what other functionality this override might break. Good luck! – thodic May 18 '15 at 19:44