D3 Line Chart - custom sorting of the x-axis labels

34 views
Skip to first unread message

Janusz Twardziak

unread,
Apr 26, 2016, 4:22:38 AM4/26/16
to d3-js
Hello All!

Would you advise how to make D3 Line Chart to render x-axis labels within a custom sorting. 
For example, let's say I have the following data point to display:
X, Y
1, 10
2, 20
3, 10
4, 30
5, 60
6, 40
7, 30
8, 20
9, 10
10, 30
11, 30
12, 20

Now, I want the X labels to be shown in the following order: 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2 and draw corresponding Y points that eventually will form a line.
For some reasons, even when I pass through the pre-sorted array, D3 display labels in a ascending order. 

Many thanks in advance for your help.

Best regards,
Janusz

Curran

unread,
Apr 26, 2016, 1:14:13 PM4/26/16
to d3-js
Hello,

Using an ordinal scale for X and passing in the pre-sorted array to the domain of the scale should work.

Can you post a code example so we can see what might be going wrong?

Best regards,
Curran

Tito

unread,
Apr 26, 2016, 3:03:06 PM4/26/16
to d3-js
Reply all
Reply to author
Forward
0 new messages