Chart.js: Sort x-axis values. Category: Question

Created on 18 Oct 2017  路  4Comments  路  Source: chartjs/Chart.js

Expected Behavior

I have a simple line chart:

labels: [1.0, 3.0, 4.0]
datasets: [{
                label: "Track Plot",
                borderColor: 'rgb(255, 0, 0)',
                datata: [0.0, 2.0, 3.0]
              }]

When I try to add new point (2.0, 5.0) I expect that dataset will be modified in a such way:
labels: [1.0, 2.0, 3.0, 4.0] datata: [0.0, 5.0, 2.0, 3.0]. So x-axis stay sorted.

config.data.labels.push(2.0);
config.data.datasets[0].data.push(5.0);

Current Behavior



When I try to add new point (2.0, 5.0) the dataset is be modified in a such way:
labels: [1.0, 3.0, 4.0, 2.0] datata: [0.0, 2.0, 3.0, 5.0]. New point is appended to the end of the dataset.

Possible Solution


Is there any options to append new point between other points to make x-axis sorted?

Thanks,
Alina.

support

All 4 comments

@AlinaYablokova the category axis always renders the labels in the order they are given. If you need to have them sorted, you'll need to sort the labels and data before calling update()

Ok, thanks. I'm a bit confused by "category axis". Are there another types of axis?

@AlinaYablokova yes, there are linear, logarithmic, and time axes. The samples show them off

Please ask questions on StackOverflow: https://stackoverflow.com/questions/tagged/chart.js

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JAIOMP picture JAIOMP  路  3Comments

HeinPauwelyn picture HeinPauwelyn  路  3Comments

joebirkin picture joebirkin  路  3Comments

JewelsJLF picture JewelsJLF  路  3Comments

akashrajkn picture akashrajkn  路  3Comments