• Edit
  • Download
  • <!DOCTYPE html>
    <html>
    
    <head>
      <meta charset="utf-8">
      <title>ZingSoft Demo</title>
    
      <script src="https://cdn.zingchart.com/zingchart.min.js"></script>
      <style>
        html,
        body {
          height: 100%;
          width: 100%;
          margin: 0;
          padding: 0;
        }
    
        #myChart {
          height: 100%;
          width: 100%;
          min-height: 150px;
        }
    
        .zc-ref {
          display: none;
        }
    
        #myChart button {
          position: absolute;
          top: 15px;
          left: 10px;
          z-index: 1000;
        }
      </style>
    </head>
    
    <body>
      <div id="myChart">
        <a class="zc-ref" href="https://www.zingchart.com">Powered by ZingChart</a>
        <button onclick="window.parent.location.reload()">Reload Data</button>
      </div>
      <script>
        ZC.LICENSE = ["569d52cefae586f634c54f86dc99e6a9", "b55b025e438fa8a98e32482b5f768ff5"]; // make the AJAX request
        var oReq = new XMLHttpRequest();
        oReq.addEventListener("load", renderFirstPlotInChart);
        oReq.open("GET", "https://zingchart-rest-api.glitch.me/api/data/plot/v1");
        oReq.send();
    
        // define chart JSON
        var myConfig = {
          type: 'bar',
          title: {
            text: 'Multiple Plots Rendering Asynchronously Using API',
            mediaRules: [{
              maxWidth: 500,
              visible: false
            }]
          },
          plot: {
            // barWidth: 25, // this will prevent users from noticing the barwidth changing
            animation: {}, // add animation to make the chart look alive
          },
          legend: {},
          scaleY: {
            values: '0:300:100' // this will prevent users from noticing the scale repaint
          },
          series: [{
            values: [],
            text: '',
          }]
        };
    
        /*
         * callback for GET request is when we will render the chart
         */
        function renderFirstPlotInChart() {
          myConfig.series[0].values = JSON.parse(this.responseText);
          myConfig.series[0].text = this.responseURL.slice(-2);
          zingchart.render({
            id: 'myChart',
            data: myConfig,
            height: '100%',
            width: '100%'
          });
        }
    
        /*
         * append the plots using ZingChart API method addplot
         * https://www.zingchart.com/docs/api/methods/#zingchart__exec__api__addplot
         */
        function addAnotherPlot() {
          zingchart.exec('myChart', 'addplot', {
            data: {
              values: JSON.parse(this.responseText),
              text: this.responseURL.slice(-2)
            }
          });
        }
        /*
         * Bind plots after the chart has rendered
         */
        zingchart.bind('myChart', 'load', function(e) {
    
          /*
           * make AJAX request for the last two plots
           * Use setTimeouts to show what the effect
           * would look like when using large dataset
           */
          setTimeout(function() {
    
            // call for second dataset
            oReq = new XMLHttpRequest();
            oReq.addEventListener("load", addAnotherPlot);
            oReq.open("GET", "https://zingchart-rest-api.glitch.me/api/data/plot/v2");
            oReq.send();
    
            // call for third dataset
            setTimeout(function() {
              oReq = new XMLHttpRequest();
              oReq.addEventListener("load", addAnotherPlot);
              oReq.open("GET", "https://zingchart-rest-api.glitch.me/api/data/plot/v3");
              oReq.send();
            }, 1000);
    
          }, 2000);
        });
      </script>
    </body>
    
    </html>
    <!DOCTYPE html>
    <html>
    
    <head>
      <meta charset="utf-8">
      <title>ZingSoft Demo</title>
    
      <script src="https://cdn.zingchart.com/zingchart.min.js"></script>
    </head>
    
    <body>
      <div id="myChart">
        <a class="zc-ref" href="https://www.zingchart.com">Powered by ZingChart</a>
        <button onclick="window.parent.location.reload()">Reload Data</button>
      </div>
    </body>
    
    </html>
    html,
    body {
      height: 100%;
      width: 100%;
      margin: 0;
      padding: 0;
    }
    
    #myChart {
      height: 100%;
      width: 100%;
      min-height: 150px;
    }
    
    .zc-ref {
      display: none;
    }
    
    #myChart button {
      position: absolute;
      top: 15px;
      left: 10px;
      z-index: 1000;
    }
    // make the AJAX request
    var oReq = new XMLHttpRequest();
    oReq.addEventListener("load", renderFirstPlotInChart);
    oReq.open("GET", "https://zingchart-rest-api.glitch.me/api/data/plot/v1");
    oReq.send();
    
    // define chart JSON
    var myConfig = {
      type: 'bar',
      title: {
        text: 'Multiple Plots Rendering Asynchronously Using API',
        mediaRules: [{
          maxWidth: 500,
          visible: false
        }]
      },
      plot: {
        // barWidth: 25, // this will prevent users from noticing the barwidth changing
        animation: {}, // add animation to make the chart look alive
      },
      legend: {},
      scaleY: {
        values: '0:300:100' // this will prevent users from noticing the scale repaint
      },
      series: [{
        values: [],
        text: '',
      }]
    };
    
    /*
     * callback for GET request is when we will render the chart
     */
    function renderFirstPlotInChart() {
      myConfig.series[0].values = JSON.parse(this.responseText);
      myConfig.series[0].text = this.responseURL.slice(-2);
      zingchart.render({
        id: 'myChart',
        data: myConfig,
        height: '100%',
        width: '100%'
      });
    }
    
    /*
     * append the plots using ZingChart API method addplot
     * https://www.zingchart.com/docs/api/methods/#zingchart__exec__api__addplot
     */
    function addAnotherPlot() {
      zingchart.exec('myChart', 'addplot', {
        data: {
          values: JSON.parse(this.responseText),
          text: this.responseURL.slice(-2)
        }
      });
    }
    /*
     * Bind plots after the chart has rendered
     */
    zingchart.bind('myChart', 'load', function(e) {
    
      /*
       * make AJAX request for the last two plots
       * Use setTimeouts to show what the effect
       * would look like when using large dataset
       */
      setTimeout(function() {
    
        // call for second dataset
        oReq = new XMLHttpRequest();
        oReq.addEventListener("load", addAnotherPlot);
        oReq.open("GET", "https://zingchart-rest-api.glitch.me/api/data/plot/v2");
        oReq.send();
    
        // call for third dataset
        setTimeout(function() {
          oReq = new XMLHttpRequest();
          oReq.addEventListener("load", addAnotherPlot);
          oReq.open("GET", "https://zingchart-rest-api.glitch.me/api/data/plot/v3");
          oReq.send();
        }, 1000);
    
      }, 2000);
    });