mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FEATURE: add graph support to admin reports
thanks to graph js, this runs latest beta cause we needed support for smarter X axis legend
This commit is contained in:
parent
46487f095e
commit
4bc860652b
6 changed files with 86 additions and 18 deletions
43
app/assets/javascripts/admin/components/admin-graph.js.es6
Normal file
43
app/assets/javascripts/admin/components/admin-graph.js.es6
Normal file
|
@ -0,0 +1,43 @@
|
|||
import loadScript from 'discourse/lib/load-script';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
tagName: 'canvas',
|
||||
|
||||
refreshChart(){
|
||||
const ctx = this.$()[0].getContext("2d");
|
||||
const model = this.get("model");
|
||||
const rawData = this.get("model.data");
|
||||
|
||||
var data = {
|
||||
labels: rawData.map(r => r.x),
|
||||
datasets: [{
|
||||
data: rawData.map(r => r.y),
|
||||
label: model.get('title'),
|
||||
backgroundColor: "rgba(200,220,240,0.3)",
|
||||
borderColor: "#08C"
|
||||
}]
|
||||
};
|
||||
|
||||
const config = {
|
||||
type: 'line',
|
||||
data: data,
|
||||
options: {
|
||||
responsive: true,
|
||||
scales: {
|
||||
yAxes: [{
|
||||
display: true,
|
||||
ticks: {
|
||||
suggestedMin: 0
|
||||
}
|
||||
}]
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
this._chart = new Chart(ctx, config);
|
||||
},
|
||||
|
||||
didInsertElement(){
|
||||
loadScript("/javascripts/Chart.min.js").then(() => this.refreshChart.apply(this));
|
||||
}
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue