Hello.

Iam a js beginner and i try to sort the values in my bar chart.
The problem is... the values are not sorted correctly:

[image: Clipboard01.jpg]


What i found is this post:
https://stackoverflow.com/questions/46544894/sorting-google-bar-chart

So i should convert the "strings" into numbers.
How does it work if I have the data in a json file?
Could someone give me an example?




My code:
google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawBasic1);


var options_gen1 = {
        chartArea: {top:10,left:0, width: '90%', height: '90%'},
        legend: {position: 'none'},
        hAxis: {minValue: 0,minorGridlines: {count:0},gridlines: {color: 
'#962d34'} ,textStyle:{color: '#962d34'}},
        backgroundColor: 'none',
        height: 400


};


function drawBasic1() {


          var main = $.ajax({
          url: "jsondata/mainraid_T.json",
          dataType: "json",
          async: false
          }).responseText;



var data1 = new google.visualization.DataTable(main);


     var formatter = new google.visualization.NumberFormat(
         {negativeColor: 'red', negativeParens: true, pattern: '#dps'});
        formatter.format(data1, 1);


var chart1 = new google.visualization.BarChart(document.getElementById('T'
));
data1.sort({column: 1, desc: true});
chart1.draw(data1, options_gen1);



jsondata:
{
"iterations":"10000",
"SIMTYPE":"LightMovement",

        "cols": [
                {"label":"Player","type":"string"},
                {"label":"mean","type":"number"},
                {"id":"","role":"style","type":"string"},
                {"id":"","role":"annotation","type":"string"}
                ],

        "rows": [
{"c":[{"v":"Schleier"},{"v":"22969.18812833047"},{"v":"#FFF569"},{"v":"Schleier"}]}
,
{"c":[{"v":"Garddòx"},{"v":"21910.629135718737"},{"v":"#A330C9"},{"v":"Garddòx"}]}
,
{"c":[{"v":"Blistersun"},{"v":"24654.787974549316"},{"v":"#ABD473"},{"v":"Blistersun"}]}
,
{"c":[{"v":"Obelion"},{"v":"20638.17902879232"},{"v":"#9482C9"},{"v":"Obelion"}]}
,
{"c":[{"v":"Dunelio"},{"v":"20409.33454964565"},{"v":"#FFFFFF"},{"v":"Dunelio"}]}
,
{"c":[{"v":"Para"},{"v":"24161.06241636201"},{"v":"#C79C6E"},{"v":"Para"}]}
,
{"c":[{"v":"Heranimuz"},{"v":"23162.95430922641"},{"v":"#69CCF0"},{"v":"Heranimuz"}]}
]}



-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/749be98b-38f8-4eb4-914c-3627292e3b9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to