mirror of
https://github.com/discourse/discourse.git
synced 2024-12-19 06:56:30 +08:00
23b7b42acd
Changes for 4f7aba06c0
Also fixes all of the object-shorthand violations in our JS code.
60 lines
1.3 KiB
JavaScript
60 lines
1.3 KiB
JavaScript
import Component from "@ember/component";
|
|
import loadScript from "discourse/lib/load-script";
|
|
|
|
export default Component.extend({
|
|
tagName: "canvas",
|
|
type: "line",
|
|
|
|
refreshChart() {
|
|
const ctx = this.element.getContext("2d");
|
|
const model = this.model;
|
|
const rawData = this.get("model.data");
|
|
|
|
let data = {
|
|
labels: rawData.map((r) => r.x),
|
|
datasets: [
|
|
{
|
|
data: rawData.map((r) => r.y),
|
|
label: model.get("title"),
|
|
backgroundColor: `rgba(200,220,240,${this.type === "bar" ? 1 : 0.3})`,
|
|
borderColor: "#08C",
|
|
},
|
|
],
|
|
};
|
|
|
|
const config = {
|
|
type: this.type,
|
|
data,
|
|
options: {
|
|
responsive: true,
|
|
plugins: {
|
|
tooltip: {
|
|
callbacks: {
|
|
title: (context) =>
|
|
moment(context[0].label, "YYYY-MM-DD").format("LL"),
|
|
},
|
|
},
|
|
},
|
|
scales: {
|
|
y: [
|
|
{
|
|
display: true,
|
|
ticks: {
|
|
stepSize: 1,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
},
|
|
};
|
|
|
|
this._chart = new window.Chart(ctx, config);
|
|
},
|
|
|
|
didInsertElement() {
|
|
loadScript("/javascripts/Chart.min.js").then(() =>
|
|
this.refreshChart.apply(this)
|
|
);
|
|
},
|
|
});
|