0

I'm using zingchart gauges in my code. My problem is that I can't change the gauge value dynamically.

I'm getting this error:

Cannot set property 'values' of undefined

I'm using flask API. How can I change this variable value with flask API? Do you have any idea what can I use for dynamic gauge?

function fetchData() {
  $.ajax({
    url: "api/read",
    method: "GET",
    success: function(data, status, xhr) {
      //var array = data.split(",").map(Number);
      a = JSON.parse(data);
      $('#myChart').series.values = 20;
      //console.log(a);                            
    },
    error: function(xhr, status, error) {
      $("#dataHeader").html("Error: \n" + error);
    }
  });
}

var myConfig4 = {
  "type": "gauge",
  "scale-r": {
    "aperture": 200,
    "values": "0:100:10",
    "center": { //Pivot Point
      "size": 6,
      "background-color": "#66CCFF #FFCCFF",
      "border-color": "#000000"
    }
  },
  "plot": {
    "csize": "5%",
    "size": "85%",
    "background-color": "#000000"
  },
  "series": [{
    "values": [] // i need to change this value
  }]
};

zingchart.render({
  id: 'myChart',
  data: myConfig4,
  height: "75%",
  width: "75%"
});

setInterval(fetchData, 1000);
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • `$('#myChart').series` is `undefined`. Check that you're using that property correctly in the gauge documentation – Rory McCrossan Dec 27 '18 at 12:02
  • Also, why bother making the AJAX requests yourself when you can use the `feed` functionality of the chart to do this for you? https://www.zingchart.com/docs/api/methods/#zingchart__exec__api__feed – Rory McCrossan Dec 27 '18 at 12:06

1 Answers1

1

you can use setseriesvalues and use array as value.

success: function(data, status, xhr) {
  a = JSON.parse(data);
  zingchart.exec('myChart', 'setseriesvalues', {
    plotindex: 0,
    'values': [20]
  });
  //console.log(a);                            
}
ewwink
  • 18,382
  • 2
  • 44
  • 54