Custom chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
rakeshshelar
Posts: 1
Joined: Fri Feb 07, 2014 9:20 am
antibot: No, of course not.

Custom chart

Post by rakeshshelar » Fri Feb 07, 2014 12:02 pm

Please refer image here for our custom chart implementation
Image

here is image
https://drive.google.com/file/d/0BxD8cR ... sp=sharing

I would like to confirm circled part of chart in above image it can be limitation or there is any direction you provide to implement same chart. we have used value marker to draw blue, red, and black lines on the bar.
Also that markers touches end to end to entire plot and as per our expcted chart it should be start at particular bar point and write on chart canvas as annotations.
please provide direction for the same

Regards,
Rakesh

Code is here
_________________________


import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.util.List;
import net.sf.jasperreports.engine.JRAbstractChartCustomizer;
import net.sf.jasperreports.engine.JRChart;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.annotations.CategoryTextAnnotation;
import org.jfree.chart.axis.CategoryAnchor;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.Marker;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.chart.renderer.category.StackedBarRenderer;
import org.jfree.ui.Layer;
import org.jfree.ui.TextAnchor;

/**
*
* @author Rakesh.Shelar
*/
public class ThermometerChartCustomizer extends JRAbstractChartCustomizer{

@Override
public void customize(JFreeChart chart, JRChart jrChart) {

CategoryPlot plot = chart.getCategoryPlot();
StackedBarRenderer stackedbarrenderer = (StackedBarRenderer)plot.getRenderer();
stackedbarrenderer.setSeriesPaint(0, new Color(251, 206, 95));//worse than expected
stackedbarrenderer.setSeriesPaint(1, new Color(168, 217, 115));//current surgen
stackedbarrenderer.setSeriesPaint(2, new Color(168, 217, 115));//national average
stackedbarrenderer.setSeriesPaint(3, new Color(168, 217, 115));//better than expected
stackedbarrenderer.setMaximumBarWidth(0.50); //bar width
plot.getDomainAxis().setLowerMargin(0.30);
plot.getDomainAxis().setCategoryMargin(.30);
plot.setRenderer(stackedbarrenderer);

List catTotal = plot.getCategories();
System.out.println("here 1");
double catName = (Double)catTotal.get(catTotal.size()-1);
//double catName = catTotal.get(catTotal.size()-1);
System.out.println("here 2");
ValueMarker marker = new ValueMarker((Double)plot.getDataset().getValue(0, 0));
Color color= new Color(0x2c6487); //custom color for line quua
marker.setPaint(color);
marker.setStroke(new BasicStroke(7.0F)); //thickness for dottted marker
CategoryTextAnnotation categoryAnnotation = new CategoryTextAnnotation("Worst than", catName , (Double)plot.getDataset().getValue(0, 0)-.20);
categoryAnnotation.setFont(new Font("SansSerif", Font.PLAIN, 10));
categoryAnnotation.setTextAnchor(TextAnchor.BOTTOM_CENTER);
categoryAnnotation.setCategoryAnchor(CategoryAnchor.START);
plot.addAnnotation(categoryAnnotation);
plot.addRangeMarker(marker);

marker = new ValueMarker((Double)plot.getDataset().getValue(1, 0));
color= new Color(0xfe0200); //custom color for line quua
marker.setPaint(color);
marker.setStroke(new BasicStroke(7.0F)); //thickness for dottted marker
marker.set
categoryAnnotation = new CategoryTextAnnotation("THIS SURGEON", catName , (Double)plot.getDataset().getValue(1, 0)-.20);
categoryAnnotation.setFont(new Font("SansSerif", Font.BOLD, 10));
categoryAnnotation.setTextAnchor(TextAnchor.BOTTOM_CENTER);
categoryAnnotation.setCategoryAnchor(CategoryAnchor.START);
plot.addAnnotation(categoryAnnotation);
plot.addRangeMarker(marker);

marker = new ValueMarker((Double)plot.getDataset().getValue(2, 0));
color= new Color(0x010007); //custom color for line quua
marker.setPaint(color);
marker.setStroke(new BasicStroke(7.0F)); //thickness for dottted marker
categoryAnnotation = new CategoryTextAnnotation("National Average", catName , (Double)plot.getDataset().getValue(2, 0)+ .20);
categoryAnnotation.setFont(new Font("SansSerif", Font.PLAIN, 10));
categoryAnnotation.setTextAnchor(TextAnchor.BOTTOM_CENTER);
categoryAnnotation.setCategoryAnchor(CategoryAnchor.END);

plot.addAnnotation(categoryAnnotation);
plot.addRangeMarker(marker);

marker = new ValueMarker(1.503596237);

color= new Color(0x2c6487); //custom color for line quua
marker.setPaint(color);
marker.setStroke(new BasicStroke(7.0F)); //thickness for dottted marker
categoryAnnotation = new CategoryTextAnnotation("Better than Expected", catName , 1.503596237 + .35);
categoryAnnotation.setFont(new Font("SansSerif", Font.PLAIN, 10));
categoryAnnotation.setTextAnchor(TextAnchor.BOTTOM_CENTER);
categoryAnnotation.setCategoryAnchor(CategoryAnchor.START);
plot.addAnnotation(categoryAnnotation);
plot.addRangeMarker(marker);


chart.setTitle(""); //set chart title off
chart.setBackgroundPaint(new Color(220, 230, 242)); //set chart background color
chart.setBorderVisible(false); //chart border off
chart.removeLegend();//remove legend

plot.setBackgroundPaint(new Color(220, 230, 242)); //set plot color
plot.setOutlineVisible(false); //plot outline off
plot.setOrientation(PlotOrientation.HORIZONTAL); //set oriention
plot.getRangeAxis().setAxisLineVisible(false); //range axis line off
plot.getDomainAxis().setAxisLineVisible(false); //domain axis line off
plot.setDomainCrosshairVisible(false);
plot.setRangeCrosshairVisible(false);
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
plot.getDomainAxis().setMinorTickMarksVisible(false);
plot.getRangeAxis().setMinorTickMarksVisible(false);
plot.getDomainAxis().setTickMarksVisible(false);//tick marks of scales off
plot.getRangeAxis().setTickMarksVisible(false); //tick marks of scales off
plot.getDomainAxis().setTickLabelsVisible(false);//scale numbers off
plot.getRangeAxis().setTickLabelsVisible(false); //scale numbers off
plot.getRangeAxis().setLabel(null); //axis lable off
plot.getDomainAxis().setLabel(null); //axis label off
/*CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setOrientation(PlotOrientation.HORIZONTAL);
chart.setBackgroundPaint(Color.WHITE);
chart.setTitle("");
chart.setBorderVisible(false);
chart.removeLegend();


plot.setBackgroundPaint(new Color(220, 230, 242));
chart.setBackgroundPaint(Color.WHITE);
plot.setOutlineVisible(false);



plot.getRangeAxis().setAxisLineVisible(false);
plot.getDomainAxis().setAxisLineVisible(false);
plot.setDomainCrosshairVisible(false);
plot.setRangeCrosshairVisible(false);
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
// plot.setRangeZeroBaselineVisible(false);
plot.getDomainAxis().setTickLabelsVisible(false);
plot.getDomainAxis().setMinorTickMarksVisible(false);
plot.getRangeAxis().setTickLabelsVisible(false);
plot.getRangeAxis().setMinorTickMarksVisible(false);
plot.getDomainAxis().setTickMarksVisible(false);
plot.getRangeAxis().setTickMarksVisible(false);
plot.getRangeAxis().setLabel(null);
plot.getDomainAxis().setLabel(null);




StackedBarRenderer stackedbarrenderer = (StackedBarRenderer)plot.getRenderer();
//stackedbarrenderer.setDrawBarOutline(true);
//stackedbarrenderer.setMaximumBarWidth(0.4);
System.out.println(stackedbarrenderer.getMaximumBarWidth());
Marker baseline = new ValueMarker(5.0);
baseline.setPaint(Color.black);
plot.addRangeMarker(baseline, Layer.FOREGROUND);


stackedbarrenderer.setSeriesOutlineStroke(2, new BasicStroke(2.0F));
stackedbarrenderer.setSeriesOutlinePaint(3, Color.RED);


stackedbarrenderer.setSeriesPaint(0, new Color(251, 206, 95)); //worse than expected
stackedbarrenderer.setSeriesPaint(1, new Color(168, 217, 115)); //current surgen
stackedbarrenderer.setSeriesPaint(2, new Color(168, 217, 115)); //national average
stackedbarrenderer.setSeriesPaint(3, new Color(168, 217, 115)); //better than expected
*/
}

}

Locked