Implement graphs properly
This commit is contained in:
34
core/static/chart.js
Normal file
34
core/static/chart.js
Normal file
@@ -0,0 +1,34 @@
|
||||
function loadJson(selector) {
|
||||
return JSON.parse(document.querySelector(selector).getAttribute('data-json'));
|
||||
}
|
||||
|
||||
|
||||
var jsonData = loadJson('#jsonData');
|
||||
var data = jsonData.map((item) => item.value);
|
||||
var labels = jsonData.map((item) => item.date);
|
||||
|
||||
var config = {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: labels,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Sentiment',
|
||||
backgroundColor: 'black',
|
||||
borderColor: 'lightblue',
|
||||
data: data,
|
||||
fill: false
|
||||
}
|
||||
]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
|
||||
}
|
||||
}
|
||||
var element = document.getElementById('volume');
|
||||
element.removeAttribute("height");
|
||||
element.removeAttribute("width");
|
||||
|
||||
var ctx = document.getElementById('volume').getContext('2d');
|
||||
new Chart(ctx, config);
|
||||
Reference in New Issue
Block a user