新聞中心
如何使用java做統(tǒng)計圖表
//參考地址去網(wǎng)站下js控件,下面是餅圖的代碼,下圖是我的代碼效果
站在用戶的角度思考問題,與客戶深入溝通,找到襄城網(wǎng)站設計與襄城網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都網(wǎng)站設計、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、國際域名空間、網(wǎng)站空間、企業(yè)郵箱。業(yè)務覆蓋襄城地區(qū)。
function?query1(housetype,redStatisticsList,text0,cashingSum,tranferSum){
!--紅包發(fā)放數(shù)據(jù)--
var?myrodiusred?=?echarts.init(document.getElementById('mainrodius'));//ID
var?redHousehold?=?housetype;
var?redMoney?=?redStatisticsList;
var?allMoney?=?0;//總金額
$.each(redStatisticsList,function(index,item){
allMoney?=allMoney+?Number(item.value);
})
optionTwo?=?{
title?:?{
text:?text0,
subtext:?"總金額:"+allMoney+"\n\n提現(xiàn)總額:"+cashingSum+"\n\n到賬總額:"+tranferSum,
x:'center'
},
tooltip?:?{
trigger:?'item',
formatter:?"{a}?br/?(vbb75nf%)"
},
legend:?{
orient:?'vertical',
left:?'left',
data:?housetype
},
series?:?[
{
type:?'pie',
radius?:?'55%',
center:?['50%',?'60%'],
data:redMoney,
itemStyle:?{
emphasis:?{
shadowBlur:?10,
shadowOffsetX:?0,
shadowColor:?'rgba(0,?0,?0,?0.5)'
}
}
}
]
};
myrodiusred.setOption(optionTwo);
}
eclipse中用JAVA代碼怎么畫柱形圖表
用jfreechart
jfreechart繪制柱狀圖
import java.io.File;
import java.io.IOException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
/*
* 繪制柱狀圖
*你亮哥
* */
public class BarChart3DDemo
{
public static void main(String[] args)
{
try
{
//設置主題
ChartFactory.setChartTheme(Theme.getTheme());
//構(gòu)造數(shù)據(jù)
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(100, "JAVA","1");
dataset.addValue(200, "js","1");
dataset.addValue(200, "C++", "2");
dataset.addValue(300, "C", "3");
dataset.addValue(400, "HTML", "4");
dataset.addValue(400, "CSS", "5");
/*
* public static JFreeChart createBarChart3D(
* java.lang.String title, 設置圖表的標題
* java.lang.String categoryAxisLabel, 設置分類軸的標示
* java.lang.String valueAxisLabel, 設置值軸的標示
* CategoryDataset dataset, 設置數(shù)據(jù)
* PlotOrientation orientation, 設置圖表的方向
* boolean legend, 設置是否顯示圖例
* boolean tooltips,設置是否生成熱點工具
* boolean urls) 設置是否顯示url
*/
JFreeChart chart = ChartFactory.createBarChart3D("編程語言統(tǒng)計", "語言",
"學習人數(shù)", dataset, PlotOrientation.VERTICAL, true, false,
false);
//保存圖表
ChartUtilities.saveChartAsPNG(new File("E:/chart/BarChart3D.png"), chart, 800, 500);
System.out.println("繪圖完成");
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
===================================================================================
//一條線 有點 有數(shù)
package Test;
import java.awt.Color;
import java.awt.Font;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardXYItemLabelGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
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.ui.RectangleInsets;
import org.jfree.ui.TextAnchor;
public class try123 {
public static void main(String[] args){
//首先構(gòu)造數(shù)據(jù)
TimeSeries timeSeries = new TimeSeries("BMI", Month.class);
// 時間曲線數(shù)據(jù)集合
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
// 構(gòu)造數(shù)據(jù)集合
timeSeries.add(new Month(1, 2009), 45);
timeSeries.add(new Month(2, 2009), 46);
timeSeries.add(new Month(3, 2009), 1);
timeSeries.add(new Month(4, 2009), 500);
timeSeries.add(new Month(5, 2009), 43);
timeSeries.add(new Month(6, 2009), 324);
timeSeries.add(new Month(7, 2009), 632);
timeSeries.add(new Month(8, 2009), 34);
timeSeries.add(new Month(9, 2009), 12);
timeSeries.add(new Month(10, 2009), 543);
timeSeries.add(new Month(11, 2009), 32);
timeSeries.add(new Month(12, 2009), 225);
lineDataset.addSeries(timeSeries);
JFreeChart chart = ChartFactory.createTimeSeriesChart("", "date", "bmi", lineDataset, true, true, true);
//增加標題
chart.setTitle(new TextTitle("XXXBMI指數(shù)", new Font("隸書", Font.ITALIC, 15)));
chart.setAntiAlias(true);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setAxisOffset(new RectangleInsets(10,10,10,10));//圖片區(qū)與坐標軸的距離
plot.setOutlinePaint(Color.PINK);
plot.setInsets(new RectangleInsets(15,15,15,15));//坐標軸與最外延的距離
// plot.setOrientation(PlotOrientation.HORIZONTAL);//圖形的方向,包括坐標軸。
AxisSpace as = new AxisSpace();
as.setLeft(25);
as.setRight(25);
plot.setFixedRangeAxisSpace(as);
chart.setPadding(new RectangleInsets(5,5,5,5));
chart.setNotify(true);
// 設置曲線是否顯示數(shù)據(jù)點
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer();
xylineandshaperenderer.setBaseShapesVisible(true);
// 設置曲線顯示各數(shù)據(jù)點的值
XYItemRenderer xyitem = plot.getRenderer();
xyitem.setBaseItemLabelsVisible(true);
xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_LEFT));
xyitem.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));
plot.setRenderer(xyitem);
//顯示
ChartFrame frame = new ChartFrame("try1", chart);
frame.pack();
frame.setVisible(true);
}
}
java怎么從數(shù)據(jù)庫里獲得動態(tài)數(shù)據(jù)生成統(tǒng)計圖
我這個是使用的echarts的餅圖,如果需要使用到其他的圖形,可以在echarts的官網(wǎng)上面去找找,上面各種的圖都有例子
option = {
title : {
//圖中2的位置
text: '某站點用戶訪問來源',
subtext: '純屬虛構(gòu)',
x:'center'
},
tooltip : {
trigger: 'item',
formatter: "{a} br/ : {c} (vbb75nf%)"
},
legend: {
orient: 'vertical',
left: 'left',
data: ['直接訪問','郵件營銷','聯(lián)盟廣告','視頻廣告','搜索引擎']//圖中1的位置
},
series : [ ? //圖中3的位置
{
name: '訪問來源',
type: 'pie',
radius : '55%',
center: ['50%', '60%'],
data:[
//這下面就是你從數(shù)據(jù)庫中查詢的結(jié)果
{value:335, name:'直接訪問'},
{value:310, name:'郵件營銷'},
{value:234, name:'聯(lián)盟廣告'},
{value:135, name:'視頻廣告'},
{value:1548, name:'搜索引擎'}
],
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
} }]};
數(shù)據(jù)具體怎么從后臺傳送到前臺來,樓主應該知道的吧,我這兒就不說了,望采納!
用java將數(shù)據(jù)導出到wps表格中,怎么實現(xiàn)
一:頁面圖片顯示預覽:
1)如下圖:
2)點擊導出按鈕后預覽:
3)最終生成的excel表格圖片預覽:
二:代碼演示:
說明:執(zhí)行操作時,請先引進導出excel表格的jar文件包。
找到導出按鈕所執(zhí)行的js方法,在java后天查看該方法的實現(xiàn)即可。
1)jsp代碼:
[html]?view plaincopyprint?
%@?page?language="java"?import="java.util.*"?pageEncoding="UTF-8"%
%@taglib?prefix="s"?uri="/struts-tags"?%
%
String?path?=?request.getContextPath();
String?basePath?=?request.getScheme()?+?"://"
+?request.getServerName()?+?":"?+?request.getServerPort()
+?path?+?"/";
%
html
head
base?href="%=basePath%"
title駕校合格率排名/title
link?href="jsp/commonstyle/css/tabStyle.css"?rel="stylesheet"?type="text/css"
link?rel="STYLESHEET"?type="text/css"?href="%=basePath%jsp/hgltj/js/tablesort.css"
script?type="text/javascript"?src="%=basePath%jsp/system/common/js/publicColor.js"/script
script?type="text/javascript"?src="jsp/commonstyle/js/js/My97DatePicker/WdatePicker.js"?defer="defer"/script
script?type="text/javascript"?src="%=basePath%jsp/hgltj/js/tablesort.js"/script
script?language="JavaScript"
function?load()
{
//根據(jù)分辨率設置表格大小
maxw=document.getElementById("maintb").offsetWidth;
if(maxw824){//1024分辨率未展開
mainbox.width="98%";
}?else?if(maxw1013){//1024分辨率展開
mainbox.width="98%";
}?else??if(maxw1081){//1280分辨率未展開
mainbox.width="95%";
}?else??if(maxw1270){//1280分辨未展開
mainbox.width="95%";
}else{//1280以上分辨展開
mainbox.width="98%";
}
}
/script
script
function?overIt(){
var?the_obj?=?event.srcElement;
if(the_obj.tagName.toLowerCase()?==?"td"){
the_obj=the_obj.parentElement;
the_obj.oBgc=the_obj.currentStyle.backgroundColor;
the_obj.oFc=the_obj.currentStyle.color;
the_obj.style.backgroundColor='#4073C4';
the_obj.style.color='#ffffff';
the_obj.style.textDecoration='underline';
}
}
function?outIt(){
var?the_obj?=?event.srcElement;
if(the_obj.tagName.toLowerCase()?==?"td"){
the_obj=the_obj.parentElement;
the_obj.style.backgroundColor=the_obj.oBgc;
the_obj.style.color=the_obj.oFc;
the_obj.style.textDecoration='';
}
}
function?serch(){
document.getElementById("formName").action="%=basePath?%hgltj.action?method=getHglpm";
document.getElementById("formName").submit();
}
function?tbbt(){
var?jzrq=document.getElementById("jzrqId").value;
//var?jxmc=document.getElementById("jxmcId").value;
window.open('%=basePath?%hgltj.action?method=getHglpmTbtjjxkshgl.jzrq='+jzrq+'tjjxkshgl.zt='+1,'','height=650,width=1250,top=150,left=200,toobar=no,menubar=no,scrollbars=yes,resizable=no,location=no,');
}
function?openwd(){
document.getElementById("formName").action="%=basePath?%hgltj.action?method=downJxhglPm";
document.getElementById("formName").submit();
}
/script
/head
BODY?onLoad="load()"?style="background:?url(images/cont_bg.gif);?background-repeat:?repeat-y"
input?type="hidden"?name="method"?value="getDriverInfoList"/
table?border="0"?width="100%"?cellspacing="0"?cellpadding="0"?id="maintb"
tr
td?align="center"
table?width="90%"??border="0"??cellspacing="0"?cellpadding="0"?id="mainbox"?style="background:url(jsp/commonstyle/images/usermessage_02.gif);?background-repeat:repeat-x;"?
!--寬度可變內(nèi)容框--
tr?
td?width="33"?height="27"?style="?background:url(jsp/commonstyle/images/usermessage_01.gif);?background-position:left;?background-repeat:no-repeat;"?/td
td?width="965"?class="style1"font?color="black"駕校合格率排名/font/td
td?width="14"?height="27"?style="?background:url(jsp/commonstyle/images/usermessage_03.gif);?background-position:right;?background-repeat:no-repeat;"?/td
/tr
tr
td?colspan="3"
!--頁面主體內(nèi)容開始--
!--查詢條件--
form?action=""?name="formName"?method="post"?style="margin:0px"?id="formName"?theme="simple"
table?width="100%"?border="0"?cellpadding="0"?cellspacing="0"???style="border-collapse:collapse;"?id="tj"?align="center"
tr?align="left"
td?class="tjbg1"?style="text-align:?left"
!--?input?type="hidden"?id="method"??name="method"?value="getHglpm"/?--
統(tǒng)計日期:
input?type="text"?name="tjjxkshgl.jzrq"?id="jzrqId"?value="s:property?value="tjjxkshgl.jzrq"/"?onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM'})"/
!--?駕校名稱:
s:select?id="jxmcId"??name="tjjxkshgl.jxxh"??value="tjjxkshgl.jxxh"?list="schoolList"?listKey="jxxh"?listValue="jxmc"?headerKey=""?headerValue="--請選擇--"?theme="simple"/s:select????????--
input?name="input"?value="?統(tǒng)?計?"?type="button"?class="normalbtn"?onClick="serch()"?style="margin-bottom:?5px"?/
input?name="input"?type="button"?value="?合格率圖表?"?onclick="tbbt()"?class="normalbtn"?style="margin-bottom:?5px"?/
input?id="Button1"?type="button"?value="?導?出?"?onclick="openwd();"?class="normalbtn"?style="margin-bottom:?5px"?/
/td
/tr
/table!--查詢結(jié)果--
/form
!--查詢結(jié)果--
table?width="100%"?border="0"?cellpadding="4"?cellspacing="1"?bgcolor="#abcfff"?id="cxjg"?align="center"
thead
tr?class="tbtitle"
td?width="4%"?align="center"?class="t1"名次/td
td?width="8%"?align="center"?class="t1"名稱/td
td?class="t1"?width="5%"?align="center"科目一/td
td?class="t1"?width="5%"?align="center"科目二/td
td?class="t1"?width="5%"?align="center"科目三/td
td?class="t1"?width="5%"?align="center"平均合格率/td
td?class="t1"?width="5%"?align="center"操作/td
/tr
/thead
s:iterator?id="jxhgl"?value="jxhelpmList"?status="st"
tr?class="changeColor"?onMouseOver="overIt()"?onMouseOut="outIt()"?style="cursor:?hand"?align="center"
tds:property?value="#st.index+1"http://td
tds:property?value="#jxhgl.jxmc"http://td
tds:property?value="#jxhgl.km1hgl"http://td
tds:property?value="#jxhgl.km2hgl"http://td
tds:property?value="#jxhgl.km3hgl"http://td
tds:property?value="#jxhgl.avghgl"/%/td
td
a?href="javascript:"?onclick="openWin('%=basePath?%hgltj.action?method=getTbForJxxhtjjxkshgl.jxxh=s:property?value="#jxhgl.jxxh"/tjjxkshgl.zt=1','',1250,750);"圖表/a
/td
/tr
/s:iterator
/table
/table
/td
/tr
/table
/body
/html
2)java代碼演示:
[java]?view plaincopyprint?
/**
*?駕校合格率導出excel圖表
*/
//response.getOutputStream();//?取得輸出流
response.reset();//?清空輸出流
String?tmptitle?=?"駕校合格率排名";?//?標題
response.setHeader("Content-disposition",?"attachment;?filename="+new?String(tmptitle.getBytes(),"iso8859-1")+".xls");//?設定輸出文件頭
response.setContentType("application/vnd.ms-excel");//?定義輸出類型
wbook?=?Workbook.createWorkbook(os);?//?建立excel文件
WritableSheet?wsheet?=?wbook.createSheet(tmptitle,?0);?//?sheet名稱
//?設置excel標題
//cellFormat.setBackground(Colour.AQUA);
cellFormat.setFont(wfont);
label.setCellFormat(cellFormat);
wsheet.addCell(label);
//wsheet.addCell(new?Label(0,?0,?tmptitle,?wcfFC));
wsheet.setRowView(0,500);?//第一行高度
wsheet.mergeCells(0,?0,?6,?1);??//合并單元格(第一列的第一行和第七列的第二行合并)
//wsheet.mergeCells(0,?1,?9,?1);
//??????wsheet.mergeCells(0,?2,?0,?4);
//??????wsheet.mergeCells(1,?2,?3,?2);
//??????wsheet.mergeCells(4,?2,?6,?2);
//??????wsheet.mergeCells(7,?2,?9,?2);
wsheet.setColumnView(0,10);?//寬度
wsheet.setColumnView(1,25);?//寬度
wsheet.setColumnView(2,10);?//寬度
wsheet.setColumnView(3,10);?//寬度
wsheet.setColumnView(4,10);?//寬度
wsheet.setColumnView(5,10);?//寬度
//?開始生成主體內(nèi)容
wfont?=?new?jxl.write.WritableFont(WritableFont.ARIAL,?14,WritableFont.BOLD,false,?UnderlineStyle.NO_UNDERLINE,Colour.BLACK);
wcfFC?=?new?WritableCellFormat(wfont);
wsheet.addCell(new?Label(0,?2,?"名次",wcfFC));
wsheet.addCell(new?Label(1,?2,?"駕校名稱",wcfFC));
wsheet.addCell(new?Label(2,?2,?"科目一",wcfFC));
wsheet.addCell(new?Label(3,?2,?"科目二",wcfFC));
wsheet.addCell(new?Label(4,?2,?"科目三",wcfFC));
wsheet.addCell(new?Label(5,?2,?"合格率",wcfFC));
int?count=jxhelpmList.size();
if(count0){??////判斷集合是否不為0
TjJxkshgl?tjhgl=null;
for(int?i=0;ijxhelpmList.size();i++){
tjhgl=(TjJxkshgl)jxhelpmList.get(i);
wsheet.addCell(new?Label(0,?i+3,?(i+1)+""));
wsheet.addCell(new?Label(1,?i+3,?tjhgl.getJxmc()));
wsheet.addCell(new?Label(2,?i+3,?tjhgl.getKm1hgl()));
wsheet.addCell(new?Label(3,?i+3,?tjhgl.getKm2hgl()));
wsheet.addCell(new?Label(4,?i+3,?tjhgl.getKm3hgl()));
wsheet.addCell(new?Label(5,?i+3,?tjhgl.getAvghgl()));
}
本文題目:java代碼數(shù)據(jù)生成圖表 javaweb生成圖表
文章地址:http://fisionsoft.com.cn/article/hgojeg.html