扩展图表示例。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

197 lines
6.0 KiB

package com.fr.plugin.demo;
import com.fr.base.BaseFormula;
import com.fr.extended.chart.AbstractChart;
import com.fr.extended.chart.ExtendedHelper;
import com.fr.extended.chart.HyperLinkPara;
import com.fr.extended.chart.export.ExportProcessor;
import com.fr.extended.chart.export.JSExportProcessor;
import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralUtils;
import com.fr.json.JSON;
import com.fr.json.JSONArray;
import com.fr.json.JSONException;
import com.fr.json.JSONFactory;
import com.fr.json.JSONObject;
import com.fr.plugin.transform.ExecuteFunctionRecord;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.stable.web.Repository;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
import java.util.ArrayList;
import java.util.List;
/**
* Created by shine on 2018/3/24.
*/
@FunctionRecorder
public class DemoChart extends AbstractChart<DemoDataConfig>{
private static final String ID = "DEMO_CHART";
private static final String NAME = "DEMO图表";
private BaseFormula titleFormula;
public BaseFormula getTitleFormula() {
return titleFormula;
}
public void setTitleFormula(BaseFormula titleFormula) {
this.titleFormula = titleFormula;
}
@Override
protected void readAttr(XMLableReader reader) {
super.readAttr(reader);
this.setTitleFormula(ExtendedHelper.readFormula(reader, "title"));
}
@Override
protected void writeAttr(XMLPrintWriter writer) {
super.writeAttr(writer);
ExtendedHelper.writeFormula(this.getTitleFormula(), writer, "title");
}
@Override
public Object clone() throws CloneNotSupportedException {
DemoChart result = (DemoChart) super.clone();
result.setTitleFormula(this.getTitleFormula().clone());
return result;
}
@Override
public boolean equals(Object ob) {
return super.equals(ob)
&& ob instanceof DemoChart
&& ComparatorUtils.equals(this.getTitleFormula(), ((DemoChart) ob).getTitleFormula())
;
}
@Override
protected String getChartID() {
return ID;
}
@Override
public String getChartName() {
return NAME;
}
@Override
protected String demoImagePath() {
return "com/fr/plugin/demo/demo.png";
}
@ExecuteFunctionRecord
@Override
protected void addJSON(DemoDataConfig dataConfig, JSONObject jsonObject, Repository repo) throws JSONException {
jsonObject.put("title", JSONFactory.createJSON(JSON.OBJECT).put("text", ExtendedHelper.getFormulaResult(titleFormula)));
JSONArray array = JSONFactory.createJSON(JSON.ARRAY);
List<Object> xValues = dataConfig.getX().getValues();
List<Object> yValues = dataConfig.getY().getValues();
List<Object> zValues = dataConfig.getZ().getValues();
double maxValue = Double.MIN_VALUE;
for (int i = 0, len = xValues.size(); i < len; i++) {
maxValue = Math.max(GeneralUtils.objectToNumber(zValues.get(i)).doubleValue(), maxValue);
array.put(JSONFactory.createJSON(JSON.ARRAY).put(xValues.get(i)).put(yValues.get(i)).put(zValues.get(i)));
}
jsonObject.put("series", JSONFactory.createJSON(JSON.OBJECT).put("type", "bar3D").put("data", array)
.put("bevelSize", 0.2).put("bevelSmoothness", 2).put("shading", "color"));
jsonObject.put("xAxis3D", JSONFactory.createJSON(JSON.OBJECT).put("type", "category"))
.put("yAxis3D", JSONFactory.createJSON(JSON.OBJECT).put("type", "category"))
.put("zAxis3D", JSONFactory.createJSON(JSON.OBJECT).put("type", "value"));
jsonObject.put("grid3D", JSONFactory.createJSON(JSON.OBJECT).put("boxWidth", 200).put("boxDepth", 80));
jsonObject.put("visualMap", JSONFactory.createJSON(JSON.OBJECT)
.put("max", maxValue)
.put("color", JSONFactory.createJSON(JSON.ARRAY).put("#d94e5d").put("#eac736").put("#50a3ba")));
}
@Override
protected String[] requiredJS() {
return new String[]{
"com/fr/plugin/demo/demoWrapper.js",
"com/fr/plugin/demo/echarts.js",
"com/fr/plugin/demo/echarts-gl.js"
};
}
@Override
protected String wrapperName() {
return "demoWrapper";
}
private static final HyperLinkPara X = new HyperLinkPara() {
@Override
public String getName() {
return "X轴";
}
@Override
public String getFormulaContent() {
return "X";
}
@Override
public String[] getProps() {
return new String[]{"data", "0"};
}
};
private static final HyperLinkPara Y = new HyperLinkPara() {
@Override
public String getName() {
return "Y轴";
}
@Override
public String getFormulaContent() {
return "Y";
}
@Override
public String[] getProps() {
return new String[]{"data", "1"};
}
};
private static final HyperLinkPara[] PARAS = new HyperLinkPara[]{
X,
Y
};
@Override
protected HyperLinkPara[] hyperLinkParas() {
return PARAS;
}
@Override
protected List<BaseFormula> formulas() {
List<BaseFormula> list = new ArrayList<BaseFormula>();
list.add(this.getTitleFormula());
return list;
}
@Override
protected ExportProcessor createExportProcessor() {
return new JSExportProcessor();
}
// @Override
// protected DemoDataConfig designerDataConfig() {
// DemoDataConfig demoDataConfig = new DemoDataConfig();
// demoDataConfig.setX(new ExtendedField("days", new String[]{"Monday","Tuesday"}));
// demoDataConfig.setY(new ExtendedField("name", new String[]{"Lily", "Marks"}));
// demoDataConfig.setZ(new ExtendedField("money", new String[]{"100", "200"}));
// return super.designerDataConfig();
// }
}