ZingCharts feed example code cannot display a chart

I am new to ZingChart. I follow this guide here http://www.zingchart.com/docs/features/feeds/#feeds__js

I wrote an html file ZingFeed.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<script>

var chartData={"refresh":{
    "type":"feed",
    "transport":"js",
    "url":"feed()",
    "interval":200
};


window.onload=function(){
    zingchart.render({
        id:"chartDiv",
        data:chartData,
        height:600,
        width:"100%"
    });
};

window.feed = function(callback) {
    var tick = {};
    tick.plot0 = parseInt(10+900*Math.random(), 10);
    callback(JSON.stringify(tick));
};

</script>
<div id='chartDiv'></div>
</body>
</html>

Nothing is displayed on the screen. Your help will be very helpful and much appreciated.

+4
source share
1 answer

First: do you download the ZingChart library? I just ask, as it is not included in your demo. If not, paste this into <head>our file:

<script src='http://cdn.zingchart.com/zingchart.min.js'></script>

Your object is chartDataalso missing a type.

Your chartDataobject also lacks a missing closing bracket.

. ZingChart. , - .

<!DOCTYPE html>
<html>

<head>
    <meta charset="ISO-8859-1">
    <title>Insert title here</title>
    <script src='http://cdn.zingchart.com/zingchart.min.js'></script>
</head>

<body>
    <script>
    var chartData = {
        "type":"line",
        "refresh": {
            "type": "feed",
            "transport": "js",
            "url": "feed()",
            "interval": 200
        },
        "series":[
            {
                "values":[]
            }
        ]
    };


    window.onload = function() {
        zingchart.render({
            id: "chartDiv",
            data: chartData,
            height: 600,
            width: "100%"
        });
    };

    window.feed = function(callback) {
        var tick = {};
        tick.plot0 = parseInt(10 + 900 * Math.random(), 10);
        callback(JSON.stringify(tick));
    };
    </script>
    <div id='chartDiv'></div>
</body>

</html>
Hide result
+4

Source: https://habr.com/ru/post/1584231/


All Articles