-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMetricLine.js
55 lines (53 loc) · 1.34 KB
/
MetricLine.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Line } from "@ant-design/plots";
import { formatter as formatHelper } from "@/utils/format";
import { isFloat } from "@/utils/utils";
import styles from "./index.scss";
export default (props) => {
const x_field = props.xField || "x";
const y_field = props.yField || "y";
const series_field = props.seriesField || "category";
const y_units = props.yUnits || "";
const config = {
data: props.data || [],
xField: x_field,
yField: y_field,
seriesField: series_field,
animation: false,
xAxis: {
label: {
// x轴不显示值
formatter: (v) => {},
},
},
yAxis: {
label: {
// y轴数值格式化
formatter: (v) => {
// `${v}`.replace(/\d{1,3}(?=(\d{3})+$)/g, (s) => `${s},`),
if (y_units.indexOf("bytes") > -1) {
return formatHelper.bytes(v);
}
return v;
},
},
},
tooltip: {
formatter: (v) => {
let value = v[y_field];
if (y_units.indexOf("bytes") > -1) {
value = formatHelper.bytes(value);
} else {
if (isFloat(value)) {
value = value.toFixed(2);
}
}
return { name: v[series_field], value: value };
},
},
};
return (
<div className={styles.chartBody}>
<Line {...config} />
</div>
);
};