neptune/core/static/chart.js

48 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2022-07-21 12:50:51 +00:00
function loadJson(selector) {
return JSON.parse(document.querySelector(selector).getAttribute('data-json'));
2022-07-21 12:51:01 +00:00
}
2022-07-21 12:50:51 +00:00
var jsonData = loadJson('#jsonData');
2022-07-21 12:51:01 +00:00
var full_data = jsonData.map((item) => item);
2022-07-21 12:50:51 +00:00
var ctx = document.getElementById('sentiment-chart').getContext("2d");
2022-07-21 12:51:01 +00:00
new Chart(ctx, {
type: 'line',
data: {
datasets: [
{
label: "Sentiment",
fill: false,
backgroundColor: 'black',
borderColor: 'lightblue',
tension: 0.3,
data: full_data,
spanGaps: true,
}
],
2022-07-21 12:50:51 +00:00
},
options: {
responsive: true,
maintainAspectRatio: false,
parsing: {
xAxisKey: 'date',
yAxisKey: 'value',
},
plugins: {
tooltip: {
callbacks: {
footer: function(context) {
var foot = "Text: " + full_data[context[0].dataIndex].text + "\n";
foot += "Nick: " + full_data[context[0].dataIndex].nick + "\n";
foot += "Channel: " + full_data[context[0].dataIndex].channel + "\n";
foot += "Net: " + full_data[context[0].dataIndex].net;
return foot;
}
}
},
legend: {
display: false,
},
2022-07-21 12:51:01 +00:00
}
2022-07-21 12:50:51 +00:00
}
2022-07-21 12:51:01 +00:00
});