I'm using google line chart to plot data by timestamp(x-axis).
my problem is that the x-axis is not being sorted automatically by the google charting.
e.g. "15:45:23 678" data point which should be the first in the chart is being shown at #2. If I put it at the first place then it is fine. That means Google chart doesn't care about the data and it plots as it sees them.
The issue is that my data set is huge and sorting it based on x-axis data takes lot of time. is there any flag in the line chart which could sort it in the browser?
below is the sample data:
['x', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6'],
['15:48:13 744', 0, 0, 0, 0, 0, 0],
['15:45:23 678', 5, 17, 36, 3957, 20, 21],
['15:48:18 749', 0, 0, 0, 0, 0, 0]
Alphabetize your dataFrom the Google Sheets menu, select Data and click Sort range. A window will prompt you to choose the column you want to sort; you can choose the A–Z option to quickly alphabetize your selection.
Click Data and select Sort range from the drop-down menu. The Sorting dialog box appears. Select the desired column you want to sort by. Select ascending or descending.
You can use the following function to sort the underlying DataTable:data.sort([{column: 0}]);
.
Column 0 indicates the x-axis.
This will sort the data in asc order, for desc use data.sort([{column: 0, desc: true}]);
You may also be interested in the getSortedRows(sortColumns)
function.
More information about these functions can be read about here
https://developers.google.com/chart/interactive/docs/reference#DataTable_sort
https://developers.google.com/chart/interactive/docs/reference#DataTable_getSortedRows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With