Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I update the graph with fetched data? #17

Closed
ms042087 opened this issue Oct 2, 2019 · 2 comments
Closed

How can I update the graph with fetched data? #17

ms042087 opened this issue Oct 2, 2019 · 2 comments

Comments

@ms042087
Copy link

ms042087 commented Oct 2, 2019

I use the following code and it doesn't work for me.

              setInterval(function() {
                y = 0
                fetch("**url**", {
                  method: "GET",
                  headers: {
                  'Content-Type': 'application/json; charset=utf-8',
                  "Connection": "close",  
                  }
                })
                  .then(respone => respone.json())
                  .then(res => {
                      y = parseFloat(res[0].Value)
                    })
                  .catch(error => {
                    y = 0
                  });
                series.addPoint(y, true, true);
              }, 2000);

The fetch process seems to be ignored and only gives y = 0.

@ms042087
Copy link
Author

ms042087 commented Oct 9, 2019

More information here.
I finally can update the chart with fetched data.
The chart shows 1 minute data which consists of 1200 points.
I update the chart by putting the function in setInterval in componentDidMount().

Result:
The chart can be updated as usual, but stop updating around 1.5 minute later. It gives no error message.

  componentDidMount(){
    setInterval(this._loadChartData,updateInterval);
  }
 _loadChartData() {
    result = {};
    url = "xxx";
    fetch(url, {
      method: "GET",
      headers: {
      'Content-Type': 'application/json; charset=utf-8',
      "Connection": "close",  
      }
    })
      .then(respone => respone.json())
      .then(res => {
          result = res[0].minute
          this.setState({
            chartOptions: {
              series: [
                {
                  data: result.slice(Math.max(result.length - numberOfPoint, 0)),
                  type: "area",
                  pointStart: new Date - 60000,
                  pointInterval: 1000*60/1200 
                }
              ]
            }
        });

          return (result)
        })
      .catch(error => {
        console.log(error);
        return (0)
      });
  }

@ms042087 ms042087 closed this as completed Oct 9, 2019
@sebastianbochan
Copy link
Contributor

Regarding to update, in the wrapper I used webkit.postmessage and event to cache it. At this moment it was removed from webview and is still developed / reorganized.

Ref:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants