SaveJpegChart.java
资源名称:OA.rar [点击查看]
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:1k
源码类别:
OA系统
开发平台:
Java
- ////////////////////////////////////////////////////////////////
- // SaveJpegChart.java
- ////////////////////////////////////////////////////////////////
- package cn.com.fcsoft.chart.examples;
- import cn.com.fcsoft.chart.*;
- import cn.com.fcsoft.chart.jpeg.*;
- import java.awt.*;
- import java.io.*;
- /**
- * This class generates a chart and writes it as a jpeg file.
- * @author meiqi.
- */
- public class SaveJpegChart {
- /**
- * Creates a chart and writes it to the specified file.
- */
- public static void main(String[] argv) {
- //create the chart
- BarChart chart = new BarChart(5);
- double[] values = new double[] {100, 200, 300, 400, 500};
- chart.setSampleValues(0, values);
- chart.setRange(0, 500);
- chart.set3DModeOn(true);
- chart.setTitle("Chart generated as a JPEG");
- chart.setTitleOn(true);
- chart.setValueLinesOn(true);
- // write the chart as a gif to the specified file
- try {
- Image image = chart.getImage(300,200);
- String file = (argv.length > 0 ? argv[0] : "chart.jpg");
- FileOutputStream out = new FileOutputStream(file);
- JpegEncoder encoder = new JpegEncoder(image, 75, out);
- encoder.Compress();
- out.flush();
- } catch (IOException e) {
- e.printStackTrace();
- }
- System.exit(0);
- }
- }