java区域图 3d图 混合图和报表,几种报表图的画法

org.jfree.chart.ChartPanel,

org.jfree.chart.JFreeChart,

org.jfree.chart.DefaultOldLegend,

org.jfree.chart.axis.NumberAxis,

org.jfree.chart.plot.CategoryPlot,

org.jfree.chart.plot.PlotOrientation,

org.jfree.chart.renderer.category.LineAndShapeRenderer,

org.jfree.data.category.CategoryDataset,

org.jfree.data.category.DefaultCategoryDataset,

org.jfree.chart.servlet.ServletUtilities

"%>

String[] rowKeys= null;//柱数据

String[] columnKeys=null;//刻度数据

rowKeys = new String[]{"219.146.1.196","219.146.10.105","219.146.10.116","219.146.10.73"};

columnKeys = new String[]{"2008年7月上旬","2007-02-04"};

double[][] data = new double[rowKeys.length][columnKeys.length];

data = new double[][]{

{1022.0,856.0},{676.0,13563.0},{12827.0,10576.0},{0.0,100.0}

};

CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);

JFreeChart chart = ChartFactory.createLineChart(

"这是测试标题...",

"时间",

"访问量",                 // range axis label

dataset,                   // data

PlotOrientation.VERTICAL,  // orientation

true,                      // include legend

true,                      // tooltips

false                      // urls

);

chart.setBackgroundPaint(Color.WHITE);  //-----------------------------背景色

chart.setBorderVisible(true);  //--------------------------------------设置边框是否可见

chart.setBorderPaint(Color.BLUE);  //-----------------------------------设置边框颜色setBorderVisible()必须为true

CategoryPlot plot = chart.getCategoryPlot();

plot.setBackgroundPaint(Color.CYAN);

CategoryAxis domainAxis = plot.getDomainAxis();

domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);

plot.setDomainAxis(domainAxis);

// customise the range axis... 设置统计图中只显示整数

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

rangeAxis.setAutoRangeIncludesZero(true);

rangeAxis.setUpperMargin(0.20);

rangeAxis.setLabelAngle(Math.PI / 2.0);

LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();

renderer.setItemLabelsVisible(true);

renderer.setShapesVisible(true);//series 点(即数据点)可见

renderer.setSeriesPaint(0, new Color(0, 0, 255));

renderer.setSeriesPaint(1, new Color(255, 0, 255));

renderer.setSeriesPaint(2, new Color(0, 255, 255));

renderer.setSeriesPaint(3, new Color(0,125,0));

renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());

renderer.setItemLabelsVisible(true);

String filename = ServletUtilities.saveChartAsPNG(chart, 850, 550, null, session);

String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;

%>

<%=%20graphURL%20%>

2.饼状图

DefaultPieDataset data = new DefaultPieDataset();

//数据初始化

data.setValue("高中以下",380);

data.setValue("高中",1620);

data.setValue("大专",6100);

data.setValue("本科",8310);

data.setValue("硕士",3520);

data.setValue("博士",1900);

//HttpSession session = request.getSession();

PiePlot plot = new PiePlot(data);//生成一个3D饼图

//plot.setURLGenerator(new StandardPieURLGenerator("DegreedView.jsp"));//设定图片链接

JFreeChart chart = new JFreeChart("",JFreeChart.DEFAULT_TITLE_FONT, plot, true);

chart.setBackgroundPaint(java.awt.Color.white);//可选,设置图片背景色

chart.setTitle("程序员学历情况调查表-By Alpha");//可选,设置图片标题

//plot.setToolTipGenerator(new StandardPieURLGenerator());

StandardEntityCollection sec = new StandardEntityCollection();

ChartRenderingInfo info = new ChartRenderingInfo(sec);

PrintWriter w = new PrintWriter(out);//输出MAP信息

//500是图片长度,300是图片高度

//String filename = ServletUtilities.saveChartAsPNG(chart,500,300,info,session);

String filename = ServletUtilities.saveChartAsJPEG(chart,500,300,info,session);

ChartUtilities.writeImageMap(w,"map0",info,false);

String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;

%>

<%=%20graphURL%20%>

3.柱状图

String[] rowInfo = new String[]{"one","two"};

String[] colInfo = new String[]{"first","second"};

double[][] dataInfo = new double[2][2];

dataInfo = new double[][]{

{1022.0,856.0},{676.0,13563.0}

};

CategoryDataset data = DatasetUtilities.createCategoryDataset(rowInfo,colInfo,dataInfo);

JFreeChart chart = ChartFactory.createBarChart3D("this is test......",

"row",

"col",

data,

PlotOrientation.VERTICAL,

true,false,false);

chart.setAntiAlias(true);

chart.setBackgroundPaint(Color.WHITE);

chart.setBorderPaint(Color.BLACK);

chart.setBorderVisible(true);

//图表区域对象,基本上这个对象决定着什么样式的图表,创建该对象的时候需要Axis、Renderer以及数据集对象的支持

CategoryPlot plot = chart.getCategoryPlot();

plot.setDomainGridlinePaint(Color.RED); //横坐标网格线白色

plot.setDomainGridlinesVisible(true); //可见

plot.setBackgroundPaint(Color.CYAN);

//用于处理图表的两个轴:纵轴和横轴

CategoryAxis axis = plot.getDomainAxis();

axis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

axis.setAxisLinePaint(Color.RED);

//axis.setLabel("asdfasdfa");

//axis.setUpperMargin(5);

axis.setTickMarksVisible(true);

axis.setAxisLineVisible(true);

NumberAxis numberaxis = (NumberAxis)plot.getRangeAxis();

numberaxis.setAutoTickUnitSelection(true);

numberaxis.setAutoRangeIncludesZero(false);

BarRenderer3D renderer = new BarRenderer3D();

renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());

renderer.setItemLabelsVisible(true);

renderer.setBaseOutlinePaint(Color.BLACK);

//设置 Wall 的颜色

renderer.setWallPaint(Color.GREEN);

//设置每种柱的颜色

//renderer.setSeriesPaint(0, new Color(0, 0, 255));

//renderer.setSeriesPaint(1, new Color(0, 100, 255));

//设置平行柱之间距离

renderer.setItemMargin(0.02);

//显示每个柱的数值,并修改该数值的字体属性

//renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());

//renderer.setItemLabelsVisible(true);

plot.setRenderer(renderer);

//设置柱的透明度

plot.setForegroundAlpha(0.8f);

//设置地区、销量的显示位置

plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);

plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

String filename = ServletUtilities.saveChartAsPNG(chart, 850, 550, null, session);

String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;

%>

<%=%20graphURL%20%> 

posted on 2008-10-21 12:00 智者无疆 阅读(666) 评论(3)  编辑  收藏 所属分类: about java

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将3D化,您需要使用Java中的形库。以下是一些常用的Java形库: 1. Java 2D Graphics API:Java 2D是Java平台的一个标准API,用于处理2D像。它提供了一个强大的、易于使用的形库,可以用来创建各种类型的2D像。您可以使用Java 2D来实现基本的3D效果。 2. Java 3D API:Java 3DJava平台的一个高级形API,用于创建复杂的3D形。它提供了一个强大的、易于使用的形引擎,可以用来创建各种类型的3D像。您可以使用Java 3D来实现高级的3D效果。 以下是一些实现3D效果的Java代码示例: 1. 使用Java 2D实现简单的3D效果: ```java public class Image3D { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(500, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; BufferedImage image = null; try { image = ImageIO.read(new File("image.jpg")); } catch (IOException e) { e.printStackTrace(); } AffineTransform at = new AffineTransform(); at.translate(0, 0); at.rotate(Math.toRadians(45), image.getWidth() / 2, image.getHeight() / 2); g2d.drawImage(image, at, null); } }; frame.add(panel); frame.setVisible(true); } } ``` 2. 使用Java 3D实现高级的3D效果: ```java public class Image3D { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(500, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SimpleUniverse universe = new SimpleUniverse(); BranchGroup group = new BranchGroup(); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); TextureLoader loader = new TextureLoader("image.jpg", new Container()); Texture texture = loader.getTexture(); Appearance ap = new Appearance(); ap.setTexture(texture); Sphere sphere = new Sphere(0.5f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, ap); Transform3D transform = new Transform3D(); transform.rotX(Math.PI/4); transform.rotY(Math.PI/4); sphere.setTransform(transform); group.addChild(sphere); universe.addBranchGraph(group); frame.add(universe.getCanvas()); frame.setVisible(true); } } ``` 这些示例只是一些基本的代码,您需要根据自己的需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值