1.所需要的jar包 jfreechar-1.0.10.jar
2.生成图的class 方法:
package data.pub.jfree;
import java.awt.Color;
import java.awt.RenderingHints;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.DateTickUnit;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.SegmentedTimeline;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.Marker;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.time.Minute;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.LengthAdjustmentType;
import org.jfree.ui.RectangleAnchor;
import org.jfree.ui.TextAnchor;
import common.dataAccess.util.As;
import common.dataAccess.util.FileUtils;
import common.dataAccess.util.Property;
import common.dataAccess.util.ResourceUtils;
import data.pub.index.IndexTodayMin;
import data.pub.util.DateUtils;
/**
* 指数日内走势图
* @author yyao
*/
public class IndexRtChart{
/**
*
*/
private static final long serialVersionUID = 1L;
private static int stye = 0;
private static double min;
private static double max;
private static double close;
public static JFreeChart getChart(List<Map<String, String>> data) {
return createChart(getPreClose(data), createDatasetBackgroud(data));
}
private static JFreeChart createChart(double preClose,XYDataset datasetBack) {
JFreeChart chart = ChartFactory.createXYAreaChart(
"",
"", "",
datasetBack,
PlotOrientation.VERTICAL,
true, // legend
true, // tool tips
false // URLs
);
chart.setBackgroundPaint(ChartColors.TABLE_BACKGROUND_outside);
chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(ChartColors.BARCHART_BACKGROUND);
plot.setOutlinePaint(ChartColors.PLOT_GRIDDING);
plot.setDomainGridlinesVisible(true);
plot.setForegroundAlpha(0.5f);
ChartCommons.setPlotLineColor(plot);
// plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);// 左边轴移到右边显示
ValueAxis domainAxis = new DateAxis("");
domainAxis.setLowerMargin(0.00001);
domainAxis.setUpperMargin(0.001);
plot.setDomainAxis(domainAxis);
ValueAxis range = new NumberAxis();
range.setLowerBound(getMin());
range.setUpperBound(getMax());
plot.setRangeAxis(range);
XYItemRenderer renderer = plot.getRenderer();
renderer.setSeriesPaint(0, ChartColors.Market_FILL); //阴影色
ChartCommons.setXAxis(plot);
ChartCommons.setYAxis(plot);
//处理时间轴 过滤非交易时段 x 轴 1801 *倍数控制横向显示
SegmentedTimeline timeline = new SegmentedTimeline(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE, 36, 60);
timeline.setBaseTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());
timeline.addException(12600000, 17600000);
((DateAxis) domainAxis).setTimeline(timeline);
((DateAxis) domainAxis).setTickUnit(
new DateTickUnit(
DateTickUnit.SECOND, 2701, new SimpleDateFormat("HH:mm")));
((DateAxis) domainAxis).setMaximumDate(DateUtils.parseDate("197001011500", "yyyyMMddhhmm"));
((DateAxis) domainAxis).setMinimumDate(DateUtils.parseDate("197001010930", "yyyyMMddhhmm"));
//Line renderer
XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer();
renderer1.setSeriesPaint(0, ChartColors.Market_LINE_1);
renderer1.setSeriesLinesVisible(0, true);
renderer1.setSeriesShapesVisible(0, false);
renderer1.setBaseShapesVisible(true);
renderer1.setBaseShapesFilled(true);
plot.setRenderer(1, renderer1);
plot.setDataset(1, (TimeSeriesCollection)datasetBack);
//标记昨日收盘价
Marker target = new ValueMarker(preClose);
target.setLabelOffsetType(LengthAdjustmentType.EXPAND);
target.setPaint(Color.BLACK);
target.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
target.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
plot.addRangeMarker(target);
chart.removeLegend();
//Legend
// LegendTitle legend = chart.getLegend();
// legend.setMargin(new RectangleInsets(2, 2, 2, 2));
// legend.setFrame(new BlockBorder());
// legend.setBorder(0, 0, 0, 0);
// legend.setItemPaint(new Color(0x666666));
// legend.setItemFont(new Font("SimSun", Font.PLAIN, 12));
// BlockContainer container = new BlockContainer(new BorderArrangement());
// container.add(legend, RectangleEdge.LEFT);
// container.add(new EmptyBlock(270, 0));//值越小
// CompositeTitle legends = new CompositeTitle(container);
// legends.setPosition(RectangleEdge.TOP);
// chart.addSubtitle(legends);
// chart.removeSubtitle(chart.getSubtitle(0));
return chart;
}
//主线&&阴影
private static XYDataset createDatasetBackgroud(List<Map<String, String>> data) {
String name = "昨日收盘价";
TimeSeries series1 = new TimeSeries(name);
SimpleDateFormat format = new SimpleDateFormat("hhmm");
List<Double> list = new ArrayList<Double>();
for (int i = 0; i < data.size(); i++) {
try {
Map<String, String> hashmap = data.get(i);
if (isNotNull(hashmap.get("close"))) {
list.add(Double.parseDouble(hashmap.get("close").toString()));
}
String tradetime = hashmap.get("trad_time");
String today_open = hashmap.get("close");
Date date = format.parse(tradetime);
series1.addOrUpdate(new Minute(date), Double.parseDouble(today_open));
} catch (Exception e) {
e.printStackTrace();
}
}
setMin(list);
setMax(list);
TimeSeriesCollection dataset = new TimeSeriesCollection(series1);
return dataset;
}
//昨日收盘价
private static Double getPreClose(List<Map<String, String>> data) {
if (data.size() <=0) return null;
Double preClose = Double.parseDouble(data.get(0).get("pre_close"));
return preClose;
}
/*
* 验证数据是否为空
*/
public static boolean isNotNull(String str) {
if (str == null || "".equals(str) || "null".equalsIgnoreCase(str) || "N/A".equals(str)) {
return false;
}
return true;
}
//处理Y轴最高点和最低点
public static double getMin() {
return min;
}
public static void setMin(List<Double> list) {
double min = Collections.min(list);
if (getClose() > 0.0 && min > getClose()) {
min = getClose();
min = min - min * 0.005;
} else {
min = min - min * 0.005;
}
IndexRtChart.min = min;
}
public static double getMax() {
return max;
}
public static void setMax(List<Double> list) {
double max = Collections.max(list);
if (max < getClose()) {
max = getClose();
max = max * 0.005 + max;
} else {
max = max * 0.005 + max;
}
IndexRtChart.max = max;
}
public static int getStye() {
return stye;
}
public static void setStye(int stye) {
IndexRtChart.stye = stye;
}
public static double getClose() {
return close;
}
public static void setClose(double close) {
IndexRtChart.close = close;
}
/*
* 生成走势图--大图
* 500*300
*/
public static String get_pic_big(List<Map<String,String>> chartData,String security_code){
String picUrl = "";
if(chartData.size() > 0){
//调用画图接口
JFreeChart jchart = getChart(chartData);
String filePath = ResourceUtils.getPicPath();
picUrl = filePath + security_code + "b" + ".png";
//生成PNG
File chartfile = new File(picUrl);
try {
ChartUtilities.saveChartAsPNG(chartfile, jchart, 500, 300, null);
} catch (IOException e) {
e.printStackTrace();
}
}
return picUrl;
}
/*
* 生成走势图--小图
* 183*114
*/
public static String get_pic_small(List<Map<String,String>> chartData,String security_code){
String picUrl = "";
if(chartData.size() > 0){
//调用画图接口
JFreeChart jchart = getChart(chartData);
String filePath = ResourceUtils.getPicPath();
picUrl = filePath + security_code + "s" + ".png";
//生成PNG
File chartfile = new File(picUrl);
try {
ChartUtilities.saveChartAsPNG(chartfile, jchart, 213, 133, null);
} catch (IOException e) {
e.printStackTrace();
}
}
return picUrl;
}
/**
* 指数的当天分钟走势图,每天早起08点初始化
*/
public static void careat_index_chart()
{
Properties pro = Property.getProperties(ResourceUtils.getChartPath());
String index_code = pro.getProperty("chart_index_code");
String[] index_codes = index_code.split(";");
for(int i=0;i<index_codes.length;i++){//循环生成指数走势图
String security_code = index_codes[i];
List<Map<String, String>> data_list = get_data(security_code);
if(data_list!=null && data_list.size()!=0)
{
get_pic_small(data_list,security_code);//生成小图
get_pic_big(data_list,security_code);//生成大图
}
}
}
private static List<Map<String, String>> get_data(String index_code)
{
List<Map<String, String>> index_list = new ArrayList<Map<String, String>>();
List<IndexTodayMin> list_temp = IndexTodayMin.get_list();
for(int i=0;i<list_temp.size();i++)
{
Map<String,String> map = new HashMap<String,String>();
//String key_id = (list_temp.get(i)).getSecurity_code() + (list_temp.get(i)).getTrad_time();
if(index_code.equals(list_temp.get(i).getSecurity_code()))
{
map.put("security_code", list_temp.get(i).getSecurity_code());
map.put("trad_time", list_temp.get(i).getTrad_time());
map.put("pre_close", ""+list_temp.get(i).getPreClose());
map.put("close", ""+list_temp.get(i).getClose());
index_list.add(map);
}
}
return index_list;
}
/*
* 测试方法
*/
public static void main(String[] args) {
/*DBHandler handler2 = DBHandler.getORADBHandler();
try
{
chartData = AccessUtils.select("INDEX_CHART_TEMP", null, handler2);
}
finally
{
handler2.close();
}
//调用画图接口
JFreeChart jchart = getChart(chartData);
try {
ChartPanel panel = new ChartPanel(jchart);
JFrame frame = new JFrame();
frame.add(panel);
frame.setSize(500, 400);
RefineryUtilities.centerFrameOnScreen(frame);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
//生成PNG
File chartfile = new File("D://399300"+ ".png");
try {
ChartUtilities.saveChartAsPNG(chartfile, jchart, 500, 300, null);
} catch (IOException e) {
e.printStackTrace();
}
*/
careat_index_chart();
System.out.println("end!!!!!!");
}
}
3.需要引入的页面:
package data.pub.jfree;
import java.awt.Color;
import java.awt.GradientPaint;
public class ChartColors {
// public
public static Color KCHART_UP = new Color(0xCC0033);
public static Color KCHART_DOWN = new Color(0x00A1FD);
public static Color KCHART_LINE_5 = new Color(0x010101);
public static Color KCHART_LINE_10 = new Color(0x0000FD);
public static Color KCHART_LINE_20 = new Color(0xFF00CC);
public static GradientPaint Market_FILL = new GradientPaint(0.0f, 0.0f, new Color(0xDDE9FD), 0.0f, 130.0f, new Color(0xDDE9FD), true);
public static Color Market_LINE_1 = new Color(0x006699);
public static Color Market_LINE_2 = new Color(0xFF9900);
public static Color Market_LINE_3 = new Color(0x339900);
public static Color Market_LINE_4 = new Color(0xCC3366);
public static Color Market_LINE_5 = new Color(0x996699);
public static Color Market_LINE_6 = new Color(0x999999);
public static Color Market_TABLE_BACKGROUND_inside = new Color(0xD8D8D8);
public static Color Market_BAR_1 = new Color(0x5081AC);
public static Color TABLE_BACKGROUND = new Color(0xE1E1E1);
public static Color TABLE_BACKGROUND_outside = new Color(0xFFFFFF);
public static Color TABLE_BACKGROUND_inside = new Color(0xE1E1E1);
public static Color TABLE_0_LINE = new Color(0x999999);
public static Color FILL_AREA = new Color(0xFFFFFF);
public static Color FILL_LINE = new Color(0x336799);
public static Color TICK_LABEL = new Color(0x323232);
public static Color TABLE_LINE = new Color(0xA2C1FF);
public static GradientPaint FUND_EA_BAR_UP = new GradientPaint(0.0f, 0.0f, new Color(0xCC3300), 0.0f, 0.0f, new Color(0xF08879), false);
public static GradientPaint FUND_EA_BAR_DOWN = new GradientPaint(0.0f, 0.0f, new Color(0x339900), 0.0f, 0.0f, new Color(0x99DF66), false);
public static Color SHADE_FROM = new Color(0x94B8FF);
public static Color SHADE_TO = new Color(0x538DFE);
public static Color JYYC_O1 = new Color(0x00A2FF);
public static Color JYYC_O2 = new Color(0x3266CC);
public static Color JYYC_O3 = new Color(0xFF7A78);
public static Color JYYC_O4 = new Color(0xFF5E5B);
public static Color MARKET_THYSZBZ_O1 = Color.RED;//new Color(0x00A2FF);
public static Color MARKET_THYSZBZ_O2 = Color.BLUE;//new Color(0x3266CC);
public static Color MARKET_THYSZBZ_O3 = Color.GREEN;//new Color(0x3266CC);
public static Color MARKET_THYSZBZ_BACK_O1 = Color.RED;//new Color(0xFF7A78);
public static Color MARKET_THYSZBZ_BACK_O2 = Color.BLUE;//new Color(0xFF5E5B);
public static Color MARKET_THYSZBZ_BACK_O3 = Color.GREEN;//new Color(0xFF5E5B);
public static Color JYYC_UP_OUT = new Color(0x5982D0);
public static Color JYYC_DOWN_OUT = new Color(0xBF0400);
public static Color DASHED = new Color(0xD3D3D3);
public static Color BAR_UP = new Color(0x7AA7FF);
public static Color BAR_DOWN = new Color(0xFF5E5B);
public static GradientPaint HFA6_BAR_UP_2 = new GradientPaint(0.0f, 8.0f, new Color(0xB2D6DE), 0.0f, 0.0f, new Color(0x006699), false);
public static GradientPaint HFA6_BAR_UP = new GradientPaint(0.0f, 8.0f, new Color(0x006699), 0.0f, 0.0f, new Color(0xB2D6DE), false);
public static GradientPaint HFA6_BAR_DOWN = new GradientPaint(0.0f, 8.0f, new Color(0xFE9B04), 0.0f, 0.0f, new Color(0xFECA63), false);
public static GradientPaint RV_DOWN_CO = new GradientPaint(0.0f, 8.0f, new Color(0xCC3401), 0.0f, 0.0f, new Color(0xEF8676), false);
public static GradientPaint RV_UP_CO = new GradientPaint(0.0f, 8.0f, new Color(0xFE9B04), 0.0f, 0.0f, new Color(0xFECA63), false);
public static Color MARKET_BAR_DOWN = new Color(0x7AA7FF);
public static Color MARKET_BAR_UP = new Color(0xFF5E5B);
public static Color BAR_UP_FRAME = new Color(0x3266C);
public static Color BAR_DOWN_FRAME = new Color(0xA20300);
public static Color HFA6_BAR_UP_FRAME = new Color(0x006699);
public static Color HFA6_BAR_DOWN_FRAME = new Color(0xCC3300);
public static Color THREE_LINE_01 = new Color(0x006699);
public static Color THREE_LINE_02 = new Color(0xFF9900);
public static Color THREE_LINE_03 = new Color(0x339900);
public static Color FOUR_LINE_01 = new Color(0xCC0033);
public static Color FOUR_LINE_02 = new Color(0x3266CC);
public static Color FOUR_LINE_03 = new Color(0x2B912D);
public static Color FOUR_LINE_04 = new Color(0xFFC600);
public static GradientPaint FIVE_BAR_01 = new GradientPaint(0.0f, 0.0f, new Color(0x1975A2), 0.0f, 0.0f, new Color(0xB2D6DE), false);
public static GradientPaint FIVE_BAR_02 = new GradientPaint(0.0f, 0.0f, new Color(0xF9A508), 0.0f, 0.0f, new Color(0xF6EF8F), false);
public static GradientPaint FIVE_BAR_03 = new GradientPaint(0.0f, 0.0f, new Color(0x9FCC00), 0.0f, 0.0f, new Color(0xC9CC00), false);
public static GradientPaint FIVE_BAR_04 = new GradientPaint(0.0f, 0.0f, new Color(0xF35C8E), 0.0f, 0.0f, new Color(0xFEAAAB), false);
public static GradientPaint FIVE_BAR_05 = new GradientPaint(0.0f, 0.0f, new Color(0x9A97C9), 0.0f, 0.0f, new Color(0xDCDCDE), false);
/**
* 行业资金流量图 超大宗 大宗 非大宗
*/
public static Color HYZJLL_UP_01 = new Color(0xBD3102);
public static Color HYZJLL_UP_02 = new Color(0xE2684C);
public static Color HYZJLL_UP_03 = new Color(0xF7B6AC);
public static Color HYZJLL_DOWN_01 = new Color(0x226501);
public static Color HYZJLL_DOWN_02 = new Color(0x69BF36);
public static Color HYZJLL_DOWN_03 = new Color(0xB9EA95);
public static GradientPaint FIVE_BAR_01_DOWN = new GradientPaint(0.0f, 0.0f, new Color(0xB2D6DE), 0.0f, 0.0f, new Color(0x1975A2), false);
public static GradientPaint FIVE_BAR_02_DOWN = new GradientPaint(0.0f, 0.0f, new Color(0xF6EF8F), 0.0f, 0.0f, new Color(0xF9A508), false);
public static GradientPaint FIVE_BAR_03_DOWN = new GradientPaint(0.0f, 0.0f, new Color(0x9DCC00), 0.0f, 0.0f, new Color(0x9FCC00), false);
public static GradientPaint FIVE_BAR_04_DOWN = new GradientPaint(0.0f, 0.0f, new Color(0xFEAAAB), 0.0f, 0.0f, new Color(0xF35C8E), false);
public static GradientPaint FIVE_BAR_05_DOWN = new GradientPaint(0.0f, 0.0f, new Color(0xDCDCDE), 0.0f, 0.0f, new Color(0x9A97C9), false);
public static Color FIVE_BAR_OUT_LINE_01 = new Color(0x006699);
public static Color FIVE_BAR_OUT_LINE_02 = new Color(0xFE9900);
public static Color FIVE_BAR_OUT_LINE_03 = new Color(0x339900);
public static Color FIVE_BAR_OUT_LINE_04 = new Color(0xCC3366);
public static Color FIVE_BAR_OUT_LINE_05 = new Color(0x996699);
public static Color FHFA_BAR_05 = new Color(0x00C15F);
public static Color RV_BAR_01 = new Color(0x3266CC);
//local
public static Color AQR_LINE_01 = new Color(0xD75E86);
public static Color AQR_LINE_02 = new Color(0x006699);
public static Color AQR_LINE_03 = new Color(0x339900);
public static Color AQR_LINE_04 = new Color(0xFF9900);
public static GradientPaint AQR_BAR_01 = new GradientPaint(0.0f, 0.0f, new Color(0xCC3300), 0.0f, 0.0f, new Color(0xF08879), false);
public static Color AQR_BAR_02 = new Color(0xFFFF66);
public static GradientPaint AQR_BAR_03 = new GradientPaint(0.0f, 0.0f, new Color(0x339900), 0.0f, 0.0f, new Color(0x99DF66), false);
public static Color LEGEND_BORDER = new Color(0x919191);
public static Color DDIS_BAR_UP = new Color(0x3266CC);
public static Color DDIS_BAR_DOWN = new Color(0xCC0033);
public static Color BETA_POINT = new Color(0x006699);
public static Color BETA_NEW_POINT = new Color(0xFF0000);
public static Color BETA_TABLE = new Color(0xA2C1FF);
public static Color BETA_LINE = new Color(0xAED79A);
public static Color GIM_LINE = new Color(0x006699);
public static Color GIM_LINE_VWAP = new Color(0xFF9900);
public static GradientPaint GIM_BAR_UP = new GradientPaint(0.0f, 0.0f, new Color(0xCC3300), 0.0f, 0.0f, new Color(0xF08879), false);
public static GradientPaint GIM_BAR_DOWN = new GradientPaint(0.0f, 0.0f, new Color(0x99DF66), 0.0f, 0.0f, new Color(0x339900), false);
public static GradientPaint GIM_BAR_DOWN_02 = new GradientPaint(0.0f, 0.0f, new Color(0x339900), 0.0f, 0.0f, new Color(0x99DF66), false);
public static Color GM_BAR_01 = new Color(0x3266CC);
public static Color GM_BAR_02 = new Color(0xCC0033);
public static Color GM_LINE_01 = new Color(0x006699);
public static Color GM_LINE_02 = new Color(0xCC00CC);
public static Color GM_LINE_03 = new Color(0xFF9900);
public static Color GM_LINE_VWAP = new Color(0xCC3366);
public static Color WACC_PIE_03 = new Color(0xB4D5E8);
public static Color HS_lINE_01 = new Color(0x3266CC);
public static Color HS_lINE_02 = new Color(0xCD00C9);
public static Color HS_PLANE_01 = new Color(0xFFA8A8);
public static Color HS_PLANE_02 = new Color(0xAAF3AA);
public static Color JGPJTJ_LINE = new Color(0x2D6191);
public static Color JGPJTJ_FILL = new Color(0xC1D0EF);
/*饼图颜色*/
private static Color PIE_01 = new Color(0xFB8873);
private static Color PIE_02 = new Color(0xD199CA);
private static Color PIE_03 = new Color(0xFDA965);
private static Color PIE_04 = new Color(0xC0DC8E);
private static Color PIE_05 = new Color(0xFEE679);
private static Color PIE_06 = new Color(0xB3D5E7);
private static Color PIE_07 = new Color(0x73A79F);
private static Color PIE_08 = new Color(0xD3C57D);
private static Color PIE_09 = new Color(0xB3C1DD);
private static Color PIE_10 = new Color(0xF0C26C);
private static Color PIE_11 = new Color(0x79C7A0);
private static Color PIE_12 = new Color(0xFEA33D);
private static Color PIE_13 = new Color(0xC8676E);
private static Color PIE_14 = new Color(0x95A289);
private static Color PIE_15 = new Color(0xA3D881);
private static Color PIE_16 = new Color(0x8A7264);
private static Color PIE_17 = new Color(0x85A789);
private static Color PIE_18 = new Color(0xE3B7DA);
private static Color PIE_19 = new Color(0xCF9B64);
private static Color PIE_20 = new Color(0xB0B5CD);
private static Color PIE_21 = new Color(0xA394BE);
private static Color PIE_22 = new Color(0xD67EAE);
public static Color[] PIE_COLORS = {
PIE_01, PIE_02, PIE_03, PIE_04, PIE_05,
PIE_06, PIE_07, PIE_08, PIE_09, PIE_10,
PIE_11, PIE_12, PIE_13, PIE_14, PIE_15,
PIE_16, PIE_17, PIE_18, PIE_19, PIE_20,
PIE_21, PIE_22,};
/*柱体渐变开始颜色01*/
static Color BARSHADEBEG_01 = new Color(0x006699);
/*柱体渐变结束颜色01*/
static Color BARSHADEEND_01 = new Color(0xC2E0E4);
/*柱体渐变开始颜色02*/
static Color BARSHADEBEG_02 = new Color(0x99CCCC);
/*柱体渐变结束颜色02*/
static Color BARSHADEEND_02 = new Color(0xE6F2F9);
/*柱体上部边框颜色*/
public static Color BAR_SHADE_BORDER = new Color(0x006699);
/*柱体渐变颜色01*/
public static GradientPaint BARCHART_GRADIENTPAINT_01 = new GradientPaint(0.0f, 0.0f, BARSHADEBEG_01, 0.0f, 0.0f, BARSHADEEND_01, false);
/*柱体渐变颜色02*/
public static GradientPaint BARCHART_GRADIENTPAINT_02 = new GradientPaint(0.0f, 0.0f, BARSHADEBEG_02, 0.0f, 0.0f, BARSHADEEND_02, false);
/*柱体PLOT背景颜色*/
public static Color BARCHART_BACKGROUND = new Color(0xFFFFFF);
/*纵向网格颜色*/
public static Color BARCHART_GRIDDING_Y = new Color(0xBBBBBB);
/*横向网格颜色*/
public static Color BARCHART_GRIDDING_X = new Color(0xBBBBBB);
/*PLOT边框颜色*/
public static Color PLOT_GRIDDING = new Color(0xBBBBBB);
/*线图颜色 第一根线*/
public static Color LINE_COLOR_01 = new Color(0x006699);
public static Color LINE_COLOR_02 = new Color(0xFF9900);
public static Color LINE_COLOR_03 = new Color(0x339900);
public static Color LINE_COLOR_04 = new Color(0xCC3366);
public static Color LINE_COLOR_05 = new Color(0x996699);
}
package data.pub.jfree;
import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.XYPlot;
/**
* Chart统一处理类 包括xAxis yAxis BackGround Gridline
* @author yyao
*
*/
public class ChartCommons {
/**
* 设置plot背景颜色渐变
* set default color to black
* @param plot
*/
protected static void setBackGroudVerticalGradual(Plot plot) {
setBackGroudVerticalGradual(plot, Color.black);
}
protected static void setBackGroudVerticalGradual(Plot plot, Color toColor) {
GradientPaint gradientpaint =
new GradientPaint(0.0F, 0.0F, toColor, 0.0F, 0.0F, new Color(0xF1, 0xF1, 0xF1), true);
plot.setBackgroundPaint(gradientpaint);
}
protected static void setBackGroudVerticalGradual(Plot plot, Color fromColor, Color toColor) {
GradientPaint gradientpaint =
new GradientPaint(-10.0F, -10.0F, toColor, 0.0F, 0.0F, fromColor, true);
plot.setBackgroundPaint(gradientpaint);
}
/**
* 设置网格颜色 XYPlot
* @param plot
* @param color
*/
protected static void setPlotLineColor(XYPlot plot, Color color) {
plot.setDomainGridlinePaint(color); //网格线纵向颜色
plot.setRangeGridlinePaint(color); //网格线横向颜色
}
/**
* 设置网格颜色 CategoryPlot
* @param plot
* @param color
*/
protected static void setPlotLineColor(CategoryPlot plot, Color color) {
plot.setDomainGridlinePaint(color); //网格线纵向颜色
plot.setRangeGridlinePaint(color); //网格线横向颜色
}
/**
* 设置网格颜色 按照默认的颜色 包括X,Y
* @param plot
*/
protected static void setPlotLineColor(CategoryPlot plot) {
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(ChartColors.BARCHART_GRIDDING_Y);
plot.setDomainGridlinesVisible(true);
plot.setDomainGridlinePaint(ChartColors.BARCHART_GRIDDING_X);
}
/**
* 设置网格颜色 按照默认的颜色 包括X,Y
* @param plot
*/
protected static void setPlotLineColor(XYPlot plot) {
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(ChartColors.BARCHART_GRIDDING_Y);
plot.setDomainGridlinesVisible(true);
plot.setDomainGridlinePaint(ChartColors.BARCHART_GRIDDING_X);
}
/**
* 设置坐标轴线的颜色
* @param plot
* @param color
*/
protected static void setTickLabelPaint(XYPlot plot, Color color) {
plot.getRangeAxis().setTickLabelPaint(color);
plot.getDomainAxis().setTickLabelPaint(color);
}
/**
* 设置Y坐标轴的属性
* @param plot
*/
protected static void setYAxis(XYPlot plot) {
NumberAxis vn = (NumberAxis) plot.getRangeAxis();
//vn.setNumberFormatOverride(new DecimalFormat("0.0%"));
/*y轴说明文字*/
vn.setTickLabelPaint(new Color(0x666666));
vn.setTickLabelFont(new Font("Arial", Font.PLAIN, 11));
/*y轴标签颜色*/
vn.setLabelPaint(new Color(0xBBBBBB));
/*y轴线的颜色*/
vn.setAxisLinePaint(new Color(0xBBBBBB));
/*y轴线Mark颜色*/
vn.setTickMarkPaint(new Color(0xBBBBBB));
// vn.setAxisLineStroke(new BasicStroke(0.0F));
}
protected static void setYAxis(CategoryPlot plot) {
NumberAxis vn = (NumberAxis) plot.getRangeAxis();
//vn.setNumberFormatOverride(new DecimalFormat("0.0%"));
/*y轴说明文字*/
vn.setTickLabelPaint(new Color(0x666666));
vn.setTickLabelFont(new Font("Arial", Font.PLAIN, 11));
/*y轴标签颜色*/
vn.setLabelPaint(new Color(0xBBBBBB));
/*y轴线的颜色*/
vn.setAxisLinePaint(new Color(0xBBBBBB));
/*y轴线Mark颜色*/
vn.setTickMarkPaint(new Color(0xBBBBBB));
// vn.setAxisLineStroke(new BasicStroke(0.0F));
}
/**
* 设置X轴属性
* @param plot
*/
protected static void setXAxis(XYPlot plot) {
ValueAxis vas = ((XYPlot) plot).getDomainAxis();
/*x轴字的颜色*/
vas.setTickLabelPaint(new Color(0x666666));
vas.setTickLabelFont(new Font("Arial", Font.PLAIN, 11));
/*x轴标签颜色*/
vas.setLabelPaint(new Color(0xBBBBBB));
/*x轴线的颜色*/
vas.setAxisLinePaint(new Color(0xBBBBBB));
/*y轴线Mark颜色*/
vas.setTickMarkPaint(new Color(0xBBBBBB));
// vas.setAxisLineStroke(new BasicStroke(0.0F));
}
protected static void setXAxis(CategoryPlot plot) {
CategoryAxis vas = ((CategoryPlot) plot).getDomainAxis();
/*x轴字的颜色*/
vas.setTickLabelPaint(new Color(0x666666));
vas.setTickLabelFont(new Font("Arial", Font.PLAIN, 11));
/*x轴标签颜色*/
vas.setLabelPaint(new Color(0xBBBBBB));
/*x轴线的颜色*/
vas.setAxisLinePaint(new Color(0xBBBBBB));
/*x轴线Mark颜色*/
vas.setTickMarkPaint(new Color(0xBBBBBB));
// vas.setAxisLineStroke(new BasicStroke(0.0F));
}
}