forked from alibaba/ice
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChartRelation.jsx
More file actions
122 lines (113 loc) · 3.26 KB
/
ChartRelation.jsx
File metadata and controls
122 lines (113 loc) · 3.26 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import React, { Component } from 'react';
import IceContainer from '@icedesign/container';
import { Chart, Geom, Tooltip, Label } from 'bizcharts';
import { DataView } from '@antv/data-set';
import './ChartRelation.scss';
export default class ChartRelation extends Component {
static displayName = 'ChartRelation';
static propTypes = {};
static defaultProps = {};
constructor(props) {
super(props);
this.state = {};
}
render() {
// 参考:https://alibaba.github.io/BizCharts/
const data = {
name: 'root',
children: [
{ name: '分类 1', value: 560 },
{ name: '分类 2', value: 500 },
{ name: '分类 3', value: 150 },
{ name: '分类 4', value: 140 },
{ name: '分类 5', value: 115 },
{ name: '分类 6', value: 95 },
{ name: '分类 7', value: 90 },
{ name: '分类 8', value: 75 },
{ name: '分类 9', value: 98 },
{ name: '分类 10', value: 60 },
{ name: '分类 11', value: 45 },
{ name: '分类 12', value: 40 },
{ name: '分类 13', value: 40 },
{ name: '分类 14', value: 35 },
{ name: '分类 15', value: 40 },
{ name: '分类 16', value: 40 },
{ name: '分类 17', value: 40 },
{ name: '分类 18', value: 30 },
{ name: '分类 19', value: 28 },
{ name: '分类 20', value: 16 },
],
};
const dv = new DataView();
dv
.source(data, {
type: 'hierarchy',
})
.transform({
field: 'value',
type: 'hierarchy.treemap',
tile: 'treemapResquarify',
as: ['x', 'y'],
});
const nodes = dv.getAllNodes();
nodes.map((node) => {
node.name = node.data.name;
node.value = node.data.value;
return node;
});
const scale = {
value: { nice: false },
};
const htmlStr =
'<li data-index={index}>' +
'<span style="background-color:{color};" class="g2-tooltip-marker"></span>' +
'{name}<br/>' +
'<span style="padding-left: 16px">浏览人数:{count}</span><br/>' +
'</li>';
return (
<div className="chart-relation">
<IceContainer>
<h4 style={styles.title}>面积图</h4>
<Chart data={nodes} forceFit height={400} scale={scale}>
<Tooltip showTitle={false} itemTpl={htmlStr} />
<Geom
type="polygon"
position="x*y"
color="name"
tooltip={[
'name*value',
(name, count) => {
return {
name,
count,
};
},
]}
style={{ lineWidth: 1, stroke: '#fff' }}
>
<Label
content="name"
offset={0}
textStyle={{ textBaseline: 'middle' }}
formatter={(val) => {
if (val !== 'root') {
return val;
}
}}
/>
</Geom>
</Chart>
</IceContainer>
</div>
);
}
}
const styles = {
title: {
margin: '0 0 40px',
fontSize: '18px',
paddingBottom: '15px',
fontWeight: 'bold',
borderBottom: '1px solid #eee',
},
};