Markers (region), multi-line labels

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

Markers (region), multi-line labels

Post by Pierre » Wed Nov 27, 2002 5:12 pm

I'm working on a LineChart.

I put 2 Markers (to indicate a minimum and maximum value), like this;

plot.addRangeMarker(new Marker(max, Color.blue, new BasicStroke(3.0f), Color.blue, 1.0f));

The lines remain dashed, and I don't get thicker lines when changing the width of the BasicStroke.

In fact, I want to highlight the complete region between the minimum and the maximum line. Any idea or tip ?

Finally, is there any way to get multi-line ("\n") labels on the domainaxis ?

Thx !!

David Gilbert

Re: Markers (region), multi-line labels

Post by David Gilbert » Fri Nov 29, 2002 6:56 pm

Pierre wrote:
>
> I'm working on a LineChart.
>
> I put 2 Markers (to indicate a minimum and maximum value),
> like this;
>
> plot.addRangeMarker(new Marker(max, Color.blue, new
> BasicStroke(3.0f), Color.blue, 1.0f));
>
> The lines remain dashed, and I don't get thicker lines when
> changing the width of the BasicStroke.

There was a bug in the AbstractXYItemRenderer class. Change the '==' to '!=' in this line:

g2.setStroke(stroke == null ? stroke : Plot.DEFAULT_OUTLINE_STROKE);

> In fact, I want to highlight the complete region between the
> minimum and the maximum line. Any idea or tip ?

You could create a subclass of Marker (call it RangeMarker) then have the drawDomainMarker and drawRangeMarker(...) methods check for this type and draw a region instead of a line.

> Finally, is there any way to get multi-line ("\n") labels on
> the domainaxis ?

Not yet. It goes on the (long) to-do list.

Regards,

DG

Pierre

Re: Markers (region), multi-line labels

Post by Pierre » Sun Dec 01, 2002 11:33 am

Hi David,

This is obviously a bug in AbstractXYItemRenderer, but ... it doesn't solve my problem ???

Thx

David Gilbert

Re: Markers (region), multi-line labels

Post by David Gilbert » Tue Dec 03, 2002 12:28 am

Sorry, I should have read more carefully. The class that will be drawing the range marker for a line chart is AbstractCategoryItemRenderer. But I can't see anything wrong in the code. Can you post a small sample that reproduces the problem?

Regards,

DG

Pierre

Re: Markers (region), multi-line labels

Post by Pierre » Tue Dec 03, 2002 5:03 pm

Here is a code snippet ;

int cols = 7;

String unit;
String[] categories = new String[cols];
String[] series = new String[1];
Stroke[] seriesStrokeArray = new Stroke[1];

series[0] = "Red blood cells";
categories = {"11/11","13/11","15/11","16/11","18/11","19/11","20/11"};

seriesStrokeArray[0] = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND);

unit = "10 exp 12 / L";

double min = 10;
double max = 20;

Number[][] data = new Float[][] {{16, 11, 11, 45, 45, 11, 12}};

DefaultCategoryDataset dataset = new DefaultCategoryDataset(data);
dataset.setCategories(categories);
dataset.setSeriesNames(series);

JFreeChart graph = ChartFactory.createLineChart(patientName,"Date",unit,dataset,true);
CategoryPlot plot = (CategoryPlot) graph.getPlot();
LineAndShapeRenderer renderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES_AND_LINES);
plot.setRenderer(renderer);
plot.setSeriesStroke(seriesStrokeArray);
plot.setValueLabelsVisible(true);

plot.addRangeMarker(new Marker(min, Color.blue, new BasicStroke(10.0f), Color.blue, 1.0f));
plot.addRangeMarker(new Marker(max, Color.blue, new BasicStroke(3.0f), Color.blue, 1.0f));

ChartFrame frame = new ChartFrame(patname, graph);
frame.pack();
frame.show();


Regards,

Pierre

David Gilbert

Re: Markers (region), multi-line labels

Post by David Gilbert » Wed Dec 04, 2002 11:57 am

Hi Pierre,

This works against the CVS version of JFreeChart, but the bug shows up against the 0.9.4 release. I'm not completely sure what has changed...

Regards,

DG

Suprigya

Re: Markers (region), multi-line labels

Post by Suprigya » Thu Dec 12, 2002 9:12 pm

The problem is happening because you are using the LineAndShapeRenderer. The drawRangeMarker method on it doesn't take marker object's stroke while drawing a line. You can extend this class and write your own drawRangeMarker in which the Graphics2D object will set the stroke based on one set on Marker.

I hope this helps.

Locked