diff --git a/src/com/fr/solution/plugin/chart/echarts/base/NewChart.java b/src/com/fr/solution/plugin/chart/echarts/base/NewChart.java index 390aba0..b5a643d 100644 --- a/src/com/fr/solution/plugin/chart/echarts/base/NewChart.java +++ b/src/com/fr/solution/plugin/chart/echarts/base/NewChart.java @@ -10,22 +10,21 @@ import com.fr.general.ComparatorUtils; */ public class NewChart extends Chart { - private NewPlot newPlot; - public NewChart() { setWrapperName("EChartsFactory"); } public NewChart(NewPlot plot) { + super(plot); setWrapperName("EChartsFactory"); - this.newPlot = plot; } @Override public BaseChartGlyph createGlyph(ChartData chartData) { NewGlyph glyph = new NewGlyph(); glyph.setGeneralInfo(this); + NewPlot newPlot = (NewPlot) getPlot(); if (newPlot != null) { glyph.setLegendGlyph(newPlot.createChartLegendGlyph(chartData)); glyph.setTitleGlyph(newPlot.createChartTitleGlyph(chartData)); diff --git a/src/com/fr/solution/plugin/chart/echarts/base/NewGlyph.java b/src/com/fr/solution/plugin/chart/echarts/base/NewGlyph.java index a8f470d..c6c3237 100644 --- a/src/com/fr/solution/plugin/chart/echarts/base/NewGlyph.java +++ b/src/com/fr/solution/plugin/chart/echarts/base/NewGlyph.java @@ -32,41 +32,29 @@ public class NewGlyph extends ChartGlyph { @Override public JSONObject toJSONObject(Repository repo) throws JSONException { JSONObject jo = new JSONObject(); - jo.put("title", createTitle(repo)); -// if (titleGlyph != null) { -// jo.put("title", titleGlyph.toJSONObject(repo)); -// } + //jo.put("title", createTitle(repo)); + if (titleGlyph != null) { + jo.put("title", titleGlyph.toJSONObject(repo)); + } jo.put("tooltip", createTooltip(repo)); - jo.put("legend", createLegend(repo)); +// jo.put("legend", createLegend(repo)); -// if (legendGlyph != null) { -// jo.put("legend", legendGlyph.toJSONObject(repo)); -// } + if (legendGlyph != null) { + jo.put("legend", legendGlyph.toJSONObject(repo)); + } jo.put("dataRange", createDataRange(repo)); jo.put("series", createSeries(repo)); return jo; } - private JSONObject createTitle(Repository repo) throws JSONException { - return JSONObject.create() - .put("text", "iPhone销量") - .put("subtext", "纯属虚构") - .put("x", "center"); - } private JSONObject createTooltip(Repository repo) throws JSONException { return JSONObject.create() .put("trigger", "item"); } - private JSONObject createLegend(Repository repo) throws JSONException { - return JSONObject.create() - .put("orient", "vertical") - .put("x", "left") - .put("data", JSONArray.create().put("iPhone3").put("iPhone4").put("iPhone5")); - } private JSONObject createDataRange(Repository repo) throws JSONException { return JSONObject.create() diff --git a/src/com/fr/solution/plugin/chart/echarts/base/NewLegendGlyph.java b/src/com/fr/solution/plugin/chart/echarts/base/NewLegendGlyph.java index c4fe1d6..c56afcb 100644 --- a/src/com/fr/solution/plugin/chart/echarts/base/NewLegendGlyph.java +++ b/src/com/fr/solution/plugin/chart/echarts/base/NewLegendGlyph.java @@ -1,9 +1,25 @@ package com.fr.solution.plugin.chart.echarts.base; import com.fr.chart.chartglyph.LegendGlyph; +import com.fr.json.JSONArray; +import com.fr.json.JSONException; +import com.fr.json.JSONObject; +import com.fr.stable.web.Repository; /** * Created by richie on 16/2/2. */ public class NewLegendGlyph extends LegendGlyph { + + @Override + public JSONObject toJSONObject(Repository repo) throws JSONException { + return createLegend(repo); + } + + private JSONObject createLegend(Repository repo) throws JSONException { + return JSONObject.create() + .put("orient", "vertical") + .put("x", "left") + .put("data", JSONArray.create().put("iPhone3").put("iPhone4").put("iPhone5")); + } } diff --git a/src/com/fr/solution/plugin/chart/echarts/base/NewPlot.java b/src/com/fr/solution/plugin/chart/echarts/base/NewPlot.java index 44f209f..7cda0fc 100644 --- a/src/com/fr/solution/plugin/chart/echarts/base/NewPlot.java +++ b/src/com/fr/solution/plugin/chart/echarts/base/NewPlot.java @@ -13,6 +13,8 @@ public abstract class NewPlot extends Plot { return ComparatorUtils.equals(NewPlot.class, obClass); } + + public NewTitleGlyph createChartTitleGlyph(ChartData chartData) { return new NewTitleGlyph("iPhone", "iPhone"); } diff --git a/src/com/fr/solution/plugin/chart/echarts/base/NewTitleGlyph.java b/src/com/fr/solution/plugin/chart/echarts/base/NewTitleGlyph.java index a121123..fc106a6 100644 --- a/src/com/fr/solution/plugin/chart/echarts/base/NewTitleGlyph.java +++ b/src/com/fr/solution/plugin/chart/echarts/base/NewTitleGlyph.java @@ -17,7 +17,14 @@ public class NewTitleGlyph extends ChartGlyph { @Override public JSONObject toJSONObject(Repository repo) throws JSONException { - return super.toJSONObject(repo); + return createTitle(repo); + } + + private JSONObject createTitle(Repository repo) throws JSONException { + return JSONObject.create() + .put("text", "iPhone销量") + .put("subtext", "纯属虚构") + .put("x", "center"); } }