neptune/core/static/chart.js

44 lines
1002 B
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
2022-07-21 12:51:01 +00:00
var ctx = document.getElementById('volume').getContext("2d");
new Chart(ctx, {
type: 'line',
data: {
2022-07-21 12:50:51 +00:00
datasets: [
2022-07-21 12:51:01 +00:00
{
label: "Sentiment",
fill: false,
2022-07-21 12:50:51 +00:00
backgroundColor: 'black',
borderColor: 'lightblue',
2022-07-21 12:51:01 +00:00
tension: 0.3,
data: full_data,
spanGaps: true,
}
],
},
options: {
2022-07-21 12:51:22 +00:00
responsive: true,
maintainAspectRatio: false,
2022-07-21 12:51:01 +00:00
parsing: {
xAxisKey: 'date',
yAxisKey: 'value',
2022-07-21 12:50:51 +00:00
},
2022-07-21 12:51:01 +00:00
plugins: {
tooltip: {
callbacks: {
beforeFooter: function(context) {
return "Nick: " + full_data[context[0].dataIndex].nick;
},
footer: function(context) {
return "Msg: " + full_data[context[0].dataIndex].text;
}
}
}
2022-07-21 12:50:51 +00:00
}
2022-07-21 12:51:01 +00:00
}
});