package com.cs.jfreechart; import java.awt.Color; import java.awt.Font; import java.io.FileOutputStream; import java.io.IOException; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.title.LegendTitle; import org.jfree.chart.title.TextTitle; import org.jfree.data.time.Month; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; import org.jfree.data.xy.XYDataset; public class TimeChartDemo { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { //生成时间顺序图 JFreeChart chart = ChartFactory.createTimeSeriesChart ( "图书销售统计表", //图表标题 "图书", //目录轴的显示标签 "销量", //数值轴的显示标签 getDateSet(), //数据 //PlotOrientation.HORIZONTAL, //图表方向水平 //PlotOrientation.VERTICAL, //图表方向垂直 true, //是否显示图例 false, //是否显示工具提示 false //是否生成URL ); //设置标题及标题字体 chart.setTitle(new TextTitle("图书销售统计图",new Font("黑体",Font.ITALIC,22))); //建一个图例 LegendTitle legendTitle = chart.getLegend(0); //设置图例字体 legendTitle.setItemFont(new Font("宋体",Font.BOLD,14)); //获取时间顺序图plot对象 XYPlot plot = (XYPlot) chart.getPlot(); //设置柱型的颜色 plot.getRenderer().setSeriesPaint(0, Color.blue); //取得横轴 ValueAxis categoryAxis = plot.getDomainAxis(); //设置横轴的字体 categoryAxis.setLabelFont(new Font("宋体",Font.BOLD,22)); //设置分类标签以45度倾斜 //categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); //设置分类标签字体 categoryAxis.setTickLabelFont(new Font("宋体",Font.BOLD,22)); //取得纵轴 NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); //设置纵轴的字体 numberAxis.setLabelFont(new Font("宋体",Font.BOLD,22)); //设置背景透明度(0~1) plot.setBackgroundAlpha(0.9f); //输出文件 FileOutputStream fos = new FileOutputStream("book.jpg"); //用ChartUtilities工具输出 ChartUtilities.writeChartAsJPEG(fos, chart, 800, 600); fos.close(); } private static XYDataset getDateSet() { //创建一个TimeSeries对象 TimeSeries spring = new TimeSeries("JAVA教程",Month.class); spring.add(new Month(10,2006),34); spring.add(new Month(11,2006),27); spring.add(new Month(12,2006),31); spring.add(new Month(1,2007),17); spring.add(new Month(2,2007),39); TimeSeries lightweight = new TimeSeries("C#教程",Month.class); lightweight.add(new Month(10,2006),28); lightweight.add(new Month(11,2006),32); lightweight.add(new Month(12,2006),11); lightweight.add(new Month(1,2007),19); lightweight.add(new Month(2,2007),12); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(spring); dataset.addSeries(lightweight); return dataset; } }
详细解决方案
施用JFreeChart创建时间顺序图
热度:107 发布时间:2012-11-18 10:51:22.0
相关解决方案
- JfreeChart 跟 HighChart比较,哪个更方便,更强大
- struts+jfreechart,路径有关问题
- JFreechart 在页面Map能够链接,但是放进action就报错,该怎么处理
- JfreeChart 和 HighChart比较,哪个更方便,更强大,该怎么处理
- jfreechart 怎么设置柱子之间的间距
- jfreechart 怎么在柱状图中画一条平均线
- jfreechart 除开灰色背景
- 用cewolf+jFreeChart 开发WEB 图形表格
- JFreeChart x y轴 出现汉语 乱码
- jfreechart 柱状图示范- 平面效果
- jfreechart 柱状图示范- 3D效果
- jfreechart 饼状图示范- 3D效果
- JFreeChart 汉语API
- JfreeChart 如何设置百分比的小数位
- jFreeChart 在tomcat temp目录下生成的临时文件 怎么办啊
- jfreechart,jsp解决方法
- JFreeChart 如何改变TIP
- JFreeChart 1.0.14 乱码
- jfreechart (急)在一个网页展示多张报表
- jfreechart,如何设置第二个dataset的颜色
- jfreechart 线条图不能出现工具提示解决方法
- jfreechart 连接有关问题
- 怎么让 JFreeChart 刻度 加权 显示
- 关于 JFreeChart 柱状图 设置有关问题,大家来看看
- Struts2 与 JFreeChart plug in 使用有关问题
- jfreechart 实现K线图好折线图的组合有关问题
- Unable to find parent packages jfreechart-default,该如何处理
- jfreechart ,该如何解决
- JfreeChart 时间格式有关问题
- jFreeChart,怎么把数据库的数据放入dataset数据集中