retreival of x-axis value on a google chart getselection -


i use column chart. when clicking @ 1 of rows in diagram listener trigger event:

google.visualization.events.addlistener(chart, 'select', renderlist); 

i able retrieve number 2456 , not 6. number 6 value of first column. have 2 columns in table. can please me this? i've been struggling quite time.

this instantiation of chart:

<script type="text/javascript">      $("select").change(function () {         drawchart();      });          function drawchart() {             var inputdata = {                 rooms: $("#rooms").val(), area: $("#areas").val(), apartmenttype: $("#apartmenttype").val(),                 queue: $("#queue").val(), year: $("#years").val()             }             $.ajax({                 url: '@url.action("allocatedapartments", "statistics")',                 datatype: 'json',                 data: inputdata,                 type: 'post',                 success: function (data) {                     tdata = new google.visualization.datatable();                     tdata.addcolumn('number', 'antal bostäder');                     tdata.addcolumn('number', 'kötid');                     $.each(data.groupedlist, function (key, value) {                         tdata.addrow([value.queuetime, value.count])                     });                      var options = {                         title: 'förmedlade bostäder',                         backgroundcolor: "f1f1f1",                         colors: ['73a948'],                         legend: { "position": "none" },                         vaxis: { title: 'antal förmedlade bostäder', titletextstyle: { color: 'gray' } },                         haxis: { title: 'kötidsintervall (antal år)', titletextstyle: { color: 'gray' } }                     };                      chart = new google.visualization.columnchart(document.getelementbyid('chart_div'));                     chart.draw(tdata, options);                     google.visualization.events.addlistener(chart, 'select', renderlist);                 }             });         }  </script> 

in function renderlist want fetch label of row selected:

function renderlist() {     var selection = chart.getselection();     var value = tdata.getvalue(selection.row, selection.column );     alert(value)  $.ajax({     url: '@url.action("renderapartmentlist", "statistics")',     datatype: 'json',     type: 'post',     data: inputdata,     success: function (data) {         var html = mustache.to_html(template, data)         $("#mypartialviewcontainer").html(html);     },     error: function (xhr) {         alert("ett fel uppstod, var god försök igen om en liten stund.")     } }); 

}

for part of code

function renderlist() {     var selection = chart.getselection();     var value = tdata.getvalue(selection.row, selection.column );     alert(value)     ... 

you have receive error in console log:

uncaught error: invalid row index undefined. should in range [0-53].  

getselection() returns array. have change to:

    function renderlist() {         var selection = chart.getselection();         var value = tdata.getvalue(selection[0].row, selection[0].column ); 

see google docs about column chart: getselection() array of selection elements

and extended description of getselection()


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -