0

My needs are very similar to those of this question, where a series of records like:

var data = [
 // time, text, temperature, count
 ['1379952000', 'field_1', 91, 56],
 ['1379952000', 'field_2', 50, 20],
 ['1379952000', 'field_3', 88, 24],
 ['1379952000', 'field_4', 50, 37],
 ['1379953200', 'field_1', 97, 58],
 ['1379953200', 'field_2', 84, 86],
 ['1379953200', 'field_3', 85, 62],
 ['1379953200', 'field_4', 88, 73]
 // etc.
];

Need to be plotted as a set of time series lines, each series corresponding to each unique value of the text field (i.e. field_1, field_2, etc.). A working possible implementation was given in the answer to that question here. However, I need the series to be plotted as bars.

I figured I should check how is dc.js's seriesChart class implemented and try to fork it to use barChart instead of lineChart as its internal plotting function. You can find the result here. (See the file seriesbarchart.js and compare to the source)

The one flaw my test has is the single-pixel width the bars come out with. I'm a newbie to this Web world of Javascript/HTML/CSS and even more so about D3 and dc.js. Can somebody knowledgeable give me a hand with this? Thanks in advance.

Community
  • 1
  • 1
Luis E.
  • 841
  • 11
  • 15

1 Answers1

1

You can define the xUnits to be a time interval, such as minutes or hours:

time_chart
.xUnits(d3.time.minutes)

For your data, however, you probably want a 15 minute time interval. This would require a custom time interval.

Here is a question that addresses that: How to define custom time interval in d3.js

Community
  • 1
  • 1
DJ Martin
  • 2,579
  • 20
  • 24
  • This worked, after having to add a line to the source `d3.js` in order to expose the `d3_time_interval` class, so that I could define a custom time unit in a way identical to that of `d3.time.minute`. Would you have a less "hacky" way of achieving this? – Luis E. Jan 06 '14 at 04:38
  • Hi Luis, I suppose you could redefine this class on your own. could you share your solution for future viewers of this thread? – DJ Martin Jan 06 '14 at 18:26