【仅供内部供应商使用,不提供对外解答和培训】

Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
public class TableDataContentPane extends AbstractTableDataContentPane {

    private UIComboBox dateComboBox;

    private UIComboBox valueComboBox;

    public TableDataContentPane(ChartDataPane parent) {

        dateComboBox = new UIComboBox();
        valueComboBox = new UIComboBox();
		dateComboBox.setPreferredSize(new Dimension(100, 20));
  		valueComboBox.setPreferredSize(new Dimension(100, 20));

        Component[][] components = new Component[][]{


            new Component[]{new UILabel("名称", SwingConstants.RIGHT), dateComboBox},

            new Component[]{new UILabel("值", SwingConstants.RIGHT), valueComboBox}};

        	double p = TableLayout.PREFERRED;
	        double[] columnSize = {p, p};
	        double[] rowSize = {p, p, p};


        JPanel panel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);

        setLayout(new BorderLayout());

        add(panel, BorderLayout.CENTER);
    }

    @Override

    public void populateBean(ChartCollection collection) {
      
		DefaultTableDataDefinition configuration = (DefaultTableDataDefinition)
		collection.getSelectedChart().getFilterDefinition();

        if (configuration == null) return;

        combineCustomEditValue(dateComboBox, configuration.getDate());
        combineCustomEditValue(valueComboBox, configuration.getValue());
    }

    @Override

    public void updateBean(ChartCollection ob) {

    	DefaultTableDataDefinition myConfiguration = new DefaultTableDataDefinition();
        Object wname = dateComboBox.getSelectedItem();
        Object wvalue = valueComboBox.getSelectedItem();

        if (wname != null) {
        	myConfiguration.setDate(wname.toString());
        }

        if (wvalue != null) {
        	myConfiguration.setValue(wvalue.toString());
        }

        ob.getSelectedChart().setFilterDefinition(myConfiguration);
    }

    @Override

    public void clearAllBoxList() {
    
		dateComboBox.removeAll();
        valueComboBox.removeAll();
    }

    @Override

    protected void refreshBoxListWithSelectTableData(List columnNameList) {
       
		refreshBoxItems(dateComboBox, columnNameList);
		refreshBoxItems(valueComboBox, columnNameList)
    }
}

第二步,继承TableDataDefinition,定义数据集的定义和查询类,这个类的功能主要是把用户定义的哪个表哪个列这样的信息,转换成真正的数据(比如这一列的所有值),然后将这些查询结果放在3中提到的查询结果存储类。

Code Block
languagejava
public class DefaultTableDataDefinition extends TableDataDefinition {


    public static final String XML_TAG = "DefaultTableDataDefinition";
    private String date;
    private String value;

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Override

    public ChartData createChartData(DataModel resultSet, DataProcessor dataProcessor) {

        Map<String, String> data = new HashMap<>();

        try {


            int wordNameCol = DataCoreUtils.getColumnIndexByName(resultSet, getDate());
            int wordValueCol = DataCoreUtils.getColumnIndexByName(resultSet, getValue());

            Map<Object, List<Object>> map = new HashMap<>();

            for (int rowIndex = 0; rowIndex < resultSet.getRowCount(); rowIndex++) {

                Object wordName = resultSet.getValueAt(rowIndex, wordNameCol);
                Object wordValue = resultSet.getValueAt(rowIndex, wordValueCol);

                if (wordName != null && wordValue != null) {

                    if (!map.containsKey(wordName)) {
                    	map.put(wordName, new ArrayList<>());
                    }
                  
					map.get(wordName).add(wordValue);
                }

            }

            for (Map.Entry<Object, List<Object>> entry : map.entrySet()){

            	data.put(entry.getKey().toString(),
                	entry.getValue().get(0).toString());
            }

        } catch (Exception e) {
           
			FRLogger.getLogger().error(e.getMessage(), e);
        }

        return new TableDataContent(data);
    }

    public void writeXML(XMLPrintWriter writer) {
      
		writer.startTAG(XML_TAG)
        	.attr("date", getDate())               
			.attr("value", getValue());
        super.writeXML(writer);
        writer.end();
    }

    public void readXML(XMLableReader reader) {
       
		super.readXML(reader);

        if (reader.isAttr()) {

            String tmpVal;

            if ((tmpVal = reader.getAttrAsString("date", null)) != null){
            	this.setDate(tmpVal);
            }

            if ((tmpVal = reader.getAttrAsString("value", null)) != null){          
				this.setValue(tmpVal);
            }
        }
    }

    public boolean equals(Object ob) {

        return ob instanceof DefaultTableDataDefinition
&& ComparatorUtils.equals(((DefaultTableDataDefinition) ob).getDate(), this.getDate())
&& ComparatorUtils.equals(((DefaultTableDataDefinition) ob).getValue(), this.getValue())
&& super.equals(ob);
    }

    public Object clone() throws CloneNotSupportedException {
       
		DefaultTableDataDefinition cloned = (DefaultTableDataDefinition) super.clone();
        cloned.setDate(getDate());
        cloned.setValue(getValue());
        return cloned;
    }
}

第三步,继承NormalChartData,定义存储2中提到的查询结果的存储类。

Code Block
languagejava
public class TableDataContent extends NormalChartData {

    private final Map<String, String> data;

	TableDataContent(Map<String, String> data) {
		this.data = data;
    }

    public Map<String, String> getData() {
        return data;
    }
}

第四步,将自定义的数据集面板,覆盖原先默认的。方法是之前有一个继承了AbstractIndependentChartsUI的类,在里边Override这个方法即可。

Code Block
languagejava
@Override

public AbstractTableDataContentPane getTableDataSourcePane(Plot plot, ChartDataPane parent) {

	//这里改成你的类名即可
	return new YourDataContentPane(parent);
}

4)开发JS

echarts.bridge.js文件中定义预览时调用的函数EChartsFactory,主要分为以下几部分:

部分一,function:定义一些参数取值,不需要变。

Code Block
languagejs
EChartsFactory = function(options, $dom) {

    this.options = options;
    this.$dom = $dom;
    this.chartID = options.chartID;
    this.autoRefreshTime = options.autoRefreshTime || 0;
    this.width = options.width || $dom.width();// 补充从dom获取.
    this.height = options.height || $dom.height();
    this.sheetIndex = options.sheetIndex || 0;
    this.ecName = options.ecName || '';
   
	FR.Chart.WebUtils._installChart(this, this.chartID);
};

部分二,prototype:页面展示(如果开发者也是用的Echarts的话,只要自定义prototype即可)

Code Block
languagejs
EChartsFactory.prototype = {


    constructor : EChartsFactory,

    inits : function() {

        //后台传过来的数据或者样式都在 this.options.chartAttr中
        var ct = this.options.chartAttr;

        //新建一个Echarts图表myChart
		var myChart = echarts.init(this.$dom[0]);

        //获取后台传过来的data,并解析
        var data = ct.data;
        var max = 0;

        for (var i = 0; i < data.length; i += 1) {
            if (parseInt(max) < parseInt(data[i][1])) {
                max = data[i][1];
            }
        }

        var year = echarts.number.parseDate(data[0][0]).getFullYear();
        max = max / 20;

        //获取后台传过来的title
        var title = ct.title;

        //设置图表的参数title、tooltip、legend等
        option = {

        }
       
		this.newCharts.setOption(ct);
    },

    resize : function() {
    
		this.newCharts.resize();
    },

    refresh:function() {

    },

    refreshData:function(options){

    },

    //数据监控的刷新方式
    setData:function(options, aimation){

    }
};