Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

你好,我是个echart的初学者,想问个问题 #1

Closed
fapwlh opened this issue Mar 3, 2016 · 3 comments
Closed

你好,我是个echart的初学者,想问个问题 #1

fapwlh opened this issue Mar 3, 2016 · 3 comments

Comments

@fapwlh
Copy link

fapwlh commented Mar 3, 2016

假如我现在要使用timeline组件,要实现官网的下面data数组,[
'2002-01-01',
'2003-01-01',
'2004-01-01',
{
value: '2005-01-01',
tooltip: { // 让鼠标悬浮到此项时能够显示 tooltip
formatter: '{b} xxxx'
},
symbol: 'diamond', // 此项的图形的特别设置。
symbolSize: 16 // 此项的图形大小的特别设置。
},
'2006-01-01'

]
我现在的写法是,
TimeLineCharts charts=new TimeLineCharts();
Map<String, Object> map=new HashMap<String,Object>();
Map<String, Object> mtool=new HashMap<>();
mtool.put("formatter", "what");
map.put("value", "2005-01-01");
map.put("tooltip", mtool);
map.put("symbol", "diamond");
map.put("symbolSize", 16);
charts.setData(new Object[]{"2002-01-01","2003-01-01","2004-01-01",map,"2006-01-01"});
Object json=EChartsAnnotationProcessor.phraseSingleChart(charts);
System.out.print(JSON.toJSONString(json));
请问我这种写法对么?还是有其它更简洁的写法,还有echarts3中说把公共的组建都放到baseOptions里,这个,我怎么能把我的这个timeline放到options里面,生成json字符串到时候,我把baseOption 并在生成好的字符串中?谢谢了

@zaoying
Copy link
Owner

zaoying commented Mar 3, 2016

你好,你这样的写法其实不适合用我的框架。正确的写法:
//创建TimeLine.java
import cn.edu.gdut.zaoying.Option.timeline.DataArray;
import cn.edu.gdut.zaoying.Option.timeline.SymbolSizeNumber;
import cn.edu.gdut.zaoying.Option.timeline.SymbolString;
import cn.edu.gdut.zaoying.Option.tooltip.FormatterString;
import cn.edu.gdut.zaoying.SingleChart;
@SingleChart
public class TimeLine {
@FormatterString(value = "{b}XXXX")
String formatter;
@dataarray
double data[];
@SymbolString(value = "diamond")
String symbol;
@SymbolSizeNumber(value = 16)
int symbolSize;

public void setData(String[] data) {
    this.data = data;
}

}
//创建ECharts.java
import com.alibaba.fastjson.JSON;
import java.util.HashMap;
import java.util.Map;

public class ECharts {
public static void main(String[] args) {
TimeLine timeLine=new TimeLine();
timeLine.setData(new String[]{"2002-01-01","2003-01-01","2004-01-01","2005-01-01","2006-01-01"});
Map<String,Object> option=new HashMap<>();
Object json=EChartsAnnotationProcessor.parseChart(timeLine);
option.put("baseOption",json);
System.out.print(JSON.toJSONString(option));
}
}
PS:别被那么多代码吓到了,其实核心代码跟你的差不多。但是这个达不到你要的效果,你给的例子是官方的特例,因为它没有写进Option配置里。因此我把你的代码改动如下:
TimeLineCharts charts=new TimeLineCharts();
Map<String,Object> map=new HashMap<>();
Map<String,Object> mtool=new HashMap<>();
mtool.put("formatter", "what");
map.put("value", "2005-01-01");
map.put("tooltip", mtool);
map.put("symbol", "diamond");
map.put("symbolSize", 16);
charts.setData(new Object[]{"2002-01-01","2003-01-01","2004-01-01",map,"2006-01-01"});
//你没有使用框架里的注解,因此调用我的解析器是没有效果的
//Object json=EChartsAnnotationProcessor.parseSingleChart(charts);
System.out.print(JSON.toJSONString(charts));//直接用fastjson输出json
PS:咳!这个可以达到你要的效果,但是我的框架不是专门解析JSON的类库。你如果觉得不喜欢用注解,我推荐你使用fastjson来到你的目的。

@fapwlh
Copy link
Author

fapwlh commented Mar 3, 2016

非常感谢回复,受教了,是我把你的这个框架还没有完全理解,下来再好好对照echart的api学学,再次感谢!

@zaoying
Copy link
Owner

zaoying commented Mar 3, 2016

不用客气

@zaoying zaoying closed this as completed Mar 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants