L'ultima sfida ha creato e aggiunto un rettangolo all'elemento `svg` per rappresentare ogni punto del `dataset` con una barra. Sfortunatamente, sono stati tutti impilati l'uno sull'altro.
Il posizionamento di un rettangolo è gestito dagli attributi `x` e `y`. Essi dicono a D3 dove iniziare a disegnare la forma nell'area `svg`. L'ultima sfida li ha impostati tutti a 0, quindi ogni barra è stata posizionata nell'angolo in alto a sinistra.
Per un grafico a barre, tutte le barre dovrebbero posionarsi allo stesso livello verticale, ciò significa che il valore `y` rimane lo stesso (a 0) per tutte le barre. Il valore `x`, tuttavia, deve cambiare quando si aggiungono nuove barre. Ricorda che valori `x` più grandi spingono gli oggetti più a destra. Mentre passi attraverso gli elementi dell'array in `dataset`, il valore `x` dovrebbe aumentare.
Il metodo `attr()` in D3 accetta una funzione di callback per impostare dinamicamente quell'attributo. La funzione di callback richiede due argomenti: uno per il punto dati stesso (solitamente `d`) e uno per l'indice del punto dati nell'array. Il secondo argomento per l'indice è opzionale. Ecco il formato:
È importante notare che NON è necessario scrivere un ciclo `for` o utilizzare `forEach()` per iterare sugli elementi del set di dati. Ricorda che il metodo `data()` analizza il set di dati, e qualsiasi metodo che viene concatenato dopo `data()` viene eseguito una volta per ciascun elemento del set di dati.
**Nota:** Ogni barra ha una larghezza di 25, quindi aumentare ogni valore `x` di 30 aggiunge dello spazio tra le barre. In questo esempio, qualsiasi valore superiore a 25 può andar bene.