Skip to content

Commit

Permalink
feat: optimize chartjs
Browse files Browse the repository at this point in the history
  • Loading branch information
杨国璇 authored and 杨国璇 committed Oct 17, 2024
1 parent 2d22723 commit 18ba12f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 19 deletions.
42 changes: 32 additions & 10 deletions frontend/src/pages/org-admin/statistic/statistic-chart.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
import React from 'react';
import {
Chart as ChartJS,
CategoryScale,
LinearScale,
PointElement,
LineElement,
Title,
Tooltip,
Legend,
} from 'chart.js';
import { Line } from 'react-chartjs-2';
import PropTypes from 'prop-types';
import { Utils } from '../../../utils/utils';
import Loading from '../../../components/loading';

ChartJS.register(
CategoryScale,
LinearScale,
PointElement,
LineElement,
Title,
Tooltip,
Legend
);

const propTypes = {
labels: PropTypes.array.isRequired,
Expand All @@ -19,7 +40,7 @@ class StatisticChart extends React.Component {
super(props);
this.state = {
data: {},
opations: {}
options: {}
};
}

Expand Down Expand Up @@ -65,10 +86,10 @@ class StatisticChart extends React.Component {
}
},
scales: {
yAxes: [{
y: [{
beginAtZero: true,
suggestedMax: suggestedMaxNumbers,
ticks: {
beginAtZero: true,
suggestedMax: suggestedMaxNumbers,
callback: function (value, index, values) {
if (isTicksCallback) {
return _this.ticksCallback(value, index, values);
Expand All @@ -77,7 +98,7 @@ class StatisticChart extends React.Component {
}
}
}],
xAxes: [{
x: [{
ticks: {
maxTicksLimit: 20
}
Expand Down Expand Up @@ -107,13 +128,14 @@ class StatisticChart extends React.Component {
};

render() {

let { data, options } = this.state;
if (Object.keys(data).length === 0 && Object.keys(options).length === 0) {
return <Loading />;
}
return (
<Line
data={data}
options={options}
/>
<>
<Line data={data} options={options} />
</>
);
}
}
Expand Down
41 changes: 32 additions & 9 deletions frontend/src/pages/sys-admin/statistic/statistic-chart.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
import React from 'react';
import {
Chart as ChartJS,
CategoryScale,
LinearScale,
PointElement,
LineElement,
Title,
Tooltip,
Legend,
} from 'chart.js';
import { Line } from 'react-chartjs-2';
import PropTypes from 'prop-types';
import { Utils } from '../../../utils/utils';
import Loading from '../../../components/loading';

ChartJS.register(
CategoryScale,
LinearScale,
PointElement,
LineElement,
Title,
Tooltip,
Legend
);

const propTypes = {
labels: PropTypes.array.isRequired,
Expand All @@ -19,7 +40,7 @@ class StatisticChart extends React.Component {
super(props);
this.state = {
data: {},
opations: {}
options: {}
};
}

Expand Down Expand Up @@ -65,10 +86,10 @@ class StatisticChart extends React.Component {
}
},
scales: {
yAxes: [{
y: [{
beginAtZero: true,
suggestedMax: suggestedMaxNumbers,
ticks: {
beginAtZero: true,
suggestedMax: suggestedMaxNumbers,
callback: function (value, index, values) {
if (isTicksCallback) {
return _this.ticksCallback(value, index, values);
Expand All @@ -77,7 +98,7 @@ class StatisticChart extends React.Component {
}
}
}],
xAxes: [{
x: [{
ticks: {
maxTicksLimit: 20
}
Expand Down Expand Up @@ -109,11 +130,13 @@ class StatisticChart extends React.Component {
render() {

let { data, options } = this.state;
if (Object.keys(data).length === 0 && Object.keys(options).length === 0) {
return <Loading />;
}
return (
<Line
data={data}
options={options}
/>
<>
<Line data={data} options={options} />
</>
);
}
}
Expand Down

0 comments on commit 18ba12f

Please sign in to comment.