wjc
2025-01-07 90d5f028ccdaaaf64286f9d632cb335a4d0544b9
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package com.hdl.photovoltaic.ui.home.aachart;
 
import static com.github.AAChartModel.AAChartCore.AATools.AAColor.AARgba;
 
import com.github.AAChartModel.AAChartCore.AAChartCreator.AAChartModel;
import com.github.AAChartModel.AAChartCore.AAChartCreator.AASeriesElement;
import com.github.AAChartModel.AAChartCore.AAChartEnum.AAChartAnimationType;
import com.github.AAChartModel.AAChartCore.AAChartEnum.AAChartSymbolStyleType;
import com.github.AAChartModel.AAChartCore.AAChartEnum.AAChartSymbolType;
import com.github.AAChartModel.AAChartCore.AAChartEnum.AAChartType;
import com.github.AAChartModel.AAChartCore.AAChartEnum.AAChartZoomType;
import com.github.AAChartModel.AAChartCore.AAOptionsModel.AAChart;
import com.github.AAChartModel.AAChartCore.AAOptionsModel.AAStyle;
import com.github.AAChartModel.AAChartCore.AAOptionsModel.AATitle;
import com.github.AAChartModel.AAChartCore.AAOptionsModel.AATooltip;
import com.github.AAChartModel.AAChartCore.AATools.AAColor;
import com.github.AAChartModel.AAChartCore.AATools.AAGradientColor;
import com.github.AAChartModel.AAChartCore.AATools.AALinearGradientDirection;
 
import java.util.Map;
 
public class BasicChartComposer {
    public static AAChartModel configureBasicOptions() {
        return new AAChartModel()
                .backgroundColor("#1C1C1E")
//                .backgroundColor("#4b2b7f")
                .dataLabelsEnabled(false)
//                .yAxisGridLineWidth(0.5)
                .touchEventEnabled(true);
    }
 
    public static AAChartModel configureAreaChart() {
        Map<String, Object> linearGradientColor = AAGradientColor.linearGradient(
                AALinearGradientDirection.ToBottom,
                "rgba(56,196,148,0.5)",//深粉色, alpha 透明度1
                "rgba(255,255,255,0)"//热情的粉红, alpha 透明度 0.1
        );//颜色字符串设置支持十六进制类型和 rgba 类型
        AASeriesElement element1 = new AASeriesElement()
                .name("Tokyo")
//                .colorByPoint(true)
                .color(AARgba(56, 196, 148, 1.0f))//猩红色, alpha 透明度 1
                .lineWidth(1.5)
//                .borderColor(AARgba(255,255,255,1.0f))
                .fillColor(linearGradientColor)
//                .fillOpacity(0.5)//区域背景透明度,设置0的话看不到区域背景
                .data(new Object[]{0, 20, 30, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6});
//        AASeriesElement element2 = new AASeriesElement()
//                .name("NewYork")
//                .data(new Object[]{0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5});
//        AASeriesElement element3 = new AASeriesElement()
//                .name("London")
//                .data(new Object[]{0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0});
//        AASeriesElement element4 = new AASeriesElement()
//                .name("Berlin")
//                .data(new Object[]{3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8});
 
        return configureBasicOptions()
                .backgroundColor("#333738")
                .legendEnabled(false)
                .markerRadius(0)
//                .markerSymbol(AAChartSymbolType.Circle)
                .markerSymbolStyle(AAChartSymbolStyleType.Normal)
                .chartType(AAChartType.Area)
                .categories(new String[]{"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"})
                .series(new AASeriesElement[]{element1});
    }
 
    public static AAChartModel configureAreaChart(String tipSuspendName, String[] categories, Object[] data) {
        Map<String, Object> linearGradientColor = AAGradientColor.linearGradient(
                AALinearGradientDirection.ToBottom,
                "rgba(56,196,148,0.5)",//深粉色, alpha 透明度1
                "rgba(255,255,255,0)"//热情的粉红, alpha 透明度 0.1
        );
        //颜色字符串设置支持十六进制类型和 rgba 类型
//        AAStyle aaStyle = new AAStyle();
//        aaStyle.color("#FFFFFFFF");
//        aaStyle.background("#FF555859");
 
 
        AATooltip aaTooltip = new AATooltip()
                .enabled(true)
                .backgroundColor(AAColor.rgbaColor(51, 55, 56, 1f))
                .valueDecimals(2);
 
        AASeriesElement element1 = new AASeriesElement()
                .name(tipSuspendName)
//                .colorByPoint(true)
                .color(AARgba(56, 196, 148, 1.0f))//猩红色, alpha 透明度 1
                .lineWidth(1.5)
//                .borderColor(AARgba(255,255,255,1.0f))
                .fillColor(linearGradientColor)
//                .fillOpacity(0.5)//区域背景透明度,设置0的话看不到区域背景
//                .tooltip(aaTooltip)
                .data(data);
 
//        AASeriesElement element2 = new AASeriesElement()
//                .name("NewYork")
//                .data(new Object[]{0.45, 0.43, 0.50, 0.55, 0.58, 0.62, 0.83, 0.39, 0.56, 0.67, 0.50, 0.34, 0.50, 0.67, 0.58, 0.29, 0.46, 0.23, 0.47, 0.46, 0.38, 0.56, 0.48, 0.36});
        return configureBasicOptions()
                .backgroundColor("#1C1C1E")
                .legendEnabled(false)
                .markerRadius(0)
//                .markerSymbol(AAChartSymbolType.Circle)
//                .markerSymbolStyle(AAChartSymbolStyleType.Normal)
                .chartType(AAChartType.Area)
                .categories(categories)
                .zoomType(AAChartZoomType.None)//手势缩放
                .yAxisGridLineWidth(0.10)
                .yAxisAllowDecimals(true)
                .xAxisVisible(true)
//                .yAxisMax(100)
                .yAxisMin(0)
                .titleStyle(AAStyle.style("#66FFFFFF", 12))//坐标轴字体颜色
//                .axesTextColor("#FFFFFF")//背景颜色
                .series(new AASeriesElement[]{element1});
    }
 
    public static AAChartModel configureStepAreaChartAndStepLineChart() {
        AASeriesElement element1 = new AASeriesElement()
                .name("Tokyo")
                .step(true)
                .data(new Object[]{149.9, 171.5, 106.4, 129.2, 144.0, 176.0, 135.6, 188.5, 276.4, 214.1, 95.6, 54.4});
 
        AASeriesElement element2 = new AASeriesElement()
                .name("NewYork")
                .step(true)
                .data(new Object[]{83.6, 78.8, 188.5, 93.4, 106.0, 84.5, 105.0, 104.3, 131.2, 153.5, 226.6, 192.3});
 
        AASeriesElement element3 = new AASeriesElement()
                .name("London")
                .step(true)
                .data(new Object[]{48.9, 38.8, 19.3, 41.4, 47.0, 28.3, 59.0, 69.6, 52.4, 65.2, 53.3, 72.2});
 
        return configureBasicOptions()
                .chartType(AAChartType.Area)
                .series(new AASeriesElement[]{element1, element2, element3,});
    }
 
    public static AAChartModel configureColumnChartAndBarChart() {
        return configureAreaChart()
                .categories(new String[]{
                        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
                })
                .legendEnabled(true)
                .colorsTheme(new String[]{"#fe117c", "#ffc069", "#06caf4", "#7dffc0"})
                .animationType(AAChartAnimationType.EaseOutCubic)
                .animationDuration(1200);
    }
 
    public static AAChartModel configureAreaChartAndAreasplineChartStyle(String chartType) {
        String[] colorsArr = {
                AAColor.Red,
                AAColor.Orange,
                AAColor.Red,
                AAColor.Green,
                AAColor.Red,
                AAColor.Blue,
                AAColor.Red,
                AAColor.Gray,
                AAColor.DarkGray,
                AAColor.LightGray,
                AAColor.Magenta,
                AAColor.Brown,
                AAColor.Black,
        };
        AAChartModel aaChartModel = configureAreaChart()
                .animationType(AAChartAnimationType.EaseOutQuart)
                .legendEnabled(true)
                .markerRadius(0)
                .markerSymbolStyle(AAChartSymbolStyleType.Normal)
//                .markerSymbol(AAChartSymbolType.Circle)
                .tooltipValueSuffix("Kw.h")
//                .colorsTheme(colorsArr)
                .legendEnabled(false);
 
 
        if (chartType.equals(AAChartType.Areaspline)) {
            Map<String, Object> gradientColorDic = AAGradientColor.linearGradient(
                    AALinearGradientDirection.ToBottomRight,
                    "rgba(138,43,226,1)",
                    "rgba(30,144,255,1)" //颜色字符串设置支持十六进制类型和 rgba 类型
            );
 
            AASeriesElement element1 = new AASeriesElement()
                    .name("Predefined symbol")
                    .fillColor(gradientColorDic)
                    .data(new Object[]{0.45, 0.43, 0.50, 0.55, 0.58, 0.62, 0.83, 0.39, 0.56, 0.67, 0.50, 0.34, 0.50, 0.67, 0.58, 0.29, 0.46, 0.23, 0.47, 0.46, 0.38, 0.56, 0.48, 0.36});
 
            AASeriesElement element2 = new AASeriesElement()
                    .name("Image symbol")
                    .data(new Object[]{0.38, 0.31, 0.32, 0.32, 0.64, 0.66, 0.86, 0.47, 0.52, 0.75, 0.52, 0.56, 0.54, 0.60, 0.46, 0.63, 0.54, 0.51, 0.58, 0.64, 0.60, 0.45, 0.36, 0.67});
 
            AASeriesElement element3 = new AASeriesElement()
                    .name("Base64 symbol (*)")
                    .data(new Object[]{0.46, 0.32, 0.53, 0.58, 0.86, 0.68, 0.85, 0.73, 0.69, 0.71, 0.91, 0.74, 0.60, 0.50, 0.39, 0.67, 0.55, 0.49, 0.65, 0.45, 0.64, 0.47, 0.63, 0.64});
 
            AASeriesElement element4 = new AASeriesElement()
                    .name("Custom symbol")
                    .data(new Object[]{0.60, 0.51, 0.52, 0.53, 0.64, 0.84, 0.65, 0.68, 0.63, 0.47, 0.72, 0.60, 0.65, 0.74, 0.66, 0.65, 0.71, 0.59, 0.65, 0.77, 0.52, 0.53, 0.58, 0.53});
 
            aaChartModel
                    .animationType(AAChartAnimationType.EaseFrom)//设置图表渲染动画类型为 EaseFrom
                    .series(new AASeriesElement[]{element1, element2, element3, element4});
        }
        return aaChartModel;
    }
 
 
    public static AAChartModel configureLineChartAndSplineChartStyle(String chartType) {
        AAChartModel aaChartModel = configureAreaChart()
                .chartType(chartType)
                .markerSymbolStyle(AAChartSymbolStyleType.BorderBlank)//设置折线连接点样式为:边缘白色
                .markerRadius(6);
        if (chartType.equals(AAChartType.Spline)) {
            AASeriesElement element1 = new AASeriesElement()
                    .name("Tokyo")
                    .lineWidth(7)
                    .data(new Object[]{50, 320, 230, 370, 230, 400,});
 
            AASeriesElement element2 = new AASeriesElement()
                    .name("Berlin")
                    .lineWidth(7)
                    .data(new Object[]{80, 390, 210, 340, 240, 350,});
 
            AASeriesElement element3 = new AASeriesElement()
                    .name("New York")
                    .lineWidth(7)
                    .data(new Object[]{100, 370, 180, 280, 260, 300,});
 
            AASeriesElement element4 = new AASeriesElement()
                    .name("London")
                    .lineWidth(7)
                    .data(new Object[]{130, 350, 160, 310, 250, 268,});
 
            aaChartModel
                    .animationType(AAChartAnimationType.SwingFromTo)
                    .series(new AASeriesElement[]{element1, element2, element3, element4});
 
        }
        return aaChartModel;
    }
}