SHARE
TWEET

Untitled

a guest Jun 17th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var colorpalette = ["red", "blue", "green", "magenta", "yellow", "brown", "purple", "orange", "black", "gray"];
  2. var currseriesnum = 0;
  3. var chart = null;
  4.  
  5. function setUpChart() {
  6.  
  7.     var ctx = document.getElementById('chartArea').getContext('2d');
  8.     chart = new Chart(ctx, {
  9.         type: 'line',
  10.         data: {
  11.             labels: monthnames,
  12.             datasets: [] // Initially blank - series added dynamically with chart.update()
  13.         },
  14.         options: {
  15.             legend: {
  16.                 display: false
  17.             },          
  18.             scales: {
  19.                 yAxes: [{
  20.                     ticks: {
  21.                         beginAtZero: true
  22.                     }
  23.                 }]
  24.             },
  25.             plugins: {  // ChartsJS DataLabels initialized here
  26.                 datalabels: {
  27.                     anchor: 'end',
  28.                     align: 'bottom',
  29.                     formatter: Math.round,
  30.                     font: {
  31.                       weight: 'bold',
  32.                       size: 16
  33.                     },
  34.                     color: colorpalette[currseriesnum] // Pick color dynamically
  35.                 }
  36.             }          
  37.         }
  38.     });    
  39.  
  40. }
  41.      
  42. chart.data.datasets.push({
  43.     label: keyValueSelection.label,
  44.     fill: false,
  45.     data: keyValueSelection.value,
  46.     borderColor: colorpalette[currseriesnum],
  47.     borderWidth: 2
  48. });
  49. chart.update();
  50. currseriesnum++;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top