SHARE
TWEET

Untitled

a guest Feb 19th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var source = new carto.source.SQL('select * from ticketspercounty_copy');
  2. var histogram = new carto.dataview.Histogram(source, 'ticketcount',{bins: 46});
  3. histogram.on('dataChanged', (data) => {
  4.        //console.log(data)
  5.  
  6.          let chart = new Chart(histo, {
  7.            type: "bar",
  8.            data: {
  9.              labels: ['Abbeville',
  10.                       'Charleston',
  11.                       'York',
  12.                     ],
  13.              datasets: [
  14.                {
  15.                  data: data.bins.map(element => element.freq)
  16.                }
  17.              ]
  18.            }
  19.          });
  20.        });
  21.       // Add the histogram to the client
  22.       client.addDataview(histogram);
  23.      
  24. const histogramDataview = new carto.dataview.Histogram(source, 'pop2005', {bins: 10});
  25.  
  26.   const histogramElement = document.getElementById('chart');   const histoChart = new Chart(histogramElement, {
  27.     type: "bar",
  28.     data: {
  29.       datasets: [{
  30.         label: 'Frequency',
  31.         data: [],
  32.         backgroundColor: [
  33.           '#fcde9c','#faa476','#f0746e','#e34f6f','#dc3977','#b9257a','#7c1d6f'
  34.         ]
  35.         }]
  36.       }
  37.     });
  38.  
  39.   client.addDataview(histogramDataview);
  40.  
  41.   histogramDataview.on('dataChanged', (data) => {
  42.     histoChart.data.labels = data.bins.map(x => `${x.start} to ${x.end}`);
  43.     histoChart.data.datasets.forEach((dataset) => {
  44.         dataset.data = data.bins.map(x => x.freq);
  45.     });
  46.     histoChart.update();   });
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