com.ohalo.cn.awt.JFreeChartTest2.java Source code

Java tutorial

Introduction

Here is the source code for com.ohalo.cn.awt.JFreeChartTest2.java

Source

/**
 * 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 javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;

public class JFreeChartTest2 extends ApplicationFrame {
    /***
    * 
    */
    private static final long serialVersionUID = -3242424710523223716L;

    public JFreeChartTest2(String title) {
        super(title);
        this.setContentPane(createPanel()); // Javapanel??
    }

    public static CategoryDataset createDataset() // ?
    {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.setValue(10, "a", "?");
        dataset.setValue(20, "b", "");
        dataset.setValue(40, "c", "?");
        dataset.setValue(15, "d", "");
        return dataset;
    }

    public static JFreeChart createChart(CategoryDataset dataset) // ?
    {
        JFreeChart chart = ChartFactory.createBarChart("hi", "", "?", dataset,
                PlotOrientation.VERTICAL, true, true, false); // JFreeChart
        chart.setTitle(new TextTitle("??", new Font("", Font.BOLD + Font.ITALIC, 20)));// ???hi?
        CategoryPlot plot = (CategoryPlot) chart.getPlot();// ?plot
        CategoryAxis categoryAxis = plot.getDomainAxis();// ??
        categoryAxis.setLabelFont(new Font("", Font.BOLD, 12));// ??
        return chart;
    }

    public static JPanel createPanel() {
        JFreeChart chart = createChart(createDataset());
        return new ChartPanel(chart); // chartPanel??ChartPanelJpanel
    }

    public static void main(String[] args) {
        JFreeChartTest2 chart = new JFreeChartTest2("??");
        chart.pack();// ??
        chart.setVisible(true);

    }
}