/*
* -------------------------------------------------------------------------
* $Id: StackedBar.java,v 1.7 2004/09/01 18:03:17 estewart Exp $
* -------------------------------------------------------------------------
* Copyright (c) 1999 Visual Numerics Inc. All Rights Reserved.
*
* This software is confidential information which is proprietary to
* and a trade secret of Visual Numerics, Inc. Use, duplication or
* disclosure is subject to the terms of an appropriate license
* agreement.
*
* VISUAL NUMERICS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
* SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. VISUAL
* NUMERICS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
* AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR
* ITS DERIVATIVES.
*--------------------------------------------------------------------------
*/
package com.imsl.demo.chart;
import com.imsl.chart.*;
import java.awt.*;
import java.applet.Applet;
public class StackedBar extends Applet {
private Chart chart = null;
public void init() {
chart = new Chart(this);
AxisXY axis = new AxisXY(chart);
chart.setFontName("serif");
chart.setFontSize(14);
int nStacks = 4;
int nGroups = 5;
int nItems = 5;
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++) {
x[kItem] = kItem * dx;
y[iStack][jGroup][kItem] =
1.0 + Math.sin(x[iStack]) + Math.exp(0.1*jGroup) +Math.sqrt(2+kItem);
}
}
}
Bar bar = new Bar(axis, y);
//bar.setBarWidth(0.5*dx);
bar.setFillColor(Color.blue);
//bar.setFillOutlineColor(Color.red);
bar.setFillOutlineType(Bar.FILL_TYPE_SOLID);
bar.getBarSet(0).setFillColor(Color.red);
bar.getBarSet(1).setFillColor(Color.yellow);
bar.getBarSet(2).setFillColor(Color.green);
bar.getBarSet(3).setFillColor(Color.blue);
// axisX.getMajorTick().setPaint(false);
// axisX.getMinorTick().setPaint(false);
axis.setBarType(Bar.BAR_TYPE_VERTICAL);
//axis.setBarGap(1.0);
//bars[0].setFillColor(Color.yellow);
//bars[0].setTitle("Yellow widgets");
//bars[1].getBars()[2].setFillColor(Color.green);
//bars[1].setTitle("Blue widgets");
//bars[0].setGradient(Color.red, Color.green, Color.green, Color.red);
//bars[1].setGradient(Color.white, Color.black, Color.black, Color.white);
//chart.getBackground().setGradient(Color.green, Color.blue, Color.blue, Color.blue);
String labels[] = {"New York", "\u041f\u0440\u043e\u0435", "Northern\nCalifornia", "Colorado", "New Jersey"};
chart.getChartTitle().setTitle("Sales by Region");
axis.getAxisX().getAxisLabel().setLabels(labels);
//axis.getAxisX().getAxisLabel().setTextAngle(90);
// axis.getAxisX().getAxisTitle().setTitle("\u5340 Western: \u0041 \u0042 CJK Unified: \u9662 \u4e01 Hanguel: \uace0 \uc218 Hirigana: \u3041 \u306e Katakana: \u30ad \u30f3");
axis.getAxisX().getAxisLabel().setTextAngle(270);
axis.getAxisX().getMajorTick().setPaint(true);
axis.getAxisX().getMinorTick().setPaint(false);
axis.getAxisX().getAxisTitle().setTitle("Russian \u041f\u0440\u043e\u0435\u043a\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0420\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u043e\u0439 \u0433\u043e\u0441\u0443\u0434\u0430\u0440\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438");
axis.getAxisY().getAxisTitle().setTitle("Sales ($million)\nby widget color");
}
public void update(Graphics g) {
chart.update(g);
}
public void paint(Graphics g) {
chart.paint(g);
}
public static void main(String argv[]) {
StackedBar ex = null;
Frame frame = new Frame();
ex = new StackedBar();
frame.add(ex);
ex.init();
ex.chart.getLegend().setPaint(true);
frame.setSize(new Dimension(400,400));
frame.show();
}
}