用我現(xiàn)在用的finereport來和題主說下餅圖吧,它也是web報(bào)表工具。

創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比泰山網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式泰山網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋泰山地區(qū)。費(fèi)用合理售后完善,10余年實(shí)體公司更值得信賴。
打開報(bào)表,設(shè)置百分比數(shù)據(jù)模板
符合餅圖和復(fù)合條餅圖只支持百分比的系列分隔方式,因此我們計(jì)算每個(gè)地區(qū)的應(yīng)付金額所占比例是多少,隱藏B列,在C1中輸入占比,C2中輸入公式:=B2/SUM(B2[!0]),B2[!0]是B2擴(kuò)展出來的所有單元格,根據(jù)情況設(shè)置單元格樣式等操作。
下面以制作符合餅圖為例,選中圖表,勾線圖表屬性表-樣式系列中的第二繪圖區(qū),將第二繪圖區(qū)小于百分比的數(shù)據(jù)改為10,默認(rèn)為5,表示第二繪圖區(qū)包含所有小于該百分比的值為:如下圖:
根據(jù)情況可設(shè)置系列標(biāo)簽樣式,勾選圖表屬性表-樣式標(biāo)簽中的標(biāo)簽,選中值,設(shè)置格式,百分比保留兩位小數(shù)。
修改圖表數(shù)據(jù)
修改圖表屬性表-數(shù)據(jù)圖例項(xiàng)值為C2單元格,復(fù)合餅圖則可設(shè)置完成。
預(yù)覽與保存
保存模板,點(diǎn)擊分頁預(yù)覽,即可看到效果。
我.net中也遇到了相同的問題:你可以先看一下下面代碼,應(yīng)該大部分你能用到,只是chart屬性可能有點(diǎn)問題,之前嘗試成功過,但是由于我不小心刪除了一些系統(tǒng)文件里的內(nèi)容,就有些運(yùn)行不起來了
我是先循環(huán)的word中的shape
foreach (Microsoft.Office.Interop.Word.Shape shape in docFile.Shapes)
{
if(shape.Name=="Chart_圖表")
{
shape.Chart.ChartData.Activate();
Microsoft.Office.Interop.Excel.Workbook wb = (Microsoft.Office.Interop.Excel.Workbook)shape.Chart.ChartData.Workbook;
Microsoft.Office.Interop.Excel.Worksheet wSh = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1];
//然后添加新數(shù)據(jù)
for (int r = 0; r tempdt.Rows.Count; r++)
{
for (int k = 0; k tempdt.Columns.Count; k++)
{
Microsoft.Office.Interop.Excel.Range Rng1 = wSh.Cells[r + 2, k + 1] as Microsoft.Office.Interop.Excel.Range;
Rng1.Value = tempdt.Rows[r][k];
}
}
wb.Application.ScreenUpdating = true;
wb.Close(Type.Missing, Type.Missing, Type.Missing);
chart.Refresh();
shape.Chart.Refresh();
}
}
java echarts是什么,讓我們一起了解一下:
ECharts是一款基于JavaScript的數(shù)據(jù)可視化圖表庫,提供直觀,生動(dòng),可交互,可個(gè)性化定制的數(shù)據(jù)可視化圖表,ECharts提供了常規(guī)的折線圖、柱狀圖、散點(diǎn)圖、餅圖、K線圖。
echarts的特點(diǎn)有哪些?
1、ECharts 屬于開源軟件,并且為我們提供了非常炫酷的圖形界面,特色是地圖,另外還提供了柱狀圖、折線圖、餅圖、氣泡圖及四象限圖等。
2、ECharts 使用簡(jiǎn)單,在官網(wǎng)中為我們封裝了 JS,只要會(huì)引用就會(huì)得到完美的展示效果。
3、ECharts 種類多,ECharts 實(shí)現(xiàn)簡(jiǎn)單,各類圖形都有;相應(yīng)的模板,還有豐富的 API 及文檔說明,非常詳細(xì)。
4、ECharts 兼容性好,基于HTML5,有著良好的動(dòng)畫渲染效果。
Java開發(fā)中Echarts是如何使用的?
我們以最簡(jiǎn)單的柱狀圖為例,采用Echarts插件,代碼如下: ? ? ? ? 測(cè)試echarts ? ? ? ? ?
//參考地址去網(wǎng)站下js控件,下面是餅圖的代碼,下圖是我的代碼效果
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/{b}?(ec0kike%)"
},
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);
}
用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
{
//設(shè)置主題
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, 設(shè)置圖表的標(biāo)題
* java.lang.String categoryAxisLabel, 設(shè)置分類軸的標(biāo)示
* java.lang.String valueAxisLabel, 設(shè)置值軸的標(biāo)示
* CategoryDataset dataset, 設(shè)置數(shù)據(jù)
* PlotOrientation orientation, 設(shè)置圖表的方向
* boolean legend, 設(shè)置是否顯示圖例
* boolean tooltips,設(shè)置是否生成熱點(diǎn)工具
* boolean urls) 設(shè)置是否顯示url
*/
JFreeChart chart = ChartFactory.createBarChart3D("編程語言統(tǒng)計(jì)", "語言",
"學(xué)習(xí)人數(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();
}
}
}
===================================================================================
//一條線 有點(diǎn) 有數(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í)間曲線數(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);
//增加標(biāo)題
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ū)與坐標(biāo)軸的距離
plot.setOutlinePaint(Color.PINK);
plot.setInsets(new RectangleInsets(15,15,15,15));//坐標(biāo)軸與最外延的距離
// plot.setOrientation(PlotOrientation.HORIZONTAL);//圖形的方向,包括坐標(biāo)軸。
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è)置曲線是否顯示數(shù)據(jù)點(diǎn)
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer();
xylineandshaperenderer.setBaseShapesVisible(true);
// 設(shè)置曲線顯示各數(shù)據(jù)點(diǎn)的值
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程序?qū)С鰩D表的excel嗎?參考下面用spire.xls.jar來創(chuàng)建Excel圖表的方法,這里以創(chuàng)建餅圖為例,當(dāng)然你也可以指定創(chuàng)建其他圖表類型,如柱狀圖、折線圖、雷達(dá)圖、散點(diǎn)圖等等:
import com.spire.xls.*;
import com.spire.xls.charts.ChartSerie;
import java.awt.*;
public class CreatePieChart {
public static void main(String[] args) {
//創(chuàng)建Workbook對(duì)象
Workbook workbook = new Workbook();
//獲取第一個(gè)工作表
Worksheet sheet = workbook.getWorksheets().get(0);
//將圖表數(shù)據(jù)寫入工作表
sheet.getCellRange("A1").setValue("年份");
sheet.getCellRange("A2").setValue("2002");
sheet.getCellRange("A3").setValue("2003");
sheet.getCellRange("A4").setValue("2004");
sheet.getCellRange("A5").setValue("2005");
sheet.getCellRange("B1").setValue("銷售額");
sheet.getCellRange("B2").setNumberValue(4000);
sheet.getCellRange("B3").setNumberValue(6000);
sheet.getCellRange("B4").setNumberValue(7000);
sheet.getCellRange("B5").setNumberValue(8500);
//設(shè)置單元格樣式
sheet.getCellRange("A1:B1").setRowHeight(15);
sheet.getCellRange("A1:B1").getCellStyle().setColor(Color.darkGray);
sheet.getCellRange("A1:B1").getCellStyle().getExcelFont().setColor(Color.white);
sheet.getCellRange("A1:B1").getCellStyle().setVerticalAlignment(VerticalAlignType.Center);
sheet.getCellRange("A1:B1").getCellStyle().setHorizontalAlignment(HorizontalAlignType.Center);
sheet.getCellRange("B2:C5").getCellStyle().setNumberFormat("\"¥\"#,##0");
//添加餅圖
Chart chart = sheet.getCharts().add(ExcelChartType.Pie);
//設(shè)置圖表數(shù)據(jù)區(qū)域
chart.setDataRange(sheet.getCellRange("B2:B5"));
chart.setSeriesDataFromRange(false);
//設(shè)置圖表位置
chart.setLeftColumn(3);
chart.setTopRow(1);
chart.setRightColumn(11);
chart.setBottomRow(20);
//設(shè)置圖表標(biāo)題
chart.setChartTitle("年銷售額");
chart.getChartTitleArea().isBold(true);
chart.getChartTitleArea().setSize(12);
//設(shè)置系列標(biāo)簽
ChartSerie cs = chart.getSeries().get(0);
cs.setCategoryLabels(sheet.getCellRange("A2:A5"));
cs.setValues(sheet.getCellRange("B2:B5"));
cs.getDataPoints().getDefaultDataPoint().getDataLabels().hasValue(true);
chart.getPlotArea().getFill().setVisible(false);
//保存文檔
workbook.saveToFile("output/PieChart.xlsx", ExcelVersion.Version2016);
}
}
餅圖創(chuàng)建效果:
excel餅狀圖效果
分享名稱:java圖表代碼 java編程圖
分享路徑:http://chinadenli.net/article34/hjoipe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、動(dòng)態(tài)網(wǎng)站、定制網(wǎng)站、網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)