Jaspersoft BI Tools

iReport,Jaspersoft Design Studio,Jaspersoft Server, Schema Workbench,Analysis,Dashboards, Self Service BI, Domains,Topics,Ad-Hoc Reports, Jaspersoft ETL, Embedding BI,HTML-5 charts, Fusion Charts,JFree Charts,Drill down reports , Drill down Dashboards,Visualize.js, Performance Tuning, D3 Charts, Jaspersoft Customization

Monday, July 15, 2013

JFree Line Chart Cusomization in Jasper iReport. Line to Dashed-line, line width,gap in the dashed lines

Hello guys...

Here is the code for customizing Line chart....
The code credit goes to Mr. Shard Sinha.. who is an exprert in cutomizing..

You must read the points in the following artical before you starting this work to do.
http://jasper-bi-suite.blogspot.in/2013/06/jfree-bar-chart-customization-in.html

Grasp.. how to make jar file in NetBeans, How to make jar file, where to keep the jar file, where to call the class in iReport and all the theory related stuff from the above link...

What we are customizing is :
1) Line to Dashed line
2) Line width
3)Gap in the dashed lines

OUTPUT is some thing like as follows:



package com.sadakar.line.chart.customizer;

import java.awt.BasicStroke;

import java.awt.Stroke;

import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;

public class LineChartCustomizer implements  net.sf.jasperreports.engine.JRChartCustomizer{

    @Override
    public void customize(org.jfree.chart.JFreeChart chart, net.sf.jasperreports.engine.JRChart jasperChart) 
    {
        
       CategoryPlot plot = (CategoryPlot) chart.getPlot();
       LineAndShapeRenderer lineAndShapeRenderer =(LineAndShapeRenderer) plot.getRenderer();
       Stroke dashed =  new BasicStroke(1.0f,BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] {10.0f}, 0.0f);
      lineAndShapeRenderer.setBaseStroke(dashed);
       lineAndShapeRenderer.setBaseItemLabelsVisible(false);
      lineAndShapeRenderer.setSeriesStroke(
            0, new BasicStroke(
                1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                1.0f, new float[] {4.0f, 2.0f}, 0.0f
            )
        );
       
    } 
       
    }
    
Thanks,
SADAKAR
Software Engineer in BI
(jasper, pentaho & Talend)