SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
BoxChart.java
1/*
2 * Class: BoxChart
3 * Description:
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.charts;
26
27import org.jfree.chart.axis.NumberAxis;
28import org.jfree.chart.ChartFactory;
29import org.jfree.chart.ChartPanel;
30import org.jfree.chart.plot.CategoryPlot;
31import org.jfree.chart.renderer.category.BoxAndWhiskerRenderer;
32import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset;
33import javax.swing.JFrame;
34
56public class BoxChart extends CategoryChart {
57
58 protected void init(String title, String XLabel, String YLabel) {
59 // create the chart...
60 chart = ChartFactory.createBoxAndWhiskerChart(title, // chart title
61 XLabel, // x axis label
62 YLabel, // y axis label
63 (DefaultBoxAndWhiskerCategoryDataset) dataset.getSeriesCollection(), // data
64 true // include legend
65 );
66
67 ((CategoryPlot) chart.getPlot()).setRenderer(dataset.getRenderer());
68 // Initialize axis variables
69 initAxis();
70 }
71
72 protected void initAxis() {
73 YAxis = new Axis((NumberAxis) ((CategoryPlot) chart.getPlot()).getRangeAxis(), Axis.ORIENTATION_VERTICAL);
75 }
76
80 public BoxChart() {
81 super();
82 dataset = new BoxSeriesCollection();
83 init(null, null, null);
84 }
85
99 public BoxChart(String title, String XLabel, String YLabel, double[] data, int numPoints) {
100 super();
101 dataset = new BoxSeriesCollection(data, numPoints);
102 init(title, XLabel, YLabel);
103 }
104
116 public BoxChart(String title, String XLabel, String YLabel, double[]... data) {
117 super();
118 dataset = new BoxSeriesCollection(data);
119 init(title, XLabel, YLabel);
120 }
121
130 public int add(double[] data) {
131 return add(data, data.length);
132 }
133
144 public int add(double[] data, int numPoints) {
145 int seriesIndex = getSeriesCollection().add(data, numPoints);
146 initAxis();
147 return seriesIndex;
148 }
149
156 return (BoxSeriesCollection) dataset;
157 }
158
165 this.dataset = dataset;
166 }
167
173 public void setFillBox(boolean fill) {
174 ((BoxAndWhiskerRenderer) dataset.getRenderer()).setFillBox(fill);
175 }
176
193 public JFrame view(int width, int height) {
194 JFrame myFrame;
195 if (chart.getTitle() != null)
196 myFrame = new JFrame("BoxChart from SSJ : " + chart.getTitle().getText());
197 else
198 myFrame = new JFrame("BoxChart from SSJ");
199 ChartPanel chartPanel = new ChartPanel(chart);
200 chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
201 myFrame.setContentPane(chartPanel);
202 myFrame.pack();
203 myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
204 myFrame.setLocationRelativeTo(null);
205 myFrame.setVisible(true);
206 return myFrame;
207 }
208
212
220 public String toLatex(double width, double height) {
221 throw new UnsupportedOperationException(" NOT implemented yet");
222 /*
223 * double yunit; double[] save = new double[4];
224 *
225 * if(dataset.getSeriesCollection().getColumnCount() == 0) throw new
226 * IllegalArgumentException("Empty chart");
227 *
228 * //Calcul des parametres d'echelle et de decalage double YScale =
229 * computeYScale(YAxis.getTwinAxisPosition());
230 *
231 *
232 * yunit = height / ( (Math.max(YAxis.getAxis().getRange().getUpperBound(),
233 * YAxis.getTwinAxisPosition()) * YScale) -
234 * (Math.min(YAxis.getAxis().getRange().getLowerBound(),
235 * YAxis.getTwinAxisPosition()) * YScale) ); //taille d'une unite en y et en cm
236 * dans l'objet "tikzpicture"
237 *
238 * Formatter formatter = new Formatter(Locale.US);
239 *
240 * // Entete du document formatter.format("\\documentclass[12pt]{article}%n%n");
241 * formatter.format(
242 * "\\usepackage{tikz}%n\\usetikzlibrary{plotmarks}%n\\begin{document}%n%n");
243 * if(chart.getTitle() != null)
244 * formatter.format("%% PGF/TikZ picture from SSJ : %s%n",
245 * chart.getTitle().getText()); else
246 * formatter.format("%% PGF/TikZ picture from SSJ %n");
247 * formatter.format("%% YScale = %s, YShift = %s%n", YScale,
248 * YAxis.getTwinAxisPosition()); formatter.
249 * format("%% and thisFileYValue = (originalSeriesYValue+YShift)*YScale%n%n"
250 * ); if (chart.getTitle() != null) formatter.format("\\begin{figure}%n");
251 * formatter.format("\\begin{center}%n");
252 * formatter.format("\\begin{tikzpicture}[y=%scm]%n", yunit);
253 * formatter.format("\\footnotesize%n"); if(grid)
254 * formatter.format("\\draw[color=lightgray] (%s) grid[ystep=%s] (%s);%n",
255 * (Math.min(YAxis.getAxis().getRange().getLowerBound(),
256 * YAxis.getTwinAxisPosition())-YAxis.getTwinAxisPosition()) * YScale,
257 * ystepGrid*YScale, (Math.max(YAxis.getAxis().getRange().getUpperBound(),
258 * YAxis.getTwinAxisPosition())-YAxis.getTwinAxisPosition()) * YScale );
259 * formatter.format("%s", YAxis.toLatex(YScale) );
260 *
261 * formatter.format("%s", dataset.toLatex(YScale, YAxis.getTwinAxisPosition(),
262 * YAxis.getAxis().getLowerBound(), YAxis.getAxis().getUpperBound()));
263 *
264 * formatter.format("\\end{tikzpicture}%n");
265 * formatter.format("\\end{center}%n"); if (chart.getTitle() != null) {
266 * formatter.format("\\caption{"); formatter.format(chart.getTitle().getText());
267 * formatter.format("}%n\\end{figure}%n"); }
268 * formatter.format("\\end{document}%n"); return formatter.toString();
269 */
270 }
271
272}
273
Represents an axis of a chart encapsulated by an instance of XYChart.
Definition Axis.java:42
void setFillBox(boolean fill)
Sets fill to true, if the boxes are to be filled.
int add(double[] data, int numPoints)
Adds a data series into the series collection.
String toLatex(double width, double height)
NOT IMPLEMENTED.
void setSeriesCollection(BoxSeriesCollection dataset)
Links a new dataset to the current chart.
BoxChart()
Initializes a new BoxChart instance with an empty data set.
Definition BoxChart.java:80
JFrame view(int width, int height)
Displays chart on the screen using Swing.
BoxChart(String title, String XLabel, String YLabel, double[] data, int numPoints)
Initializes a new BoxChart instance with data data.
Definition BoxChart.java:99
int add(double[] data)
Adds a data series into the series collection.
BoxChart(String title, String XLabel, String YLabel, double[]... data)
Initializes a new BoxChart instance with data data.
BoxSeriesCollection getSeriesCollection()
Returns the chart’s dataset.
This class stores data used in a umontreal.ssj.charts.CategoryChart.
int add(double[] data)
Adds a data series into the series collection.
This class provides tools to create charts from data in a simple way.
void setAutoRange()
Sets chart range to automatic values.