JFreechart完整柱状图.docx_第1页
JFreechart完整柱状图.docx_第2页
JFreechart完整柱状图.docx_第3页
JFreechart完整柱状图.docx_第4页
JFreechart完整柱状图.docx_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

JFreechart完整柱状图import java.io.IOException;public class AttendanceMain publicstaticvoidmain(String args) throws IOExceptiondouble data = newdouble100,96,98,95,99,100,92,93,91,94,96,97,96,98,95,99,100,92,93,91,94,96,97,96,98,95,99,100,92,93,91,94,96,97,96,98,95,99,100,92,93,91,94,96;String columnKeys = 测控1班, 测控2班, 信号1班, 信号2班, 信号3班 ,计通1班,计通2班,城轨1班,城轨2班,计应1班,计应2班;String rowKeys=2009级,2010级,2011级,2012级;newAttendance(data,rowKeys,columnKeys );/at.setSubstring(第八周);import java.awt.Color;import java.awt.Font;import java.awt.RenderingHints;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.AxisLocation;import org.jfree.chart.axis.CategoryAxis;import org.jfree.chart.axis.CategoryLabelPositions;import org.jfree.chart.axis.ValueAxis;import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;import org.jfree.chart.plot.CategoryPlot;import org.jfree.chart.plot.PlotOrientation;import org.jfree.chart.renderer.category.BarRenderer;import org.jfree.chart.title.TextTitle;import org.jfree.data.category.CategoryDataset;import org.jfree.data.general.DatasetUtilities;public class Attendance /*private String subtitle;public void setSubstring(String sub)subtitle=sub;*/public Attendance(double data,String rowKeys,String columnKeys )throws IOException CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);JFreeChart chart = ChartFactory.createBarChart( 计算机与通信工程系各班出勤率, /图表标题 班级, /目录轴的显示标签 出勤率(%), /数值轴的显示标签 dataset, /数据集 PlotOrientation.VERTICAL, /图表方向:水平 /PlotOrientation.HORIZONTAL, /图表方向:垂直 true, false, false);/设置背景颜色chart.setBackgroundPaint(Color.cyan);CategoryPlotplot=chart.getCategoryPlot();BarRendererrender=(BarRenderer)plot.getRenderer();render.setBaseOutlinePaint(Color.red);/设置详细图表的显示细节部分的背景颜色plot.setBackgroundPaint(Color.lightGray);/设置垂直网格线颜色plot.setDomainGridlinePaint(Color.black);/设置是否显示垂直网格线plot.setDomainGridlinesVisible(false);/设置水平网格线颜色plot.setRangeGridlinePaint(Color.black);/设置是否显示水平网格线plot.setRangeGridlinesVisible(false);/设置X轴标题的倾斜程度CategoryAxisdomainAxis=plot.getDomainAxis();domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI/6.0);/设置柱状体与图片边框的左右间距domainAxis.setLowerMargin(0.005);domainAxis.setUpperMargin(0.005);/设置柱状体与图片边框的上下间距ValueAxisrAxis=plot.getRangeAxis();rAxis.setUpperMargin(0.05);rAxis.setLowerMargin(0.005);/设置每组柱状体之间的间隔render.setItemMargin(0.01);/设置柱的透明度plot.setForegroundAlpha(1.0f);chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);/设置标题的字体TextTitletextTitle=chart.getTitle();textTitle.setFont(new Font(华文行楷,Font.PLAIN,40);/设置副标题chart.addSubtitle(new TextTitle(第八周);/chart.setTitle(subtitle);/设置X轴坐标上的文字字体domainAxis.setTickLabelFont(new Font(华文行楷,Font.PLAIN,20);/设置X轴的标题文字字体domainAxis.setLabelFont(new Font(华文行楷,Font.PLAIN,20);/设置Y轴坐标上的文字标题rAxis.setTickLabelFont(new Font(华文行楷,Font.PLAIN,20);/设置Y轴的标题文字字体chart.getLegend().setItemFont(new Font(华文行楷,Font.PLAIN,20);/设置上下左右显示位置plot.setDomainAxisLocation(AxisLocation.TOP_OR_LEFT); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);/这句代码解决了底部汉字乱码的问题rAxis.setLabelFont(new Font(华文行楷,Font.PLAIN,20);/显示每个柱的数值,并修改该数值的字体属性render.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator();/显示每个柱的数值 render.setBaseItemLabelsVisible(true); /注意:此句很关键,若无此句,那数字的显示会被覆盖,给人数字没有显示出来的问题 /render.setBasePositiveItemLabelPosition(new ItemLabelPosition( render.OUTSIDE12, TextAnchor.BASELINE_CENTER); render.setItemLabelAnchorOffset(10D);/ 设置柱形图上的文字偏离值 /render.setItemLabelsVisible(true); plot.setRenderer(render);/使用我们设计的效果/设置纵横坐标的显示位置/学校显示在下端(柱子竖直)或左侧(柱子水平)plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);/人数显示在下端(柱子水平)或左侧(柱子竖直)plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); /设定柱子上面的颜色 render.setSeriesPaint(0, Color.black); / 给series1 Bar render.setSeriesPaint(1, Color.decode(#8979FF); / 给series2 Bar render.setSeriesPaint(2, Color.green); / 给series4 Bar render.setSeriesPaint(3, new Color(200, 50, 50); / 给series5 Bar render.setSeriesOutlinePaint(0,Color.BLACK);/边框为黑色 render.setSeriesOutlinePaint(1,Color.BLACK);/边框为黑色 render.setSeriesOutlinePaint(2,Color.BLACK); /边框为黑色 render.setSeriesOutlinePaint(3,Color.BLACK);/边框为黑色 FileOutputStreamgf=null;trygf=ne

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论