首页>代码>Flash插件FusionCharts,可以做动态报表 包含各种图>/FusionCharts_Evaluation/FusionCharts_Evaluation/Code/JSP/SourceCode/com/fusioncharts/FusionChartsHelper.java
/*
 * Created on Oct 25, 2006
 *
 */
package com.fusioncharts;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.servlet.http.HttpServletResponse;


/**
 * Contains methods to add no cache string to a url,getting colors for the charts.<br>
 * This class can be used to create chart xml given the swf filename and other<br> 
 * parameters.<br>
 * In order to use this class in your jsps,import this class and<br> 
 * call the appropriate method directly as follows:<br>
 * FusionChartsHelper.addCacheToDataURL(...);<br>
 * In order to use this class for colors call the method as shown:<br>
 * FusionChartsHelper helper = new FusionChartsHelper();<BR>
 * String color = helper.getFCColor();<BR>
 * @author InfoSoft Global (P) Ltd.
 */
public class FusionChartsHelper {
	
	/*This page contains an array of colors to be used as default set of colors for FusionCharts
	'arr_FCColors is the array that would contain the hex code of colors 
	'ALL COLORS HEX CODES TO BE USED WITHOUT #*/


	//We also initiate a counter variable to help us cyclically rotate through
	//the array of colors.
	int FC_ColorCounter=0;
	
	String[] arr_FCColors = new String[]{
		"1941A5",
		"AFD8F8",
		"F6BD0F",
		"8BBA00",
		"A66EDD",
		"F984A1",
		"CCCC00", 
		"999999",
		"0099CC",
		"FF0000", 
		"006F00", 
		"0099FF", 
		"FF66CC", 
		"669966",
		"7C7CB4",
		"FF9933",
		"9900FF",
		"99FFCC",
		"CCCCFF",
		"669900",
	};
	/*
	 "1941A5"; //Dark Blue
	 "CCCC00"; //Chrome Yellow+Green
	"999999"; //Grey
	"0099CC"; //Blue Shade
	"FF0000"; //Bright Red 
	"006F00"; //Dark Green
	"0099FF"; //Blue (Light)
	"FF66CC"; //Dark Pink
	"669966"; //Dirty green
	"7C7CB4"; //Violet shade of blue
	"FF9933"; //Orange
	"9900FF"; //Violet
	"99FFCC";//Blue+Green Light
	"CCCCFF"; //Light violet
	"669900"; //Shade of green
	*/
	
	//getFCColor method helps return a color from arr_FCColors array. It uses
	//cyclic iteration to return a color from a given index. The index value is
	//maintained in FC_ColorCounter

	public String getFCColor() {
		//Update index
		FC_ColorCounter += 1;
		//Return color
		return arr_FCColors[FC_ColorCounter % arr_FCColors.length];
		
	}



    /**
     * Adds additional string to the url to and encodes the parameters,<br>
     * so as to disable caching of data.<br>  
     * @param strDataURL -
     *                dataURL to be fed to chart
     * @return cachedURL - URL with the additional string added
     */

    public static String addCacheToDataURL(String strDataURL) {
	String cachedURL = strDataURL;
	// Add the no-cache string if required

	// We add ?FCCurrTime=xxyyzz
	// If the dataURL already contains a ?, we add &FCCurrTime=xxyyzz
	// We replace : with _, as FusionCharts cannot handle : in URLs
	Calendar nowCal = Calendar.getInstance();
	Date now = nowCal.getTime();
	SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH_mm_ss a");
	String strNow = sdf.format(now);

	try {

	    if (strDataURL.indexOf("?") > 0) {
		cachedURL = strDataURL + "&FCCurrTime="
		+ URLEncoder.encode(strNow, "UTF-8");
	    } else {
		cachedURL = strDataURL + "?FCCurrTime="
		+ URLEncoder.encode(strNow, "UTF-8");
	    }

	} catch (UnsupportedEncodingException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	    cachedURL = strDataURL + "?FCCurrTime=" + strNow;
	}

	return cachedURL;
    }

    /**
     * Encodes the dataURL before it's served to FusionCharts.
     * If you have parameters in your dataURL, you necessarily need to encode it.
     * @param strDataURL - dataURL to be fed to chart
     * @param addNoCacheStr - Whether to add additional string to URL to disable caching of data
     * @return String - the encoded URL
     */

    public static String encodeDataURL(String strDataURL, String addNoCacheStr,
	    HttpServletResponse response) {
		String encodedURL = strDataURL;
		//Add the no-cache string if required
		if (addNoCacheStr.equals("true")) {
		    /*We add ?FCCurrTime=xxyyzz
		    If the dataURL already contains a ?, we add &FCCurrTime=xxyyzz
		    We send the date separated with '_', instead of the usual ':' as FusionCharts cannot handle : in URLs
		    */
		    java.util.Calendar nowCal = java.util.Calendar.getInstance();
		    java.util.Date now = nowCal.getTime();
		    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
			    "MM/dd/yyyy HH_mm_ss a");
		    String strNow = sdf.format(now);
		    if (strDataURL.indexOf("?") > 0) {
			encodedURL = strDataURL + "&FCCurrTime=" + strNow;
		    } else {
			strDataURL = strDataURL + "?FCCurrTime=" + strNow;
		    }
		    encodedURL = response.encodeURL(strDataURL);
	
		}
		return encodedURL;
    }
    
    
}
最近下载更多
smallmicro  LV3 2021年1月24日
caozongan  LV19 2020年4月17日
jiqingxings  LV4 2020年3月10日
wanglong_wang  LV13 2019年8月1日
15239218175  LV7 2019年4月22日
lwf626888  LV16 2017年12月6日
dagf113225  LV68 2017年12月1日
chenzheng  LV1 2017年11月27日
wupujian  LV17 2017年11月10日
1324488732  LV27 2017年7月30日
最近浏览更多
fesfefe  LV13 2023年11月1日
yz2810790 2023年7月5日
暂无贡献等级
张顺利  LV6 2023年2月3日
无花空折枝  LV9 2021年6月28日
17558420274  LV16 2021年5月28日
长得丑活得久  LV3 2021年3月4日
smallmicro  LV3 2021年1月24日
daishu14 2020年12月10日
暂无贡献等级
清欢hello  LV3 2020年6月18日
hxx88781143  LV8 2020年5月19日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友