I just want to add additional details about the chart. how can i include additional details like in the below pic.
Asked
Active
Viewed 5,232 times
4
-
@Radu Murzea, here before i didnt work with JFreechart. I just hope that solution may be related to XYTextAnnotiation. – A.Mohamed Bilal Jan 30 '14 at 08:06
-
Means u need to add label of that is it?? means label which will contain text is it? – Kishan Bheemajiyani Jan 30 '14 at 10:04
3 Answers
3
final Marker start = new ValueMarker(3400000.0);
start.setPaint(Color.red);
start.setLabel("Current Value");
start.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
start.setLabelTextAnchor(TextAnchor.TOP_LEFT);
plot.addRangeMarker(start);
34,00,000 is counter value. Set counter value as per your need. On (x,y) Axis.

Java Man
- 1,854
- 3
- 21
- 43
1
Try the annotations (e.g., XYDrawableAnnotation). Here's an example:
http://www.java2s.com/Code/Java/Chart/JFreeChartMarkerDemo1.htm

rlegendi
- 10,466
- 3
- 38
- 50
1
You can modify the chart using graphics object. For getting the graphics object of chart:
- Create chart.
- Get the buffered image of the graph.
- fetch buffered image graphics and modify them.
- Convert modified buffered image into the png or jpg format.
Following is the code snippet:
// fetch chart as buffered image
BufferedImage image = chart.createBufferedImage(width, height);
// fetch graphics from the buffered image for perform modifications.
Graphics2D g2 = (Graphics2D) image.getGraphics();
g2.setFont(g2.getFont().deriveFont(30f));
g2.setColor(Color.red);
g2.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, fontSize));
String str = "Test String";
float location_x = 200;
float location_y = 200;
// will draw string horizontally
TextUtilities.drawAlignedString(str, g2, location_x,
location_y, TextAnchor.CENTER_LEFT);
// will draw string Vertically
TextUtilities.drawRotatedString(str, g2, -Math.PI / 2,
location_x, location_y);
g2.dispose();
// generate png file from the modified buffered image
String path = "/sample/test.png";
try {
ImageIO.write(image, "png", new File(path));
} catch (IOException e) {
System.out.println("Error While Creating chart");
e.printStackTrace();
}

Shalinee Tawar
- 31
- 2