Hello,
How we can draw the attached chart using jfreechart. i have the XY Points of the curve.
1. The shape would be painted
2. it would be on log scale
any direction would be of great help.
Regards,
Pranav C Lunavat
draw a custom shape chart with colour and log scale
Re: draw a custom shape chart with colour and log scale
i am attaching a sample dataset for one shape
this creates the shape, but i am unable to fill the shape.
Also is this the correct way.. or is there any alternate and better option
Regards,
Pranav C Lunavat
Code: Select all
private static XYDataset createDataset() {
XYSeriesCollection dataset = new XYSeriesCollection();
XYSeries series = new XYSeries("Random Data", false);
XYSeries series1 = new XYSeries("Random Data1", false);
XYSeries series2 = new XYSeries("Random Data2", false);
XYSeries series3 = new XYSeries("Random Data3", false);
// data for Upper Curve
series.add(38.85,34);
series.add(55.5,30.5);
series.add(60,28.8);
// data for lower Curve
series1.add(33.6,19.2);
series1.add(48,17);
series1.add(55,15.4);
// data to join first point of both curve
series2.add(38.85,34);
series2.add(33.6,19.2);
// data to join last point of both curve
series3.add(60,28.8);
series3.add(55,15.4);
dataset.addSeries(series);
dataset.addSeries(series1);
dataset.addSeries(series2);
dataset.addSeries(series3);
return dataset;
}
Also is this the correct way.. or is there any alternate and better option
Regards,
Pranav C Lunavat
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: draw a custom shape chart with colour and log scale
In the screenshot, the lines connecting the data points are apparently slightly curved, so I assume that you have used an XYSplineRenderer.
Unfortunately, this renderer and its "parent" renderer the XYLineAndShapeRenderer only draw the path which is generated from the individual line or curve segments.
After studying the source codes for a while, I suggest to do the following:
Extend XYSplineRenderer, add a field "pathFillPaint" which is an instance of Paint, and override the method drawFirstPassShape(java.awt.Graphics2D g2, int pass, int series, int item, java.awt.Shape shape).In the overriden method, place the following code
You will also have to stuff your data points into a single series for this to work.
[Edit] just tried that with the code snippet provided here. Apparently, that approach does not work because the interpolation used in the XYSplineRenderer leads to a very deformed shape. But you should be able to get a shape with straight lines using a precision of 1.
Unfortunately, this renderer and its "parent" renderer the XYLineAndShapeRenderer only draw the path which is generated from the individual line or curve segments.
After studying the source codes for a while, I suggest to do the following:
Extend XYSplineRenderer, add a field "pathFillPaint" which is an instance of Paint, and override the method drawFirstPassShape(java.awt.Graphics2D g2, int pass, int series, int item, java.awt.Shape shape).In the overriden method, place the following code
Code: Select all
super.drawFirstPassShape(java.awt.Graphics2D g2, int pass, int series, int item, java.awt.Shape shape);
g2.setPaint(pathFillPaint);
g2.fill(shape);
[Edit] just tried that with the code snippet provided here. Apparently, that approach does not work because the interpolation used in the XYSplineRenderer leads to a very deformed shape. But you should be able to get a shape with straight lines using a precision of 1.