Skip to content

Commit fe1b920

Browse files
committed
增加一个例子,但是无法正常显示,因为echarts不认识字符串的日期。
1 parent bf5653a commit fe1b920

3 files changed

Lines changed: 104 additions & 2 deletions

File tree

‎src/main/java/com/github/abel533/echarts/feature/MagicType.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ public MagicType(Magic... magics) {
5252
this.type(magics);
5353
}
5454
}
55-
}
55+
}

‎src/main/java/com/github/abel533/echarts/feature/SaveAsImage.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ public SaveAsImage() {
3737
this.type("png");
3838
this.lang(new String[]{"点击保存"});
3939
}
40-
}
40+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014 abel533@gmail.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package com.github.abel533.echarts.samples.scatter;
26+
27+
import com.github.abel533.echarts.axis.TimeAxis;
28+
import com.github.abel533.echarts.axis.ValueAxis;
29+
import com.github.abel533.echarts.code.Orient;
30+
import com.github.abel533.echarts.code.Tool;
31+
import com.github.abel533.echarts.code.Trigger;
32+
import com.github.abel533.echarts.code.Y;
33+
import com.github.abel533.echarts.series.Scatter;
34+
import com.github.abel533.echarts.util.EnhancedOption;
35+
import org.junit.Test;
36+
37+
import java.math.BigDecimal;
38+
import java.math.MathContext;
39+
import java.math.RoundingMode;
40+
import java.text.SimpleDateFormat;
41+
import java.util.ArrayList;
42+
import java.util.Date;
43+
import java.util.List;
44+
45+
/**
46+
* @author liuzh
47+
*/
48+
public class ScatterTest6 {
49+
50+
@Test
51+
public void test() {
52+
//地址:http://echarts.baidu.com/doc/example/scatter6.html
53+
//TODO echarts只能认识js的Date...
54+
EnhancedOption option = new EnhancedOption();
55+
option.title("时间坐标散点图","dataZoom支持");
56+
option.tooltip().trigger(Trigger.item).formatter("function (params) {" +
57+
" return params.seriesName + ' (' + '类目' + params.value[0] + ')<br/>'" +
58+
" + params.value[1] + ', ' " +
59+
" + params.value[2];" +
60+
" }");
61+
option.legend("series1");
62+
option.toolbox().show(true).feature(Tool.mark, Tool.dataView, Tool.restore, Tool.saveAsImage);
63+
option.dataZoom().show(true).start(30).end(70);
64+
option.dataRange().min(0).max(100).orient(Orient.horizontal).x(30).y(Y.center).color("lightgreen", "orange").splitNumber(5);
65+
option.grid().y2(80);
66+
option.xAxis(new TimeAxis().splitNumber(10));
67+
option.yAxis(new ValueAxis());
68+
option.animation(false);
69+
70+
Scatter series1 = new Scatter("series1");
71+
series1.symbolSize("function (value){" +
72+
" return Math.round(value[2]/10);" +
73+
" }");
74+
series1.data(getData().toArray());
75+
76+
option.series(series1);
77+
option.exportToHtml("scatter6.html");
78+
option.view();
79+
}
80+
81+
public List<Object[]> getData(){
82+
List<Object[]> dataList = new ArrayList<Object[]>(1500);
83+
for (int i = 0; i < 1500; i++) {
84+
dataList.add(new Object[]{getDateStr(new Date(114,9,1,0,(int)Math.round(Math.random()*10000))),
85+
(int)(round(Math.random()*30) - 0),
86+
(int)(round(Math.random()*100) - 0)
87+
});
88+
}
89+
return dataList;
90+
}
91+
92+
public String getDateStr(Date date){
93+
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
94+
return format.format(date);
95+
}
96+
97+
public Double round(Double d) {
98+
BigDecimal bigDecimal = new BigDecimal(d.toString());
99+
bigDecimal = bigDecimal.round(new MathContext(2, RoundingMode.HALF_UP));
100+
return bigDecimal.doubleValue();
101+
}
102+
}

0 commit comments

Comments
 (0)