Chart.js vertically symmetrical chart - Javascript Chart.js

Javascript examples for Chart.js:Chart Configuration

Description

Chart.js vertically symmetrical chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.2.1/Chart.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){/*from   w w w.  ja v a 2s . co m*/
var ctx = document.getElementById('customer_chart').getContext('2d');
Chart.pluginService.register({
    beforeInit: function(chart) {
       // clones the dataset
       var newdataset = jQuery.extend(true, {}, chart.config.data.datasets[0]);
        chart.config.data.datasets[1] = newdataset;
        for (var i = 0; i < chart.config.data.datasets[1].data.length; i++) {
           // data * -1
           chart.config.data.datasets[1].data[i] *= -1;
        }
        chart.config.data.datasets[1].label = "";
    }
});
var chart = new Chart(ctx, {
    type: 'line',
    data: {
        labels: ['', 'Conference', 'Webinar', 'Trial'],
        datasets: [{
            label: 'Pipeline',
            lineTension: 0.3,
            data: [0, 10, 20, 15],
            backgroundColor: [
                'rgba(255, 99, 132, 0.2)',
            ],
            borderColor: [
                'rgba(255,99,132,1)',
            ],
        }],
    }
})
console.log(chart);
    }

      </script> 
   </head> 
   <body> 
      <script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script> 
      <canvas id="customer_chart" height="100"></canvas>  
   </body>
</html>

Related Tutorials