Search
Create Chart Instance

Once you have added a JChart.jar reference to your project, you can access the public classes defined in com.mindfusion.charting packages. Chart components that draw specific chart of graphics are implemented by Chart -derived classes (BarChart, RadarChart, etc) and the Dashboard class lets you define more complex dashboard that consist of multiple plots, axes, and graphics types. Charts load data by means of their Series property. A minimal application that draws a barchart looks like this:

Java  Copy Code

import java.awt.*;
import java.util.List;
import javax.swing.*;

import com.mindfusion.drawing.*;
import com.mindfusion.charting.*;
import com.mindfusion.charting.swing.*;

public class MinApp
{
    Chart createChart()
    {
        BarChart chart = new BarChart();

        chart.getXAxis().setInterval(1.0);
        chart.getYAxis().setMaxValue(8.0);

        BarSeries series1 = new BarSeries(
            List.of(2.0, 5.0, 3.0, 4.0), null, null);
        BarSeries series2 = new BarSeries(
            List.of(5.0, 3.0, 4.0, 2.0), null, null);

        chart.getSeries().add(series1);
        chart.getSeries().add(series2);

        return chart;
    }

    MinApp()
    {
        JFrame frame = new JFrame();
        frame.setSize(800, 600);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // add chart component to the middle of the frame
        frame.getContentPane().add(
            createChart(), BorderLayout.CENTER);

        frame.setVisible(true);
    }

    static public void main(String[] args)
    {
        SwingUtilities.invokeLater(MinApp::new);
    }
}

Browse the other sections of this help file to learn more about the functionality provided by the MindFusion.Charting classes, methods and properties. Follow the tutorials to learn different ways to load data and how to build more complex charts.