/********************************************************************** # Copyright (c) EWA Systems Inc. 1998 - 2005 All Rights Reserved # No part of this program may be photocopied, reproduced, # or translated to another programming language without # the prior written consent of EWA Systems. **********************************************************************/ package com.ewasystems.chart.test; import java.awt.Color; import java.util.Random; import com.ewasystems.chart.AxesXY; import com.ewasystems.chart.Chart; import com.ewasystems.chart.JFrameChart; import com.ewasystems.chart.JPanelChart; import com.ewasystems.chart.bar.ChartBar; /** *

Title: Example Bar Chart #1

*

Copyright: (c) 1998 - 2005

*

Company: EWA Systems, Inc.

* @author Lincoln Evans-Beauchamp * @version 1.0 */ public class BarEx1 extends javax.swing.JApplet { private JPanelChart panel; public void init() { Chart chart = new Chart(this); panel = new JPanelChart(chart); getContentPane().add(panel, java.awt.BorderLayout.CENTER); setup(chart); } static private void setup(Chart chart) { AxesXY axis = new AxesXY(chart); int nStacks = 2; int nGroups = 3; int nItems = 6; // Generate some random data Random r = new Random(123457); double x[] = new double[nItems]; double y[][][] = new double[nStacks][nGroups][nItems]; double dx = 0.5*Math.PI/(x.length-1); for (int istack = 0; istack < y.length; istack++) { for (int jgroup = 0; jgroup < y[istack].length; jgroup++) { for (int kitem = 0; kitem < y[istack][jgroup].length; kitem++) {y[istack][jgroup][kitem] = r.nextDouble();} } } // Create an instance of a Bar Chart ChartBar bar = new ChartBar(axis, y); // Set the Bar Chart Title chart.getChartTitle().setTitle( "Sales by Region" ); // Set the fill outline type; bar.setFillOutlineType(ChartBar.FILL_TYPE_SOLID); // Set the Bar Item fill colors bar.getBarSet(0,0).setFillColor(Color.red); bar.getBarSet(0,1).setFillColor(Color.yellow); bar.getBarSet(0,2).setFillColor(Color.green); bar.getBarSet(1,0).setFillColor(Color.blue); bar.getBarSet(1,1).setFillColor(Color.cyan); bar.getBarSet(1,2).setFillColor(Color.magenta); chart.getChartLegend().setPaint(true); bar.getBarSet(0,0).setTitle( "Red" ); bar.getBarSet(0,1).setTitle( "Yellow" ); bar.getBarSet(0,2).setTitle( "Green" ); bar.getBarSet(1,0).setTitle( "Blue" ); bar.getBarSet(1,1).setTitle( "Cyan" ); bar.getBarSet(1,2).setTitle( "Magenta" ); // Setup the vertical axis for a labeled bar chart. String labels[] = {"New York", "Texas", "Northern\nCalifornia", "Southern\nCalifornia", "Colorado", "New Jersey"}; bar.setLabels(labels, bar.BAR_TYPE_VERTICAL); // Set the text angle axis.getAxisX().getAxisLabel().setTextAngle(270); // Set the Y axis title axis.getAxisY().getAxisTitle().setTitle( "Sales ($million)\nby widget color" ); } public static void main(String argv[]) { JFrameChart frame = new JFrameChart(); BarEx1.setup(frame.getChart()); frame.show(); } }