skip to main content
Developing with design tools > Using the Designer > Writing an application > Creating a basic Swing application from a JViews Charts component
 
Creating a basic Swing application from a JViews Charts component
The Designer essentially allows you to define a configuration for your chart component, without coding it in Java™. While a Designer project file is not mandatory for writing an application using a JViews Charts component, it is a convenient way to easily configure both the data model and the chart component.
1. Create your GUI with various Swing components, such as a working area, a toolbar, and so on.
getContentPane().add(button, BorderLayout.NORTH);
2. Create an instance of a Chart in the Java API.
 
 // Creates the chart instance on which project file will be applied.
    chart = new IlvChart();
    getContentPane().add(chart, BorderLayout.CENTER);
3. Connect the instance to a data model or load a project file that has been created and saved in the Designer. In this example, we connect a project file that is chosen from a File Browser shown when the button is pressed.
 
JFileChooser fileChooser = new JFileChooser();
...
int ret = fileChooser.showOpenDialog(ProjectViewer.this);
if (ret == JFileChooser.APPROVE_OPTION) {
     File file = fileChooser.getSelectedFile();
     try {
         URL project = file.toURI().toURL();
         // Apply the project file to the chart
         chart.setProject(project);
     } catch (Exception e) {
        e.printStackTrace();
     }
}
See Integrating your development into an application for more about loading a project file.
Instead of loading a project file, you can load a custom data model and then load a style sheet ( .css file) defined in the Designer. In this case, you use only the styling developed with the Designer and not the whole project.
Refer to the samples provided with Rogue Wave® JViews Chart for examples on how to create applications that use charts.
The complete sample ProjectViewer.java is located in:
<installdir>/jviews-charts/codefragments/chart/project-viewer/src/ProjectViewer.java
Refer to Developing with the JViews Charts SDK to see how to create a chart and customize it with the SDK instead of the Designer.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.