0

This is the sample data:

var data = [
    {row: 0, col: 0, value: [{x: 1, y: 19}, {x: 2, y: 20}]},
    {row: 0, col: 1, value: [{x: 1, y: 24}, {x: 2, y: 27}]},
    {row: 1, col: 1, value: [{x: 1, y: 31}, {x: 2, y: 26}]},
    {row: 1, col: 2, value: [{x: 1, y: 29}, {x: 2, y: 19}]},
]

I cannot figure out a way of defining x-domain.

var x1 = d3.scale.ordinal()
        .domain(data.map(function(d) { return d.value.x; }))
        .rangeRoundBands([0, chartW], 0.1);

This bit gives error:

 .domain(data.map(function(d) { return d.value.x; }))

How can I iterate through the inner array of values object ??

Thanks in advance !

9
  • Its best that you manipulate the data that you have into d3friendly format data. Commented Apr 25, 2014 at 6:27
  • @NevinMadhukarK Does it mean to rearrange my data in a simpler format ?? Commented Apr 25, 2014 at 6:35
  • See stackoverflow.com/questions/22316866/… I had to change my data to a d3friendly data format,where the d3 inbuilt functions can easily recognize. Commented Apr 25, 2014 at 6:38
  • @NevinMadhukarK Thanks for that! But is there no way of doing it with the format that I have above?? I really want my data to be formatted like above. Commented Apr 25, 2014 at 6:43
  • 1
    Take a look through github.com/mbostock/d3/wiki/Gallery You might find your required output,and compare the data input given there and change your data format to that. Commented Apr 25, 2014 at 6:56

1 Answer 1

2

You need to have two nested iterations here:

.domain([
  d3.min(data, function(d) { return d3.min(d.value, function(e) { return e.x; }); }),
  d3.max(data, function(d) { return d3.max(d.value, function(e) { return e.x; }); })
  ]);

Similarly for y.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.