CSS饼图/环形图

.pie {
   width: 300px;
   aspect-ratio: 1; // 设置宽高比
   border-radius: 100%;
   background: conic-gradient(red 0 30%, orange 30% 60%, yellow 60% 85%, blue 85% 100%); // 圆锥形渐变
   display: flex;
   align-items: center;
   justify-content: center;
}
.pie > .inner {
  width: 70%;
  aspect-ratio: 1;
  border-radius: 100%;
  background-color: #fff;
}
.box {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: conic-gradient(red 0deg 90deg, pink 90deg 180deg, yellow 180deg);
}

<body>
	<!-- 环形 -->
  <div class="pie">
    <div class="inner"></div>
  </div>
  <!--饼图-->
  <div class="box"></div>
</body>

Java 可以使用 Apache POI 库来操作 Excel 文件,其中也包括创建饼图环形。 以下是一个简单的示例代码,可以创建一个包含饼图的 Excel 文件: ``` import java.io.FileOutputStream; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.*; public class PieChartExample { public static void main(String[] args) throws Exception { // 创建 Excel 文件 XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Pie Chart"); // 创建数据行 Row row; Cell cell; row = sheet.createRow(0); cell = row.createCell(0); cell.setCellValue("Category"); cell = row.createCell(1); cell.setCellValue("Value"); row = sheet.createRow(1); cell = row.createCell(0); cell.setCellValue("Apples"); cell = row.createCell(1); cell.setCellValue(20); row = sheet.createRow(2); cell = row.createCell(0); cell.setCellValue("Oranges"); cell = row.createCell(1); cell.setCellValue(30); row = sheet.createRow(3); cell = row.createCell(0); cell.setCellValue("Pears"); cell = row.createCell(1); cell.setCellValue(10); row = sheet.createRow(4); cell = row.createCell(0); cell.setCellValue("Bananas"); cell = row.createCell(1); cell.setCellValue(40); // 创建饼图 XSSFDrawing drawing = sheet.createDrawingPatriarch(); XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 5, 1, 15, 15); XSSFChart chart = drawing.createChart(anchor); chart.setTitleText("Fruit Sales"); chart.setTitleOverlay(false); XDDFChartLegend legend = chart.getOrAddLegend(); legend.setPosition(org.apache.poi.xddf.usermodel.chart.LegendPosition.TOP_RIGHT); XDDFDataSource<String> categories = XDDFDataSourcesFactory.fromStringCellRange(sheet, new CellRangeAddress(1, 4, 0, 0)); XDDFNumericalDataSource<Double> values = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(1, 4, 1, 1)); XDDFChartData data = chart.createData(ChartTypes.PIE, null, null); data.setVaryColors(true); data.addSeries(categories, values); chart.plot(data); // 保存文件 FileOutputStream fileOut = new FileOutputStream("PieChartExample.xlsx"); workbook.write(fileOut); fileOut.close(); workbook.close(); } } ``` 这个示例代码创建了一个 Excel 文件,包含一个名为 "Pie Chart" 的工作表,该工作表包含一个简单的数据表格和一个饼图。你可以根据需要修改数据和表的设置来满足你的需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值