• 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;
        }
      </style>
    </head>
    
    <body>
      <div id="myChart"><a class="zc-ref" href="https://www.zingchart.com">Powered by ZingChart</a></div>
      <script>
        ZC.LICENSE = ["569d52cefae586f634c54f86dc99e6a9", "b55b025e438fa8a98e32482b5f768ff5"];
        var myConfig = {
          type: 'bar',
          title: {
            text: 'Dynamically Determine Bar Color'
          },
          subtitle: {
            text: 'Color Determined by Previous Value'
          },
          series: [{
            values: [35, 42, 67, 89, 25, 34, 67, 25]
          }]
        };
    
        // define colors to se
        var baseColor = '#64b5f6';
        var increaseColor = '#81c784';
        var decreaseColor = '#e57373';
    
        // function to loop through series
        function applyStyles(seriesArray) {
          // base stays blue
          var stylesArray = [baseColor];
    
          // loop through series objects (multiple plots is possible)
          seriesArray.forEach(function(seriesObj) {
            if (seriesObj && seriesObj.values) {
    
              // add a color for each node based on increase or decreased value
              var prevValue = seriesObj.values[0];
              for (var i = 1; i < seriesObj.values.length; i++) {
                if (seriesObj.values[i] > prevValue) {
                  stylesArray.push(increaseColor);
                } else {
                  stylesArray.push(decreaseColor);
                }
                prevValue = seriesObj.values[i];
              }
              seriesObj.styles = stylesArray;
            }
          });
        }
    
        // when data is ready apply the rules to the chart
        zingchart.bind('myChart', 'dataparse', function(e, oGraph) {
          if (oGraph && oGraph.graphset[0])
            applyStyles(oGraph.graphset[0].series);
    
          return oGraph;
        });
    
        zingchart.render({
          id: 'myChart',
          data: myConfig,
          height: '100%',
          width: '100%'
        });
      </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></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;
    }
    var myConfig = {
      type: 'bar',
      title: {
        text: 'Dynamically Determine Bar Color'
      },
      subtitle: {
        text: 'Color Determined by Previous Value'
      },
      series: [{
        values: [35, 42, 67, 89, 25, 34, 67, 25]
      }]
    };
    
    // define colors to se
    var baseColor = '#64b5f6';
    var increaseColor = '#81c784';
    var decreaseColor = '#e57373';
    
    // function to loop through series
    function applyStyles(seriesArray) {
      // base stays blue
      var stylesArray = [baseColor];
    
      // loop through series objects (multiple plots is possible)
      seriesArray.forEach(function(seriesObj) {
        if (seriesObj && seriesObj.values) {
    
          // add a color for each node based on increase or decreased value
          var prevValue = seriesObj.values[0];
          for (var i = 1; i < seriesObj.values.length; i++) {
            if (seriesObj.values[i] > prevValue) {
              stylesArray.push(increaseColor);
            } else {
              stylesArray.push(decreaseColor);
            }
            prevValue = seriesObj.values[i];
          }
          seriesObj.styles = stylesArray;
        }
      });
    }
    
    // when data is ready apply the rules to the chart
    zingchart.bind('myChart', 'dataparse', function(e, oGraph) {
      if (oGraph && oGraph.graphset[0])
        applyStyles(oGraph.graphset[0].series);
    
      return oGraph;
    });
    
    zingchart.render({
      id: 'myChart',
      data: myConfig,
      height: '100%',
      width: '100%'
    });