Problems in OverlaidVerticalCategoryPlot class

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Deepak Bhatt

Problems in OverlaidVerticalCategoryPlot class

Post by Deepak Bhatt » Wed Jan 08, 2003 11:13 am

Hi,
I am trying to use OverlaidVertical Category Plot class to plot a overlaid chart, And I am using OverlaidVerticalCategoryPlotDemo.java class.
The problem I am getting that The range Axis and Domain Axis comes properly but the actual chart does not appear.Or chart I am getting is empty.
I am plotting the chart with the hard coded data still it does not work.

Please provide some pointers for the same.

Thanks in Advance.
Regards,
Deepak Bhatt.

David Gilbert

Re: Problems in OverlaidVerticalCategoryPlot class

Post by David Gilbert » Thu Jan 09, 2003 7:29 am

Hi Deepak,

E-mail me a sample application that shows the problem, and I'll take a look.

Regards,

Dave Gilbert

Deepak Bhatt

Re: Problems in OverlaidVerticalCategoryPlot class

Post by Deepak Bhatt » Thu Jan 09, 2003 9:51 am

Hi Dave,

Thank you very much for reply.
I tell you the task which I have to do.I need a chart having Bars and 2 lines.In Bar chart labels should be displayed in '%' as 67%,32% etc. , and the domain axis (Y axis) ticks should also be displayed in '%'.

So I am using OverlaidVerticalCategoryPlot for the same and adding 3 subplos to it.But Only Range axis and Domain Axis with labels are getting displayed actual chart is not displayed.

Then I used the OverlaidCategoryChartDemo class provided by JFreechart samples.If I run the class same thing is happening , I mean the actual chart is coming empty again.

I am attaching the code here.
The code is in between the dotted lines.

-------------------------------------------------------------------------------------------
package com.jrefinery.chart.demo;

import java.awt.Color;
import java.awt.Font;
import java.text.DecimalFormat;
import com.jrefinery.chart.ChartPanel;
import com.jrefinery.chart.HorizontalCategoryAxis;
import com.jrefinery.chart.JFreeChart;
import com.jrefinery.chart.LineAndShapeRenderer;
import com.jrefinery.chart.NumberTickUnit;
import com.jrefinery.chart.OverlaidVerticalCategoryPlot;
import com.jrefinery.chart.SeriesShapeFactory;
import com.jrefinery.chart.VerticalCategoryPlot;
import com.jrefinery.chart.VerticalIntervalBarRenderer;
import com.jrefinery.chart.VerticalNumberAxis;
import com.jrefinery.data.DefaultCategoryDataset;
import com.jrefinery.data.DefaultIntervalCategoryDataset;
import com.jrefinery.ui.ApplicationFrame;
import com.jrefinery.ui.RefineryUtilities;

/**
* An overlaid category chart.
*
* @author JB
*/
public class OverlaidCategoryChartDemo extends ApplicationFrame {

/** The categories. */
private static final String[] CATEGORIES = { "1", "3", "5", "10", "20" };

/** The bar colors. */
private static Color[] barColors = null;

/** The dot colors. */
private static Color[] dotColors = null;

/** The line colors. */
private static Color[] lineColors = null;

/** The label font. */
private static Font labelFont = null;

/** The bold label font. */
private static Font boldLabelFont = null;

/** The title font. */
private static Font titleFont = null;

/** The chart. */
private JFreeChart chart = null;

static {
barColors = new Color[1];
barColors[0] = new Color(51, 102, 153);
dotColors = new Color[1];
dotColors[0] = Color.white;
lineColors = new Color[4];
lineColors[0] = Color.red;
lineColors[1] = Color.blue;
lineColors[2] = Color.yellow;
lineColors[3] = Color.magenta;
labelFont = new Font("Helvetica", Font.PLAIN, 10);
boldLabelFont = new Font("Helvetica", Font.BOLD, 10);
titleFont = new Font("Helvetica", Font.BOLD, 14);
}

/**
* Creates a new demo.
*
* @param title the frame title.
*/
public OverlaidCategoryChartDemo(String title) {

super(title);
DefaultIntervalCategoryDataset barData = null;
double[][] lows = { { -.0315, .0159, .0306, .0453, .0557 } };
double[][] highs = { { .1931, .1457, .1310, .1163, .1059 } };
barData = new DefaultIntervalCategoryDataset(lows, highs);

DefaultCategoryDataset dotData = null;
double[][] vals = { { 0.0808, 0.0808, 0.0808, 0.0808, 0.0808 } };
dotData = new DefaultCategoryDataset(vals);
DefaultCategoryDataset lineData = null;
double[][] lineVals = new double[4][5];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
lineVals[j] = (Math.random() * 0.56) - 0.18;
}
}
lineData = new DefaultCategoryDataset(lineVals);

String ctitle = "Strategie Sicherheit";
String xTitle = "Zeitraum (in Jahren)";
String yTitle = "Performance";
HorizontalCategoryAxis xAxis = new HorizontalCategoryAxis(xTitle);
xAxis.setLabelFont(titleFont);
xAxis.setTickLabelFont(labelFont);
xAxis.setTickMarksVisible(false);
VerticalNumberAxis yAxis = new VerticalNumberAxis(yTitle);
yAxis.setLabelFont(titleFont);
yAxis.setTickLabelFont(labelFont);
yAxis.setMinimumAxisValue(-0.2);
yAxis.setMaximumAxisValue(0.4);
DecimalFormat formatter = new DecimalFormat("0.##%");
yAxis.setTickUnit(new NumberTickUnit(0.05, formatter));

OverlaidVerticalCategoryPlot plot
= new OverlaidVerticalCategoryPlot(xAxis, yAxis, CATEGORIES);
plot.setBackgroundPaint(Color.lightGray);
plot.setOutlinePaint(Color.black);

VerticalIntervalBarRenderer barRenderer = null;
barRenderer = new VerticalIntervalBarRenderer();
VerticalCategoryPlot bars = null;
bars = new VerticalCategoryPlot(barData, null, null, barRenderer);
bars.setLabelsVisible(true);
bars.setLabelFont(labelFont);
bars.setLabelFormatString("0.##%");
bars.setSeriesPaint(barColors);
plot.add(bars);

LineAndShapeRenderer dotRenderer = null;
dotRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES,
LineAndShapeRenderer.RIGHT);
VerticalCategoryPlot dots = null;
dots = new VerticalCategoryPlot(dotData, null, null, dotRenderer);
dots.setLabelsVisible(true);
dots.setLabelFont(boldLabelFont);
dots.setLabelPaint(Color.white);
dots.setLabelFormatString("0.##%");
dots.setSeriesPaint(dotColors);
dots.setShapeFactory(new SeriesShapeFactory());
plot.add(dots);

LineAndShapeRenderer lineRenderer = null;
lineRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES_AND_LINES);
VerticalCategoryPlot lines = null;
lines = new VerticalCategoryPlot(lineData, null, null, lineRenderer);
lines.setSeriesPaint(lineColors);
lines.setShapeFactory(new SeriesShapeFactory());
plot.add(lines);

chart = new JFreeChart(ctitle, titleFont, plot, false);
chart.setBackgroundPaint(Color.white);

ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);

}

/**
* Starting point for the demo.
*
* @param args ignored.
*/
public static void main(String[] args) {

OverlaidCategoryChartDemo demo
= new OverlaidCategoryChartDemo("Overlaid Category Chart Demo");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);

}

}
-------------------------------------------------------------------------------------------


Please have a look at it.I doubt there are some problems in OverlaidVerticalCategoryPlot class.

Regards,
Deepak.

Locked