用ChartDirector 画饼

ChartDirector是一款简单使用的图形报表工具,足以应付一般的开发需求。

 

对比习惯于JFreeChart开发的人,这家伙显得简单、明了。

 

// 设置Chart大小、背景色
PieChart pc = new PieChart(750,500,0xddddff,-1,1);
pc.setPieSize(390, 245, 150);

// 设置图表标题
// 只要将文字转成UTF-8编码就可以解决中文乱码问题
// 另外如果你将程序部署到Linux下就需要copy相应的字体文件,比如simsun.ttc文件到/usr/share/font下
TextBox t = null;
pc.setDefaultFonts("SIMSUN.TTC", "simhei.ttf");
t = pc.addTitle(rb.get("REPORT_TOTAL_PURCHASED"), "", 14); // 中文就从resource.properties中取吧
t.setBackground(0xaaaaff); // 字体也要有背景的
t.setBackground(0xaaaaff,0xaaffaa); // 需要加边框吗?加上第二个参数就可以了
t.setHeight(30);

StringBuffer sb = new StringBuffer(RetrainingConstant.get("total_join"))
	.append(data[data.length-1]).append(rb.get("rein"));

TextBox total = pc.addText(10, 35, sb.toString()); // 加个文字吧,随便显示什么都行了
total.setFontColor(0x000000);
total.setFontSize(10);

double[] data = new double[]{100,90,80,70}; 
String[] labels = new String[]{"ColumnA", "ColumnB", "ColumnC", "ColumnD"};

pc.setData(dt,labels); // 放数据

double[] depths1 = {45,10,35,20,25,30,15,40};
pc.set3D2(depths1);
pc.setLabelLayout(Chart.SideLayout);

// 每一块饼都得给个说明
TextBox t1 = pc.setLabelStyle();
t1.setBackground(Chart.SameAsMainColor, Chart.Transparent, Chart.glassEffect());
t1.setRoundedCorners(5);
pc.setLineColor(Chart.SameAsMainColor, 0x000000);
pc.setStartAngle(225);

// 最终的img.src
getRequest().setAttribute("chartURL", pc.makeSession(getRequest(), "chartURL"));
// 链接的href,其中变量{dataSetName}和{value}分别对应了data和lables中的值
getRequest().setAttribute("imageMap" ,pc.getHTMLImageMap("searchStudents.html",
		"chartType=5&subject={dataSetName}", "title='{value}人'"));
		
// 至此,饼图就被搞定了~~

  

相关的资源大家可以到这下载。附加里面是破解的jar。

 

管方网址:www.advsofteng.com

//Name of demo program public String toString() { return "Glass Bar Shading"; } //Number of charts produced in this demo public int getNoOfCharts() { return 1; } //Main code for creating charts public void createChart(ChartViewer viewer, int index) { // The data for the bar chart double[] data = {450, 560, 630, 800, 1100, 1350, 1600, 1950, 2300, 2700}; // The labels for the bar chart String[] labels = {"1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005"}; // Create a XYChart object of size 600 x 360 pixels XYChart c = new XYChart(600, 360); // Set the plotarea at (60, 40) and of size 480 x 280 pixels. Use a vertical // gradient color from light blue (eeeeff) to deep blue (0000cc) as // background. Set border and grid lines to white (ffffff). c.setPlotArea(60, 40, 480, 280, c.linearGradientColor(60, 40, 60, 280, 0xeeeeff, 0x0000cc), -1, 0xffffff, 0xffffff); // Add a title to the chart using 18pts Times Bold Italic font c.addTitle("Annual Revenue for Star Tech", "Times New Roman Bold Italic", 18) ; // Add a multi-color bar chart layer using the supplied data. Use glass // lighting effect with light direction from the left. c.addBarLayer3(data).setBorderColor(Chart.Transparent, Chart.glassEffect( Chart.NormalGlare, Chart.Left)); // Set the x axis labels c.xAxis().setLabels(labels); // Show the same scale on the left and right y-axes c.syncYAxis(); // Set the left y-axis and right y-axis title using 10pt Arial Bold font c.yAxis().setTitle("USD (millions)", "Arial Bold", 10); c.yAxis2().setTitle("USD (millions)", "Arial Bold", 10); // Set all axes to transparent c.xAxis().setColors(Chart.Transparent); c.yAxis().setColors(Chart.Transparent); c.yAxis2().setColors(Chart.Transparent); // Set the label styles of all axes to 8pt Arial Bold font c.xAxis().setLabelStyle("Arial Bold", 8); c.yAxis().setLabelStyle("Arial Bold", 8); c.yAxis2().setLabelStyle("Arial Bold", 8); // output the chart viewer.setImage(c.makeImage()); //include tool tip for the chart viewer.setImageMap(c.getHTMLImageMap("clickable", "", "title='Year {xLabel}: US$ {value}M'"));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值