0

This is different because as of 2016 this should have been fixed in inspector and as well the chart itself is not displaying correctly. again not a duplicate of the chrome inspector bug....

So i'm calling my endpoint with axios....

An example of the returned data is

 [
  {
    "report_name": "voltage", 
    "report_time": "Tue, 28 May 2019 19:04:38 GMT", 
    "report_value": 12.1726
  }, 
  {
    "report_name": "voltage", 
    "report_time": "Tue, 28 May 2019 19:04:43 GMT", 
    "report_value": 12.3142
  }, 
  {
    "report_name": "pumpstate", 
    "report_time": "Tue, 28 May 2019 19:14:59 GMT", 
    "report_value": 0.0
  }, 

I'm trying to reformat the array so that it works for the data in a scatter plot charts.js...

 mounted() {
    this.getData();
  },
  methods: {
    getData(){
      this.axios
        .get("http://192.168.1.103:2000/hydrodata/1", {
          params: {
          }
        })
        .then(response => {
          var voltages = []
          var statuses = []
          var newobj = {}

          response.data.forEach(function (item, index) {
            if(item.report_name == 'voltagea'){
              newobj['x']=randomScalingFactor()
              newobj['y']=item.report_value
              voltages.push(newobj)
            }
            if(item.report_name == 'pumpstate'){
              /////LINE 51
              console.log(item.report_value)
              /////LINE 52
              console.log(item.report_time)
              newobj['x']=randomScalingFactor()
              //newobj.x=item.report_time
              newobj['y']=item.report_value
               /////LINE 56
              console.log(newobj)
              statuses.push(newobj)
              /////LINE 58
              console.log(statuses)
            }
          });
          console.log(voltages)
          console.log(statuses)
          console.log(response.data)
        })
        .catch(error => {
          console.log(error);
          this.errored = true;
        })
    }

The function RandomScalingFactor is a function to set random X values for now what I'm seeing though is that my array is not being built correctly.

1                                  RandomChart.vue:51 
Tue, 28 May 2019 21:49:46 GMT      RandomChart.vue:52
{x: -68, y: 1}                    RandomChart.vue:56
 x: 79y: 0
 __proto__: Object

So the Console.log on 56 is showing something I don't understand. It is showing the "correct" object then wrong values underneath....

When I console log the entire array to a point.... after 18 loops then I get:

(18) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…},  {…}, {…}, {…}, {…}, {…}]         RandomChar.vue:58
0: {x: 79, y: 0}
1: {x: 79, y: 0}
2: {x: 79, y: 0}
3: {x: 79, y: 0}
4: {x: 79, y: 0}
5: {x: 79, y: 0}
.....
145: {x: 79, y: 0}
146:
   x: 79
   y: 0
   __proto__: Object
147: {x: 79, y: 0}
length: 148

But when I open the array it has a length of 148 .. just confused as to buiilding arrays in JS I think....

BostonMacOSX
  • 1,369
  • 2
  • 17
  • 38
  • 1
    this is not a duplicate of that issues....sorry it isn't...good to know but not a duplicate – BostonMacOSX May 30 '19 at 00:14
  • 1
    Move `var newobj = {}` inside your `forEach` function. Also read [Is JavaScript a pass-by-reference or pass-by-value language?](https://stackoverflow.com/questions/518000/is-javascript-a-pass-by-reference-or-pass-by-value-language) – Phil May 30 '19 at 01:09
  • Phil this gets me to the correct arrays......thanks.... – BostonMacOSX May 30 '19 at 12:18

0 Answers0