Shapes on Area Chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
sainath
Posts: 3
Joined: Fri Mar 29, 2019 7:20 am
antibot: No, of course not.

Shapes on Area Chart

Post by sainath » Fri Mar 29, 2019 8:15 am

Hi,

I am new to Jfreechart library I am using AreaChart it working fine but I want shapes(triangle, squares, circles) on areachart to point the data. Like shapes in line chart. Is there anyway to implement for area chart?

In my project to paint chart binding the data dynamically. If data contains huge information then on X-axis scale is not rending properly. It is looking as a line. How to solve this problem.

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Shapes on Area Chart

Post by John Matthews » Sun Mar 31, 2019 9:07 am

  1. Looking the annotations, e.g. XYShapeAnnotation or XYPointerAnnotation.
  2. Use the zoom and pan features mentioned here as needed.

sainath
Posts: 3
Joined: Fri Mar 29, 2019 7:20 am
antibot: No, of course not.

Re: Shapes on Area Chart

Post by sainath » Mon Apr 01, 2019 9:12 am

Hi,

1. Thank you! John Matthews for your answer. I am using category plot not XY plot. In XY plots we can add dataseries only number type but my requirement is number, String type. Is there any way to give shapes for category area chart?

2. My requirement is to save the plot as image so zoom and pan will not work in the image. Can we set the range on X-axis for Category plots?

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Shapes on Area Chart

Post by John Matthews » Tue Apr 02, 2019 1:43 am

[[/list]

sainath
Posts: 3
Joined: Fri Mar 29, 2019 7:20 am
antibot: No, of course not.

Re: Shapes on Area Chart

Post by sainath » Tue Apr 02, 2019 10:51 am

Hi,

Thank you, John! I have implemented using time series in XYAreaChart as per my requirement.

Now my requirement is I have only one series in XYAreaChart but I need to differentiate datapoints with shapes. I want to add squares in green and triangles in red color. Is it possible to add different shapes in the same series?

Here is my code:

Code: Select all

JFreeChart areaChart= ChartFactory.createXYAreaChart(
	    		"Heap Usage (after GC)","Time "+data.get(GraphDataBuilder.ZONE_OFFSET),
	    		"Heap size ("+data.get(GraphDataBuilder.Y_AXIS_SCALE)+")",
	    		line_chart_dataset,PlotOrientation.VERTICAL,
	    		true,true,false);
		
	    XYPlot plot = areaChart.getXYPlot();
	    XYAreaRenderer renderer = new XYAreaRenderer(XYAreaRenderer.AREA_AND_SHAPES);
	    DateAxis domain = new DateAxis("Time");
	    domain.setAutoRange(true);
	    if(rawJVMDuration > 84000000) {
	    	
	    	domain.setDateFormatOverride(new SimpleDateFormat("MMM-dd hh:mm"));
	    } else {
	    	
	    	domain.setDateFormatOverride(new SimpleDateFormat("hh:mm:ss a"));
	    }
	    plot.setDomainAxis(domain);
	   
	    Shape shape = new Ellipse2D.Double(-4, -4, 10, 10);
	    //renderer.setSeriesShape(0, ShapeUtilities.createUpTriangle(5.5f));
	    plot.setRenderer(renderer);
	    plot.getRenderer().setSeriesPaint(0, Color.decode("#1fb5ab"));
	    

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Shapes on Area Chart

Post by John Matthews » Wed Apr 03, 2019 5:12 pm

The API suggests that you override getItemShape().

Locked