Problem with adding data(variables)

25 views
Skip to first unread message

Mario D

unread,
Jun 6, 2019, 5:40:15 PM6/6/19
to Google Visualization API
HELLO im drawing a google line chart and it is working with only one variable/line with a name zadnjiBroj, i want to add 2 more variables into chart, 2 more lines named zadnjiBrojy and zadnjiBrojz that will work on the same graph. Can anyone help me to implement that 2 more lines?

There is a code:

google
.charts.load('current', {'packages':['corechart']});
var numbersFromLabView = [];
var time = [];



$
('.viewbutton').click(function() {
 
// Zovi api poziv i dohvati podatke svako 2 sec
  $
('#portfolio').addClass('hidden');
  $
('#element-di-zivi-aplikacija').removeClass('hidden');
  setInterval
(getDataFromLabView, 2000);
});


function getDataFromLabView() {
 
var jsonData = $.ajax({
    url
: 'projectXHTTP',
    dataType
: 'json',
    success
: function (jsonArray) {
     
     
var zadnjiBroj = jsonArray.slice(0,1).pop();
     
var zadnjiBrojy = jsonArray.slice(0,2).pop();
     
var zadnjiBrojz = jsonArray.slice(0,3).pop();
   
      drawChart
(zadnjiBroj);
   
   
      $
(document.querySelector('.current-number')).text(zadnjiBroj);
      $
(document.querySelector('.current-numbery')).text(zadnjiBrojy);
      $
(document.querySelector('.current-numberz')).text(zadnjiBrojz);
 
   
}
 
});
}


function drawChart(number) {
 
var data = new google.visualization.DataTable();
 
  moment
.locale('hr');
  time
.push(moment());
  numbersFromLabView
.push(number);


 
// kako ce se zvati x i y osi na grafu
  data
.addColumn('string', 'Time of Day');
  data
.addColumn('number', 'Current');
 


  numbersFromLabView
.forEach((number, key) =>  {
   
// za svaki broj koji dohvati ubaci njega i vrijeme u data Objekt
    data
.addRow([time[key].format('LTS'), number]);
 
});


 
// stilovi i izgled grafa se ovdje definiraju
 
var options = {
    background
: 'transparent',
    title
: 'Numeric values from LabView on time scale',
    height
: 500,
    width
: '100%',
    hAxis
: {
      title
: 'Vrijeme',
   
},
    vAxis
: {
      title
: 'I',
     
   
}
 
}


 
 
var chart = new google.visualization.LineChart(document.querySelector('#chart_div'));
 
 
  chart
.draw(data, options);
}

Mario D

unread,
Jun 7, 2019, 6:25:10 AM6/7/19
to Google Visualization API
Heeeeelp
Reply all
Reply to author
Forward
0 new messages