Java tutorial
/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package com.ohalo.cn.awt; import java.awt.Font; import java.io.FileOutputStream; import java.io.OutputStream; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PiePlot; import org.jfree.chart.title.LegendTitle; import org.jfree.chart.title.TextTitle; import org.jfree.data.general.DefaultPieDataset; public class JFreeChartTest3 { public static void main(String[] args) throws Exception { JFreeChart chart = ChartFactory.createPieChart("???", getDataset(), true, true, false); chart.setTitle(new TextTitle("??", new Font("", Font.BOLD + Font.ITALIC, 20))); LegendTitle legend = chart.getLegend(0);// Legend legend.setItemFont(new Font("", Font.BOLD, 14)); PiePlot plot = (PiePlot) chart.getPlot();// Plot plot.setLabelFont(new Font("", Font.BOLD, 16)); OutputStream os = new FileOutputStream("company.jpeg");// ??FileOutputStream? ChartUtilities.writeChartAsJPEG(os, chart, 1000, 800); // ??applicationchart??JPEG?3?4? os.close();// ? } private static DefaultPieDataset getDataset() { DefaultPieDataset dpd = new DefaultPieDataset(); // dpd.setValue("?", 25); // ? dpd.setValue("", 25); dpd.setValue("?", 45); dpd.setValue("", 10); return dpd; } }