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 !!
Markers (region), multi-line labels
Re: Markers (region), multi-line labels
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
>
> 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
Re: Markers (region), multi-line labels
Hi David,
This is obviously a bug in AbstractXYItemRenderer, but ... it doesn't solve my problem ???
Thx
This is obviously a bug in AbstractXYItemRenderer, but ... it doesn't solve my problem ???
Thx
Re: Markers (region), multi-line labels
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
Regards,
DG
Re: Markers (region), multi-line labels
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
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
Re: Markers (region), multi-line labels
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
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
Re: Markers (region), multi-line labels
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.
I hope this helps.