/*
* Licensed Materials - Property of Rogue Wave Software, Inc.
* © Copyright Rogue Wave Software, Inc. 2014, 2017
* © Copyright IBM Corp. 2009, 2014
* © Copyright ILOG 1996, 2009
* All Rights Reserved.
*
* Note to U.S. Government Users Restricted Rights:
* The Software and Documentation were developed at private expense and
* are "Commercial Items" as that term is defined at 48 CFR 2.101,
* consisting of "Commercial Computer Software" and
* "Commercial Computer Software Documentation", as such terms are
* used in 48 CFR 12.212 or 48 CFR 227.7202-1 through 227.7202-4,
* as applicable.
*/
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import ilog.views.chart.IlvChart;
import ilog.views.chart.IlvChartLayout;
import ilog.views.chart.IlvChartRenderer;
import ilog.views.chart.IlvColor;
import ilog.views.chart.IlvLegend;
import ilog.views.chart.IlvStyle;
import ilog.views.chart.data.IlvDataSource;
import ilog.views.chart.data.IlvDefaultDataSource;
import ilog.views.chart.renderer.IlvHiLoChartRenderer;
import ilog.views.chart.renderer.IlvPolylineChartRenderer;
import ilog.views.util.IlvProductUtil;
public class Cartesian extends JFrame {
/** Creates new Cartesian */
public Cartesian() {
super("Basic Cartesian Chart");
setDefaultCloseOperation(EXIT_ON_CLOSE);
// creates the initial values array
double[][] temps = { { 10, 8, 12, 19, 10, 14, 13 }, { 16, 12, 20, 15, 18, 24, 26 } };
String[] names = { "Morning Temperatures", "Afternoon Temperatures" };
String[] labels = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
// Create one data source to store the temperatures. No x series since
// the x values are actually the index of the y value in the data set
IlvDataSource tempDataSource = new IlvDefaultDataSource(temps, -1, names, labels);
// Create a new cartesian chart
IlvChart chart = new IlvChart();
chart.setAntiAliasing(true);
// Create the renderer that will draw the graphical representation of
// the morning and afternoon temperatures as two distinct polylines.
IlvChartRenderer tempRenderer = new IlvPolylineChartRenderer();
tempRenderer.setDataSource(tempDataSource);
chart.addRenderer(tempRenderer);
// Create the hilo renderer. This renderer shares the same data source
// than the polyline renderer. This is a clear illustration of the
// model-views design of the chart library : one model, two graphical
// representations.
IlvHiLoChartRenderer hiloRenderer = new IlvHiLoChartRenderer();
hiloRenderer.setWidthPercent(40);
hiloRenderer.setDataSource(tempDataSource);
IlvStyle[] styles = { new IlvStyle(Color.black, IlvColor.indianRed),
new IlvStyle(Color.black, IlvColor.cornflowerBlue) };
hiloRenderer.setStyles(styles);
hiloRenderer.getChild(0).setName("Morning/Afternoon Temperatures");
chart.addRenderer(hiloRenderer);
// Customize the scales
chart.getXScale().setCategory(tempDataSource.getDataSet(0), false);
chart.getYScale(0).setStepUnit(new Double(5.), new Double(1.));
// Adding a legend to the chart. The legend is placed within the
// chart area, at an absolute position. When a legend is added with
// the ABSOLUTE constraint and its moveable property value is true (the
// default value), it can be dragged within the chart. The legend is
// said in "floating" mode.
IlvLegend legend = new IlvLegend();
legend.setLocation(50, 30);
chart.addLegend(legend, IlvChartLayout.ABSOLUTE);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(chart, BorderLayout.CENTER);
setSize(500, 400);
}
public static void main(String[] args) {
// This sample uses JViews Charts features. When deploying an
// application that includes this code, you need to be in possession
// of a Rogue Wave JViews Charts Deployment license.
IlvProductUtil.DeploymentLicenseRequired(IlvProductUtil.JViews_Charts_Deployment);
SwingUtilities.invokeLater(new Runnable() {
Override
public void run() {
Cartesian frame = new Cartesian();
frame.setVisible(true);
}
});
}
}