All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.janeluo.jfinalplus.render.chart.funshion.CreateCharts Maven / Gradle / Ivy

There is a newer version: 2.2.0.r3
Show newest version
/**
 * Copyright (c) 2011-2013, kidzhou 周磊 ([email protected])
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.janeluo.jfinalplus.render.chart.funshion;

import com.janeluo.jfinalplus.kit.KeyLabel;
import com.jfinal.kit.StrKit;
import com.jfinal.log.Log;

import java.util.List;

public class CreateCharts {

    protected static final Log LOG = Log.getLog(CreateCharts.class);

    // private static Configuration cfg;

    // static {
    // cfg = new Configuration();
    // try {
    // String path=PathKit.getWebRootPath()+"tpo/funshionCharts/flt";
    // File file =new File(path);
    // if(!file.exists()){
    // file.mkdirs();
    // }
    // cfg.setDirectoryForTemplateLoading(file);
    // } catch (IOException e) {
    // logger.error("init freemaker error", e);
    // }
    // //设置FreeMarker模版文件的位置
    // }

    /**
     * 创建报表柱状图,曲线图,区域图
     *
     * @param chart
     *            报表实体
     * @return 创建的字符串
     */
    public static String createChart(PieChart chart) {
        String strXML = "";
        // if (StrKit.isBlank(chart.getFltPath())) { //freemaker模板为空调用list数据源生成xml
        strXML += "";

        List list = chart.getList();

        for (KeyLabel key : list) {
            strXML += "";
        }

        strXML += "";
        // } else {
        // Template t = null;
        // try {
        // t = cfg.getTemplate(chart.getFltPath());
        // } catch (IOException e1) {
        // logger.error("CreateCharts error", e1);
        // }
        //
        // ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
        // Writer out = new OutputStreamWriter(byteArray);
        // try {
        // t.process(chart.getMapRoot(), out);
        // strXML = new String(byteArray.toByteArray());
        // } catch (TemplateException e) {
        // logger.error("CreateCharts TemplateException", e);
        // } catch (IOException e) {
        // logger.error("CreateCharts IOException", e);
        // }
        //
        // }
        FusionCharts charts = new FusionCharts();

        String chartCode = charts.createChartHTML(chart.getCharUrl(), "", strXML, "myNext", chart.getCharWidth(), chart.getCharHigh(),
                false);
        return chartCode;
    }

    public static String createPieChart(PieChart chart) {
        String strXML = "";
        strXML += "";

        List list = chart.getList();

        for (KeyLabel key : list) {
            String tkey = key.getKey();
            if (StrKit.isBlank(tkey)) {
                tkey = "0";
            }

            strXML += "";
        }

        strXML += "";
        FusionCharts charts = new FusionCharts();

        String chartCode = charts.createChartHTML(chart.getCharUrl(), "", strXML, "chartId", chart.getCharWidth(), chart.getCharHigh(),
                false);
        return chartCode;
    }

    /**
     *
     * @param multiCharts
     * @return
     */
    public static String createMultiCharts(GraphChart multiCharts) {
        StringBuffer strXML = new StringBuffer("");
        strXML.append("");
        strXML.append("");
        for (String lable : multiCharts.getLabels()) {
            strXML.append("");
        }
        strXML.append("");
        List seriesName = multiCharts.getLeftSeriesNames();

        List> list = multiCharts.getLeftValues();
        List colors = multiCharts.getColors();
        for (int i = 0; i < seriesName.size(); i++) {
            strXML.append("");
            List values = list.get(i);
            for (int j = 0; j < values.size(); j++) {
                strXML.append("");
            }
            strXML.append("");
        }
        List sSeriesNames = multiCharts.getRightSeriesNames();

        List> slist = multiCharts.getRightValues();

        if (sSeriesNames != null) {
            for (int i = 0; i < sSeriesNames.size(); i++) {
                strXML.append("");
                List values = slist.get(i);
                for (int j = 0; j < values.size(); j++) {
                    strXML.append("");
                }
                strXML.append("");
            }
        }
        strXML.append("");

        FusionCharts charts = new FusionCharts();

        // Create the chart - Column 3D Chart with data from strXML variable
        // using dataXML method
        String chartCode = charts.createChartHTML(multiCharts.getCharUrl(), "", strXML.toString(), "myNext", multiCharts.getCharWidth(),
                multiCharts.getCharHigh(), false);
        return chartCode;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy