N
N
Ninja Mate2016-04-28 21:43:09
JavaScript
Ninja Mate, 2016-04-28 21:43:09

How in my case to redo the functions to get values ​​(D3.js)?

I made D3.js graphics according to the tutorial and everything worked out, but there the date is from the usual array, and I need it from this one.

var dataArray= [
                          [ {'name': 'Education', 'number': 33}],
                          [ {'name': 'Promotion', 'number': 10}],
                          [ {'name': 'Events', 'number': 55 }]
                         ]
<.code>
Не могу разобраться что и откуда берется для 
<code>
//SVG element
        var myChart = d3.select(this.refs.chart).append("svg")
            .attr("width", width + margin.left + margin.right)
            .attr("height", height + margin.top + margin.bottom)
.selectAll("rect")
            .data(dataArray)
            .enter().append("rect")
            .style("fill", function (d) { return colors([d].number) })//Как здесь задать?
            .attr("width", xScale.rangeBand()-2 )
            .attr("height", function (d) { return yScale([d].number) })//Как здесь задать?
            .attr("x", function (d, i) { return xScale(i) })//Как здесь задать?
            .attr("y", height)//Как здесь задать?
</code>
Вот так все отлично работает если данные из аррея
<code>
.selectAll("rect")
            .data(dataArray)
            .enter().append("rect")
            .style("fill", function (d) { return colors(d) })
            .attr("width", xScale.rangeBand()-2 )
            .attr("height", function (d) { return yScale(d) })
            .attr("x", function (d, i) { return xScale(i) })
            .attr("y", height)
</code>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Novikov, 2016-04-28
@victorzadorozhnyy

And what for an array in an array from one element? You have no uniqueness here and you will either have to sort through them or choose the first value (d[0].number).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question