Files
discourse/app/assets/javascripts/admin/components/admin-graph.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.2 KiB
JavaScript
Raw Normal View History

import Component from "@ember/component";
2016-04-14 15:46:01 +10:00
import loadScript from "discourse/lib/load-script";
export default Component.extend({
2016-04-14 15:46:01 +10:00
tagName: "canvas",
type: "line",
2016-04-14 15:46:01 +10:00
refreshChart() {
2019-07-16 12:45:15 +02:00
const ctx = this.element.getContext("2d");
const model = this.model;
2016-04-14 15:46:01 +10:00
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,${this.type === "bar" ? 1 : 0.3})`,
2016-04-14 15:46:01 +10:00
borderColor: "#08C",
},
],
};
const config = {
type: this.type,
2016-04-14 15:46:01 +10:00
data: data,
options: {
responsive: true,
tooltips: {
callbacks: {
title: (context) =>
moment(context[0].xLabel, "YYYY-MM-DD").format("LL"),
},
},
2016-04-14 15:46:01 +10:00
scales: {
yAxes: [
{
display: true,
ticks: {
2019-03-29 12:14:11 +08:00
stepSize: 1,
2018-06-15 17:03:24 +02:00
},
2016-04-14 15:46:01 +10:00
},
],
},
},
};
2016-04-14 16:30:04 +10:00
this._chart = new window.Chart(ctx, config);
2016-04-14 15:46:01 +10:00
},
didInsertElement() {
loadScript("/javascripts/Chart.min.js").then(() =>
this.refreshChart.apply(this)
);
},
2016-04-14 16:30:04 +10:00
});