File tree Expand file tree Collapse file tree 3 files changed +115
-0
lines changed
packages/console-line-chart Expand file tree Collapse file tree 3 files changed +115
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,14 @@ import { ConsoleLineChart } from '@alicloud/console-chart';
6868
6969[ MDXInstruction:importDemo: GradualColor ] ( ./demo/GradualColor.tsx )
7070
71+ ## Legend点击事件
72+
73+ 通过` event ` 属性来配置事件,配置` legend-item:click ` 对应的事件即可以配置图例点击事件。注意,由于内部实现和React自带的Function Component优化有冲突,` event ` 属性配置的事件不会触发` function component ` 的更新,所以这时候请使用` class ` 语法。
74+
75+ 更多事件请看[ G2-图表事件] ( https://g2-v3.antv.vision/zh/docs/manual/tutorial/event )
76+
77+ [ MDXInstruction:importDemo: LegendClick ] ( ./demo/LegendClick.tsx )
78+
7179# Config 配置
7280
7381# 数据列配置
Original file line number Diff line number Diff line change 1+ // @ts -nocheck
2+ import React from 'react' ;
3+ import { ConsoleLineChart } from '@alicloud/console-chart' ;
4+
5+ const data = [
6+ {
7+ name : 'ECS' ,
8+ data : [
9+ [ '201804' , 31 ] ,
10+ [ '201805' , 39 ] ,
11+ [ '201806' , 32 ] ,
12+ [ '201807' , 35 ] ,
13+ [ '201808' , 31 ] ,
14+ [ '201809' , 36 ] ,
15+ [ '201810' , 32 ] ,
16+ [ '201811' , 34 ] ,
17+ ] ,
18+ } ,
19+ {
20+ name : 'OSS' ,
21+ data : [
22+ [ '201804' , 12 ] ,
23+ [ '201805' , 12 ] ,
24+ [ '201806' , 12 ] ,
25+ [ '201807' , 11 ] ,
26+ [ '201808' , 10 ] ,
27+ [ '201809' , 14 ] ,
28+ [ '201810' , 12 ] ,
29+ [ '201811' , 11 ] ,
30+ ] ,
31+ } ,
32+ {
33+ name : 'RDS' ,
34+ data : [
35+ [ '201804' , 48 ] ,
36+ [ '201805' , 45 ] ,
37+ [ '201806' , 43 ] ,
38+ [ '201807' , 44 ] ,
39+ [ '201808' , 41 ] ,
40+ [ '201809' , 45 ] ,
41+ [ '201810' , 42 ] ,
42+ [ '201811' , 45 ] ,
43+ ] ,
44+ } ,
45+ ] ;
46+
47+ const ossConfig = {
48+ yAxis : {
49+ min : 30
50+ }
51+ } ;
52+
53+ const defaultConfig = {
54+ yAxis : {
55+ min : 0
56+ }
57+ }
58+
59+ interface State {
60+ keys : string [ ] ;
61+ }
62+
63+ interface Props { }
64+
65+ class Demo extends React . Component < Props , State > {
66+ constructor ( props : Props ) {
67+ super ( props ) ;
68+ const defaultKeys = data . map ( x => x . name ) ;
69+ this . state = {
70+ keys : defaultKeys ,
71+ }
72+ }
73+
74+ handleClick = ( ev : any ) => {
75+ const { keys } = this . state ;
76+ const val = ev . data . value ;
77+ let newKeys = [ ] ;
78+ if ( keys . includes ( val ) ) {
79+ newKeys = keys . filter ( x => x !== val ) ;
80+ } else {
81+ newKeys = [ ...keys , val ] ;
82+ }
83+ this . setState ( { keys : newKeys } ) ;
84+ } ;
85+
86+ render ( ) {
87+ const { keys } = this . state ;
88+ console . log ( keys ) ;
89+
90+ const config = ! keys . includes ( 'OSS' ) ? ossConfig : defaultConfig ;
91+
92+ return (
93+ < ConsoleLineChart
94+ data = { data }
95+ config = { config }
96+ height = { 300 }
97+ event = { {
98+ 'legend-item:click' : this . handleClick ,
99+ } }
100+ />
101+ ) ;
102+ }
103+ }
104+
105+ export default ( ) => < Demo /> ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import Stack from './Stack';
1313import XAxisAsync from './XAxisAsync' ;
1414import YAxisMin from './YAxisMin' ;
1515import GradualColor from './GradualColor' ;
16+ import LegendClick from './LegendClick' ;
1617
1718storiesOf ( 'ConsoleLineChart' , module )
1819 . add ( '基本折线图' , ( ) => < Basic /> )
@@ -27,3 +28,4 @@ storiesOf('ConsoleLineChart', module)
2728 . add ( '线条带点' , ( ) => < Dot /> )
2829 . add ( '面积堆栈图' , ( ) => < Stack /> )
2930 . add ( '颜色渐变图' , GradualColor )
31+ . add ( '图例点击控制' , LegendClick )
You can’t perform that action at this time.
0 commit comments