JavaScript
const FACTOR = 100
const randomScalingFactor = () => (Math.round(Math.random() * FACTOR))
const rsf = randomScalingFactor
const fakeData = [{
label: '2016-11-21',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}, {
label: '2016-11-22',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}, {
label: '2016-11-23',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}, {
label: '2016-11-29',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}, {
label: '2016-12-01',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}, {
label: '2016-12-02',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}, {
label: '2016-12-03',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}, {
label: '2016-12-04',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}, {
label: '2016-12-05',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}, {
label: '2016-12-08',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}, {
label: '2016-12-09',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}, {
label: '2016-12-12',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}, {
label: '2016-12-14',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}, {
label: '2016-12-15',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}, {
label: '2016-12-16',
negative: rsf(),
neutral: rsf(),
positive: rsf()
}]
const renderChart = (id) => {
const ctx = document.getElementById(id).getContext('2d')
const unit = id // day, week, month
console.log('ctx', ctx)
const data = {
labels: fakeData.map(({
label
}) => label),
datasets: [{
type: 'bar',
label: 'Negative',
backgroundColor: '#fa5151',
data: fakeData.map(({
negative
}) => negative),
}, {
type: 'bar',
label: 'Neutral',
backgroundColor: '#f8cc54',
data: fakeData.map(({
neutral
}) => neutral),
}, {
type: 'bar',
label: 'Positive',
...