forked from ECharts-Java/ECharts-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChart.java
More file actions
145 lines (117 loc) · 3.78 KB
/
Chart.java
File metadata and controls
145 lines (117 loc) · 3.78 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package org.icepear.echarts;
import java.util.ArrayList;
import java.util.List;
import org.icepear.echarts.components.dataset.Dataset;
import org.icepear.echarts.components.legend.Legend;
import org.icepear.echarts.components.title.Title;
import org.icepear.echarts.components.tooltip.Tooltip;
import org.icepear.echarts.components.visualMap.ContinousVisualMap;
import org.icepear.echarts.origin.component.visualMap.VisualMapOption;
import org.icepear.echarts.origin.util.SeriesOption;
public abstract class Chart<T extends Chart<?, ?>, E extends SeriesOption> {
protected final T self;
protected final Class<E> seriesClazz;
protected List<Dataset> datasets;
protected List<SeriesOption> series;
protected Option option;
public Chart(final Class<T> clazz, final Class<E> seriesClazz) {
self = clazz.cast(this);
this.seriesClazz = seriesClazz;
datasets = new ArrayList<>();
series = new ArrayList<>();
option = new Option();
}
public Option getOption() {
if (datasets.size() > 0) {
option.setDataset(datasets.toArray(new Dataset[0]));
}
option.setSeries(series.toArray(new SeriesOption[0]));
return option;
}
public T setTitle(String text) {
option.setTitle(new Title().setText(text));
return self;
}
public T setTitle(Title title) {
option.setTitle(title);
return self;
}
public T setLegend() {
option.setLegend(new Legend());
return self;
}
public T setLegend(Legend legend) {
option.setLegend(legend);
return self;
}
public T setTooltip(String trigger) {
option.setTooltip(new Tooltip().setTrigger(trigger));
return self;
}
public T setTooltip(Tooltip tooltip) {
option.setTooltip(tooltip);
return self;
}
public T addDataset(Object[] source) {
datasets.add(new Dataset().setSource(source));
return self;
}
public T addDataset(Object[][] source) {
datasets.add(new Dataset().setSource(source));
return self;
}
public T addDataset(Object[][][] source) {
datasets.add(new Dataset().setSource(source));
return self;
}
public T addDataset(Dataset dataset) {
datasets.add(dataset);
return self;
}
public T setVisualMap(Number min, Number max) {
option.setVisualMap(new ContinousVisualMap().setMin(min).setMax(max));
return self;
}
public T setVisualMap(VisualMapOption visualMap) {
option.setVisualMap(visualMap);
return self;
}
public T addSeries(Object[] data) {
this.series.add(createSeries(data));
return self;
}
public T addSeries(Object[][] data) {
this.series.add(createSeries(data));
return self;
}
public T addSeries(Object[][][] data) {
this.series.add(createSeries(data));
return self;
}
public T addSeries(String name, Object[] data) {
this.series.add(createSeries(name, data));
return self;
}
public T addSeries(String name, Object[][] data) {
this.series.add(createSeries(name, data));
return self;
}
public T addSeries(String name, Object[][][] data) {
this.series.add(createSeries(name, data));
return self;
}
public T addSeries(E series) {
this.series.add(createSeries(series));
return self;
}
protected abstract E createSeries();
protected E createSeries(Object data) {
return seriesClazz.cast(createSeries().setData(data));
}
protected E createSeries(String name, Object data) {
return seriesClazz.cast(createSeries(data).setName(name));
}
protected E createSeries(E series) {
return series;
}
}