关于java3d柱状图的信息

博主:adminadmin 2022-11-23 02:45:07 70

本篇文章给大家谈谈java3d柱状图,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java 柱状图系统配置与实例

ChartDirector除了一个英文件的帮助以外,也没有再提供Java DOC形式的文档,为了方便,写以下一个例子说明使用ChartDirector生成柱状图的方法.jsp方式实质与JAVA方式没有区别,这里是我从JSP中取的代码(JSP改起来方便,不过手动)

代码如下:

%@ page language="java" contentType="text/Html; charset=UTF-8"

pageEncoding="UTF-8" import="ChartDirector.*;"%

%

request.setCharacterEncoding("UTF-8");

//以两个系列数据为例

double[] data = {185, 156, 179.5, 211, 123};

double[] data1 = {55, 76, 34.5, 88, 43};

//数据列名

String[] labels = {"一月", "二月", "三月", "四月", "五月"};

//生成图片大小 250 x 250

XYChart c = new XYChart(550, 350);

//图标题

c.addTitle("第一个图","",15);

//支持中文

c.setDefaultFonts("SIMSUN.TTC","simhei.ttf");

//图表在图片中的定位及区域大小

c.setPlotArea(30, 40, 400, 250);

//=========================

//加入单个数据

//BarLayer layer = c.addBarLayer(data,0xff3456,"我的测试");

//=========================

//加入多个BAR数据(多个datasets)

BarLayer layer = c.addBarLayer2(Chart.Side, 3);

layer.addDataSet(data, 0xff8080, "我测试1");

layer.addDataSet(data1, 0x008080, "你也测2");

//3d化

layer.set3D();

//设置BAR边框形式

layer.setBarShape(0);

//bar宽度

layer.setBarWidth(50);

//设置BAR边框颜色

//layer.setBorderColor(0xff9999);

//图例形式

layer.setLegend(1);

//每个BAR顶部加入数据显示

layer.setAggregateLabelStyle();

//设置BAR底部的名称显示

TextBox t = c.xAxis().setLabels(labels);

//名称文字大小

t.setFontSize(9);

//加图例

//LegendBox legend = c.addLegend(260, 120,true);

//legend.addKey("钱财",0xff8080);

//图例位置

c.addLegend(450, 120,true);

//output the chart

String chart1URL = c.makeSession(request, "chart1");

//include tool tip for the chart

String imageMap1 = c.getHTMLImageMap("#", "", "title='{xLabel}: US${value}K'");

%!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

meta http-equiv="Content-Type" content="text/html; charset=UTF-8"

title图表测试/title

/head

body

h1中文/h1

hr color="#000080"

br

img src='%=response.encodeURL("getchart.jsp?"+chart1URL)%'

usemap="#map1" border="0"

map name="map1"%=imageMap1%/map

/body

/html

资料引用:

java如何读取excel中报表(柱状图)的信息

public class Report {

/**作用:报表样式的枚举,该类的getvalue方法返回对应值。br

* Columns_2DVer:2D柱状垂直报表。br

* Columns_3DVer:3D柱状垂直报表。br

* Columns_2DHor:2D柱状水平报表。br

* Columns_3DHor:3D柱状水平报表。

* */

public enum ReportType{

Columns_2DVer("Z2DV"),

Columns_3DVer("Z3DV"),

Columns_2DHor("Z2DH"),

Columns_3DHor("Z3DH"),

LineReport_2D("Line2D"),

LineReport_3D("Line3D"),

PieReport_2D("Pie2D"),

PieReport_3D("Pie3D");

private ReportType(String a){

this.str=a;

}

private String str;

public String getvalue(){

return this.str;

}

}

/**作用:作为创建报表时的参数。br

* 成员1:报表的标题。br

* 成员2:报表的横坐标标题。br

* 成员3:报表的纵坐标标题。br

* 成员4:JSP页面的request对象。br

* 成员5:报表所保存的文件名。br

* 成员6:报表的长度。br

* 成员7:报表的宽度。br

* 成员8:报表的背景颜色,默认为白色。br

* 成员9:报表网格中竖线的颜色,默认为黑色。br

* 成员10:报表网格中横线的颜色,默认为黑色。br

* 成员11:报表横轴内容的数组。br

* 成员12:报表纵轴内容的list数组。br

* 成员13:提示信息。如果写入多个提示信息,报表就变成多柱状。br

* 成员14:报表的模式。详见reportType枚举类br

* 成员15:饼状图专用的数值数组。数组的和必须等于1.br

* 注意1:要在JSP页面引入该类型才能使用,横纵轴数组的长度必须一致。br

* 注意2:如果在提示信息数组中写入了多个提示信息,那么报表纵轴内容的

* list中就必须存放入和它数量一致的int数组。否则会出错。

* */

public class ReportClass{

public String ReportTitle;

public String xTitle;

public String yTitle;

public HttpServletRequest request;

public String filename;

public int width;

public int height;

public Color BackgroundColor=Color.WHITE;

public Color ylineColor=Color.BLACK;

public Color xlineColor=Color.BLACK;

public String[] xValues;

public ArrayListint[] yValue=new ArrayListint[]();

public String[] helpstr;

public String reportType;

public double[] PieValue;

}

/**作用:创建一个指定类型和数据的图表。br

* 参数1:ReportClass类型,各成员具体作用参见ReportClass说明br

* 返回值:String类型,在JSP页面可以直接out.println显示图形。br

* 注意1:ReportClass类型中,必须设置的成员主要有:br

* 1、ReportTitle 2、request 3、filename 4、width 5、height 6、reportTypebr

* 注意2:如果要生成饼状图,还需要设置:br

* 1、xValues 2、PieValue 这两个数组的长度必须一致br

* 注意3:如果要生成柱状图或折线图,还需要设置:br

* 1、xValues 2、yValue 3、helpstrbr

* yvalue数组总和必须等于1.即100%.br

* 如果要生成多柱状或折线图,则需要设置helpstr长度。br

* yvalue列表的长度必须和helpstr数组长度一致。br

* yvalue中的成员数组的长度必须和xvalue数组长度一致。

* */

public String CreateReport(ReportClass rc){

String s="sf";

String str="";

JFreeChart jc=null;

Font titlefont=new Font("宋体",Font.BOLD,20);

Font tickfont=new Font("宋体",0,15);

Font labelfont=new Font("宋体",Font.BOLD,15);

DefaultCategoryDataset ds=null;

DefaultPieDataset pds=null;

if (rc.ReportTitle!=null){

if (rc.reportType.indexOf("Pie")!=-1){//饼状图

pds=new DefaultPieDataset();

double[] ob=rc.PieValue;

for (int i=0;iob.length;i++){

pds.setValue(rc.xValues[i], ob[i]);

}

if (rc.ReportTitle!=null){

if (rc.reportType.equals("Pie2D")){

jc=ChartFactory.createPieChart(rc.ReportTitle,pds,true, true, false);

}

else if (rc.reportType.equals("Pie3D")){

jc=ChartFactory.createPieChart3D(rc.ReportTitle,pds,true, true, false);

}

jc.getTitle().setFont(titlefont);

jc.getLegend().setItemFont(labelfont);

jc.setBackgroundPaint(rc.BackgroundColor);//总背景色

jc.setBorderPaint(rc.BackgroundColor);

PiePlot plot=(PiePlot)jc.getPlot();

plot.setBackgroundPaint(rc.BackgroundColor);

plot.setLabelFont(new Font("宋体",0,15));

}

}

else { //柱状或折线图

ds=new DefaultCategoryDataset();

for (int i=0;irc.helpstr.length;i++){

int[] ob=rc.yValue.get(i);

for (int j=0;job.length;j++){

ds.addValue(ob[j], rc.helpstr[i], rc.xValues[j]);

}

}

if (rc.reportType.indexOf("Z2D")!=-1){

PlotOrientation po=null;

if (rc.reportType.indexOf("V")!=-1){

po=PlotOrientation.VERTICAL;

}

else if (rc.reportType.indexOf("H")!=-1){

po=PlotOrientation.HORIZONTAL;

}

jc=ChartFactory.createBarChart(rc.ReportTitle, rc.xTitle, rc.yTitle,

ds, po, true, true, false);

}

else if (rc.reportType.indexOf("Z3D")!=-1){

PlotOrientation po=null;

if (rc.reportType.indexOf("V")!=-1){

po=PlotOrientation.VERTICAL;

}

else if (rc.reportType.indexOf("H")!=-1){

po=PlotOrientation.HORIZONTAL;

}

jc=ChartFactory.createBarChart3D(rc.ReportTitle, rc.xTitle, rc.yTitle,

ds, po, true, true, false);

}

else if (rc.reportType.equals("Line2D")){

PlotOrientation po=PlotOrientation.VERTICAL;

jc=ChartFactory.createLineChart(rc.ReportTitle, rc.xTitle, rc.yTitle,

ds, po, true, true, false);

}

else if (rc.reportType.equals("Line3D")){

PlotOrientation po=PlotOrientation.VERTICAL;

jc=ChartFactory.createLineChart3D(rc.ReportTitle, rc.xTitle, rc.yTitle,

ds, po, true, true, false);

}

jc.getTitle().setFont(titlefont);

jc.getLegend().setItemFont(labelfont);

jc.setBackgroundPaint(rc.BackgroundColor);//总背景色

CategoryPlot cp=jc.getCategoryPlot();

cp.setBackgroundPaint(rc.BackgroundColor);//图形框架背景色

cp.setDomainGridlinePaint(rc.ylineColor);//图形背景网格中竖线的颜色

cp.setDomainGridlinesVisible(true);

cp.setRangeGridlinePaint(rc.xlineColor);//图形背景网格中横线的颜色

cp.getDomainAxis().setTickLabelFont(tickfont);

cp.getDomainAxis().setLabelFont(labelfont);

cp.getRangeAxis().setTickLabelFont(tickfont);

cp.getRangeAxis().setLabelFont(labelfont);

}

try {

File ff=new File(rc.request.getRealPath("/")+"file");

if (!ff.exists()){

ff.mkdir();

}

File file=new File(rc.request.getRealPath("/")+"file/"+rc.filename);

if (!file.exists()){

file.createNewFile();

}

ChartUtilities.saveChartAsJPEG(file, jc, rc.width, rc.height);

str="img src='"+file.getPath()+"'";

return str;

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

return null;

}

}

else {

return null;

}

}

}

以前写的一个报表的集成,可以生成任何形式的报表,要引入JFreeChar.你可以慢慢研究下...

如何利用FusionCharts 来创建3D柱状图

1.选择好你要创建的图形类型对应的SWF文件。例如,我们现在要创建的是3D柱状图形,那么我们的SWF文件就是FusionCharts_Column3D.swf。上篇文章已经介绍过了,所有的SWF文件都放在FusionChartsCharts文件夹里。

2.XML数据文件。FusionCharts只接受基于XML格式的数据。因此,你需要把你的数据转成XML格式。

3.HTML文件。这个HTML文件将包含用来嵌入图形的代码。

在我们进行上面的工作之前,我们先要新建一个文件夹。例如,我们创建一个叫c:\FusionCharts 的文件夹。以后我们的例子都放到这个里面。

怎么用java做柱形图!!!

首先要有jfreechart.jar和jcommon-1.0.12.jar两个包然后在web.xml配置

servlet

servlet-nameDisplayChart/servlet-name

servlet-classorg.jfree.chart.servlet.DisplayChart/servlet-class

/servlet

servlet-mapping

servlet-nameDisplayChart/servlet-name

url-pattern/DisplayChart/url-pattern

/servlet-mapping

最后是jsp代码:

%@ page contentType="text/html;charset=GBK"%

%@ page import="org.jfree.chart.ChartFactory,

org.jfree.chart.JFreeChart,

org.jfree.chart.plot.PlotOrientation,

org.jfree.chart.servlet.ServletUtilities,

org.jfree.data.category.CategoryDataset,

org.jfree.data.general.DatasetUtilities"%

%

double[][] data = new double[][] {{1310}, {720}, {1130}, {440}};

String[] rowKeys = {"猪肉", "牛肉","鸡肉", "鱼肉"};

String[] columnKeys = {""};

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

JFreeChart chart = ChartFactory.createBarChart3D("广州肉类销量统计图", "肉类",

"销量",

dataset,

PlotOrientation.VERTICAL,

true,

false,

false);

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

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

%

img src="%= graphURL %"width=500 height=300 border=0 usemap="#%= filename %"

怎么用java的相关类去画一个柱状图

可以使用java第三方JFreeChart的api:具体

import java.awt.Color;

import java.awt.GradientPaint;

import org.jfree.chart.ChartFactory;

import org.jfree.chart.JFreeChart;

import org.jfree.chart.axis.CategoryAxis;

import org.jfree.chart.axis.CategoryLabelPositions;

import org.jfree.chart.axis.NumberAxis;

import org.jfree.chart.plot.CategoryPlot;

import org.jfree.chart.plot.PlotOrientation;

import org.jfree.chart.renderer.category.BarRenderer;

import org.jfree.chart.renderer.category.BarRenderer3D;

import org.jfree.data.category.CategoryDataset;

import org.jfree.data.category.DefaultCategoryDataset;

import org.jfree.data.general.DatasetUtilities;

/**

* 柱状图测试

* @author xjh

*

*/

public class BarChartTest {

/**

* 得到2D柱状图的数据集合

*

* @return

*/

private CategoryDataset getDataset2D() {

String str1 = "First";

String str2 = "Second";

String str3 = "Third";

String str4 = "Category 1";

String str5 = "Category 2";

String str6 = "Category 3";

String str7 = "Category 4";

String str8 = "Category 5";

DefaultCategoryDataset localDefaultCategoryDataset = new DefaultCategoryDataset();

localDefaultCategoryDataset.addValue(1.0D, str1, str4);

localDefaultCategoryDataset.addValue(4.0D, str1, str5);

localDefaultCategoryDataset.addValue(3.0D, str1, str6);

localDefaultCategoryDataset.addValue(5.0D, str1, str7);

localDefaultCategoryDataset.addValue(5.0D, str1, str8);

localDefaultCategoryDataset.addValue(5.0D, str2, str4);

localDefaultCategoryDataset.addValue(7.0D, str2, str5);

localDefaultCategoryDataset.addValue(6.0D, str2, str6);

localDefaultCategoryDataset.addValue(8.0D, str2, str7);

localDefaultCategoryDataset.addValue(4.0D, str2, str8);

localDefaultCategoryDataset.addValue(4.0D, str3, str4);

localDefaultCategoryDataset.addValue(3.0D, str3, str5);

localDefaultCategoryDataset.addValue(2.0D, str3, str6);

localDefaultCategoryDataset.addValue(3.0D, str3, str7);

localDefaultCategoryDataset.addValue(6.0D, str3, str8);

return localDefaultCategoryDataset;

}

/**

* 创建2D柱状图

*

* @param paramCategoryDataset

* @return

*/

public JFreeChart createBarChart2D() {

//得到2D柱状图的数据集合

CategoryDataset paramCategoryDataset = getDataset2D();

//创建柱状图

JFreeChart localJFreeChart = ChartFactory.createBarChart(

"Bar Chart Demo", "Category", "Value", paramCategoryDataset,

PlotOrientation.VERTICAL, true, true, false);

//设置柱状图属性

localJFreeChart.setBackgroundPaint(Color.white);

//获取柱状图的标注点集合

CategoryPlot localCategoryPlot = localJFreeChart.getCategoryPlot();

//设置标注点的背景色

localCategoryPlot.setBackgroundPaint(Color.lightGray);

//设置绘制区域的方格线的颜色

localCategoryPlot.setDomainGridlinePaint(Color.white);

//是方格线可见

localCategoryPlot.setDomainGridlinesVisible(true);

//设置方格线变动绘制颜色

localCategoryPlot.setRangeGridlinePaint(Color.white);

//得到数值坐标轴

NumberAxis localNumberAxis = (NumberAxis) localCategoryPlot

.getRangeAxis();

//设置坐标轴单元

localNumberAxis.setStandardTickUnits(NumberAxis

.createIntegerTickUnits());

//得到柱状图渲染器

BarRenderer localBarRenderer = (BarRenderer) localCategoryPlot

.getRenderer();

//如果超出绘制区域边界将不可见

localBarRenderer.setDrawBarOutline(false);

//创建倾斜度对象

GradientPaint localGradientPaint1 = new GradientPaint(0.0F, 0.0F,

Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));

GradientPaint localGradientPaint2 = new GradientPaint(0.0F, 0.0F,

Color.green, 0.0F, 0.0F, new Color(0, 64, 0));

GradientPaint localGradientPaint3 = new GradientPaint(0.0F, 0.0F,

Color.red, 0.0F, 0.0F, new Color(64, 0, 0));

//为渲染器设置倾斜度

localBarRenderer.setSeriesPaint(0, localGradientPaint1);

localBarRenderer.setSeriesPaint(1, localGradientPaint2);

localBarRenderer.setSeriesPaint(2, localGradientPaint3);

//旋转坐标轴

CategoryAxis localCategoryAxis = localCategoryPlot.getDomainAxis();

localCategoryAxis.setCategoryLabelPositions(CategoryLabelPositions

.createUpRotationLabelPositions(0.5235987755982988D));

return localJFreeChart;

}

/**

* 创建3D柱状图

*

* @return

*/

public JFreeChart createBarChart3D() {

// 设置坐标点

double[][] arrayOfDouble = { { 10.0D, 4.0D, 15.0D, 14.0D },

{ -5.0D, -7.0D, 14.0D, -3.0D }, { 6.0D, 17.0D, -12.0D, 7.0D },

{ 7.0D, 15.0D, 11.0D, 0.0D }, { -8.0D, -6.0D, 10.0D, -9.0D },

{ 9.0D, 8.0D, 0.0D, 6.0D }, { -10.0D, 9.0D, 7.0D, 7.0D },

{ 11.0D, 13.0D, 9.0D, 9.0D }, { -3.0D, 7.0D, 11.0D, -10.0D } };

// 创建图表的数据集合,第一个参数:横坐标的文字说明;第二个参数:纵坐标的文字说明;第三个参数:坐标数组

CategoryDataset paramCategoryDataset = DatasetUtilities

.createCategoryDataset("Series ", "Category ", arrayOfDouble);

// 创建3D图表

JFreeChart localJFreeChart = ChartFactory.createBarChart3D(

"3D Bar Chart Demo", "Category", "Value", paramCategoryDataset,

PlotOrientation.VERTICAL, true, true, false);

// 得到横坐标点集合对象

CategoryPlot localCategoryPlot = localJFreeChart.getCategoryPlot();

// 设置方格可见

localCategoryPlot.setDomainGridlinesVisible(true);

// 得到坐标轴

CategoryAxis localCategoryAxis = localCategoryPlot.getDomainAxis();

// 设置标注点位置

localCategoryAxis.setCategoryLabelPositions(CategoryLabelPositions

.createUpRotationLabelPositions(0.3926990816987241D));

// 创建3D柱状图渲染对象

BarRenderer3D localBarRenderer3D = (BarRenderer3D) localCategoryPlot

.getRenderer();

// 设置超出边界不可见

localBarRenderer3D.setDrawBarOutline(false);

// 返回图表对象

return localJFreeChart;

}

}

关于java3d柱状图和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-23,除非注明,否则均为首码项目网原创文章,转载请注明出处。