question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How essential is it for C3 to sort the x axis list?

See original GitHub issue

Plotting experience from Python/Matplotlib, R, Matlab, Excel, etc., suggests that the ordering of the x values of a plot is important, i.e., if you use a non-sorted list of for your x axis and ask for a line plot, you’ll get a jagged line. C3.js doesn’t do this: it’ll sort the x-axis data before drawing a “normal-looking” (but unexpected, and in some cases, incorrect) plot.

How important is this decision to C3’s design? Can it be relaxed by a user-settable parameter?

var chart = c3.generate({
    bindto : '#ch',
    data : {
        x : 'x',
        rows : [
            [ 'x', 'data1', 'data2' ],
            [ 11, 120, 300 ],
            [ 22, 160, 240 ],
            [ -33, 200, 290 ], // <----- note shuffled x point
            [ 44, 160, 230 ],
            [ 55, 130, 300 ],
        ]
    }
});

Background: I’m using tooltip.contents and a non-sorted list for x in a scatter plot, and have to create a lookup object to transform the x values to indexes just for this. The x list can’t be stored sorted because it indexes many other lists.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
masayuki0812commented, Sep 9, 2014

Hi, Thank you for the feedback and the discussion. I added data.xSort option to determine whether the data will be sorted or not by x values.

Now you can do that by setting this option false, then the sort will be skipped and the order of the data will be maintained. Than, you can access the element of unsorted data by the index obtained from data in tooltip.content. Could you try the latest code? Thanks.

0reactions
OttoGcommented, Nov 29, 2018

@shafiquejamal it works for me with version 0.4.11. Setting <c3 chart object>.data.xSort = false solved a problem similar to the one described by the original poster. The dots keep their index numbers from the supplied data set (and the corresponding drawing order is respected) regardless of their x values.

That version is rather old, though. Perhaps the functionality has become broken in later versions?

Read more comments on GitHub >

github_iconTop Results From Across the Web

C3.js x-axis show every other categories - Stack Overflow
If you wanted every 5th tick to show and had 100 ticks in total, you'd set the value of max to be equal...
Read more >
Re: Sort by expression whatever the selection - Qlik Community
I only sort by expression ascending, State is not checked. It works fine if I have no selection. If I filter on C3,...
Read more >
Customizing Axes in D3.js - Glenn Henshaw
We will make a horizontal axis and customize it in different ways using D3 methods and CSS selections. First I'll show you how...
Read more >
Changing the order of the x axis in Power BI - YouTube
When Power BI decides on the order of the columns in a visualisation it only knows about numeric order or alphabetical order.
Read more >
Combining Datasets: Concat and Append
The first argument is a list or tuple of arrays to concatenate. Additionally, it takes an ... x = [[1, 2], [3, 4]]...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found