Hi,
How can I control colour on my chart, I am using bbar3DPlot and I would like to have different colour on each bar. If I use pie3DPlot then it renders with different colour and I am trying to have the same thing with bar3DPlot. I am attaching my .jrxml file. Any help would be greatyly appreciated.
Thanks in advance.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="YaChartReport" language="java" columnCount="2" pageWidth="595" pageHeight="842" columnWidth="270" columnSpacing="15" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30">
<style name="Arial_Normal" isDefault="true" fontName="Arial" fontSize="8" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<style name="Arial_Bold" isDefault="false" fontName="Arial" fontSize="8" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<style name="Arial_Italic" isDefault="false" fontName="Arial" fontSize="8" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Oblique" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<style name="Comic_Normal" isDefault="false" fontName="Comic Sans MS" fontSize="10" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="COMIC.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
<style name="Comic_Bold" isDefault="false" fontName="Comic Sans MS" fontSize="10" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="COMICBD.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
<parameter name="ReportTitle" class="java.lang.String">
</parameter>
<queryString><![CDATA[SELECT ProductTypeDisplayName, count(ProductTypeDisplayName) as numberofproduct FROM yabank.Application a, yabank.ApplicantApplication aa, yabank.Applicant p, yabank.ProductType, yabank.Name WHERE a.ApplicationId = aa.Application_ApplicationId AND p.ApplicantId = aa.Applicant_ApplicantId AND ProductTypeId = a.ProductType_ProductTypeId AND Name_NameId = NameId group by ProductTypeDisplayName]]></queryString>
<field name="ProductTypeDisplayName" class="java.lang.String">
</field>
<field name="numberofproduct" class="java.lang.Integer">
</field>
<variable name="ProductTypeDisplayNameSumGroup" class="java.lang.Integer" resetType="None">
<variableExpression><![CDATA[$F{numberofproduct}]]></variableExpression>
</variable>
<group name="ProductTypeGroup" isStartNewColumn="true" isReprintHeaderOnEachPage="false" minHeightToStartNewPage="200">
<groupHeader>
<band height="310">
<rectangle>
<reportElement x="0" y="14" width="520" height="25" forecolor="#ffdddd" backcolor="#ffdddd"/>
<graphicElement/>
</rectangle>
<staticText>
<reportElement style="Arial_Italic" mode="Opaque" x="0" y="14" width="520" height="11" forecolor="#ff0000" backcolor="#ffdddd"/>
<text><![CDATA[Alle produkt søknader hittil nå :]]></text>
</staticText>
<bar3DChart>
<chart evaluationTime="Group" evaluationGroup="ProductTypeGroup">
<reportElement positionType="Float" x="0" y="25" width="520" height="275"/>
</chart>
<categoryDataset>
<dataset incrementType="Group" incrementGroup="ProductGroup" resetType="Group" resetGroup="ProductTypeGroup"/>
<categorySeries>
<seriesExpression>"Produkt"</seriesExpression>
<categoryExpression>$F{ProductTypeDisplayName}</categoryExpression>
<valueExpression>$V{ProductTypeDisplayNameSumGroup}</valueExpression>
<labelExpression></labelExpression>
</categorySeries>
</categoryDataset>
<bar3DPlot>
<plot foregroundAlpha="0.5"/>
</bar3DPlot>
</bar3DChart>
</band>
</groupHeader>
</group>
<group name="ProductGroup" isReprintHeaderOnEachPage="false">
<groupExpression><![CDATA[$F{ProductTypeDisplayName}]]></groupExpression>
<groupFooter>
<band height="18">
<textField>
<reportElement style="Arial_Bold" mode="Opaque" x="10" y="2" width="100" height="15" backcolor="#c0c0c0"/>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{ProductTypeDisplayName}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="Arial_Bold" mode="Opaque" x="110" y="2" width="400" height="15" backcolor="#c0c0c0"/>
<textElement textAlignment="Right">
<font/>
</textElement>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{ProductTypeDisplayNameSumGroup}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
</jasperReport>
How can I control colour on my chart, I am using bbar3DPlot and I would like to have different colour on each bar. If I use pie3DPlot then it renders with different colour and I am trying to have the same thing with bar3DPlot. I am attaching my .jrxml file. Any help would be greatyly appreciated.
Thanks in advance.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="YaChartReport" language="java" columnCount="2" pageWidth="595" pageHeight="842" columnWidth="270" columnSpacing="15" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30">
<style name="Arial_Normal" isDefault="true" fontName="Arial" fontSize="8" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<style name="Arial_Bold" isDefault="false" fontName="Arial" fontSize="8" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<style name="Arial_Italic" isDefault="false" fontName="Arial" fontSize="8" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Oblique" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<style name="Comic_Normal" isDefault="false" fontName="Comic Sans MS" fontSize="10" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="COMIC.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
<style name="Comic_Bold" isDefault="false" fontName="Comic Sans MS" fontSize="10" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="COMICBD.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
<parameter name="ReportTitle" class="java.lang.String">
</parameter>
<queryString><![CDATA[SELECT ProductTypeDisplayName, count(ProductTypeDisplayName) as numberofproduct FROM yabank.Application a, yabank.ApplicantApplication aa, yabank.Applicant p, yabank.ProductType, yabank.Name WHERE a.ApplicationId = aa.Application_ApplicationId AND p.ApplicantId = aa.Applicant_ApplicantId AND ProductTypeId = a.ProductType_ProductTypeId AND Name_NameId = NameId group by ProductTypeDisplayName]]></queryString>
<field name="ProductTypeDisplayName" class="java.lang.String">
</field>
<field name="numberofproduct" class="java.lang.Integer">
</field>
<variable name="ProductTypeDisplayNameSumGroup" class="java.lang.Integer" resetType="None">
<variableExpression><![CDATA[$F{numberofproduct}]]></variableExpression>
</variable>
<group name="ProductTypeGroup" isStartNewColumn="true" isReprintHeaderOnEachPage="false" minHeightToStartNewPage="200">
<groupHeader>
<band height="310">
<rectangle>
<reportElement x="0" y="14" width="520" height="25" forecolor="#ffdddd" backcolor="#ffdddd"/>
<graphicElement/>
</rectangle>
<staticText>
<reportElement style="Arial_Italic" mode="Opaque" x="0" y="14" width="520" height="11" forecolor="#ff0000" backcolor="#ffdddd"/>
<text><![CDATA[Alle produkt søknader hittil nå :]]></text>
</staticText>
<bar3DChart>
<chart evaluationTime="Group" evaluationGroup="ProductTypeGroup">
<reportElement positionType="Float" x="0" y="25" width="520" height="275"/>
</chart>
<categoryDataset>
<dataset incrementType="Group" incrementGroup="ProductGroup" resetType="Group" resetGroup="ProductTypeGroup"/>
<categorySeries>
<seriesExpression>"Produkt"</seriesExpression>
<categoryExpression>$F{ProductTypeDisplayName}</categoryExpression>
<valueExpression>$V{ProductTypeDisplayNameSumGroup}</valueExpression>
<labelExpression></labelExpression>
</categorySeries>
</categoryDataset>
<bar3DPlot>
<plot foregroundAlpha="0.5"/>
</bar3DPlot>
</bar3DChart>
</band>
</groupHeader>
</group>
<group name="ProductGroup" isReprintHeaderOnEachPage="false">
<groupExpression><![CDATA[$F{ProductTypeDisplayName}]]></groupExpression>
<groupFooter>
<band height="18">
<textField>
<reportElement style="Arial_Bold" mode="Opaque" x="10" y="2" width="100" height="15" backcolor="#c0c0c0"/>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{ProductTypeDisplayName}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="Arial_Bold" mode="Opaque" x="110" y="2" width="400" height="15" backcolor="#c0c0c0"/>
<textElement textAlignment="Right">
<font/>
</textElement>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{ProductTypeDisplayNameSumGroup}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
</jasperReport>
6 Answers:
Posted on August 24, 2006 at 11:03am
Thanks for your suggestion but I have already tried that. The problem is I can't controll colour on each bar, with this customizer the colour is set on whole plot. I got to have differnt colour on each bar. Please help me to solve this problem.
import net.sf.jasperreports.engine.JRChartCustomizer;
import net.sf.jasperreports.engine.JRChart;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.renderer.category.BarRenderer;
import java.awt.*;
public class BarChartCustomizer implements JRChartCustomizer
{
public void customize(JFreeChart chart, JRChart jasperChart)
{
BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
renderer.setSeriesPaint(0, Color.green);
}
}
import net.sf.jasperreports.engine.JRChartCustomizer;
import net.sf.jasperreports.engine.JRChart;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.renderer.category.BarRenderer;
import java.awt.*;
public class BarChartCustomizer implements JRChartCustomizer
{
public void customize(JFreeChart chart, JRChart jasperChart)
{
BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
renderer.setSeriesPaint(0, Color.green);
}
}
Posted on February 6, 2007 at 10:44am
Hi
This is Atanu. I am very new in ireport and also in java environment. In the ireport I have designed a template .like this.
please look on attach file
[img size=150]C:\Documents and Settings\Atanu\My Documents\graph.jpeg[/img]
Now I want to plot a line graph on the basis of the each data like t1 t2 ---t5 and lcl, ucl, actual value for each row.
That I have done. Now my problem is that I have to change the color of points of t1 t2 ---t5 on the basis of Lcl and Ucl . If the value of t1 ,or t2 or ----t5 are between Ucl and Lcl the color will be blue. And if it out side of Lcl and Ucl then it will be red..
I want the following figure. Where the upper bold line is Ucl and lower bold line isLcl
[img size=150]C:\Documents and Settings\Atanu\My Documents\data.jpeg[/img]
Actually I have got a information that for that I have to write a customizer class for chart. Also I have write it .
This is Atanu. I am very new in ireport and also in java environment. In the ireport I have designed a template .like this.
please look on attach file
[img size=150]C:\Documents and Settings\Atanu\My Documents\graph.jpeg[/img]
Now I want to plot a line graph on the basis of the each data like t1 t2 ---t5 and lcl, ucl, actual value for each row.
That I have done. Now my problem is that I have to change the color of points of t1 t2 ---t5 on the basis of Lcl and Ucl . If the value of t1 ,or t2 or ----t5 are between Ucl and Lcl the color will be blue. And if it out side of Lcl and Ucl then it will be red..
I want the following figure. Where the upper bold line is Ucl and lower bold line isLcl
[img size=150]C:\Documents and Settings\Atanu\My Documents\data.jpeg[/img]
Actually I have got a information that for that I have to write a customizer class for chart. Also I have write it .
Code: |
<br /> import net.sf.jasperreports.engine.*;<br /> import net.sf.jasperreports.view.JasperViewer;<br /> import net.sf.jasperreports.engine.JREmptyDataSource;<br /> import java.util.*;<br /> import java.sql.DriverManager;<br /> import java.sql.Connection;<br /> import java.sql.SQLException;<br /> import net.sf.jasperreports.engine.JRAbstractChartCustomizer;<br /> import javax.sql.*;<br /> import org.jfree.chart.axis.CategoryAxis;<br /> import org.jfree.chart.plot.CategoryPlot;<br /> import org.jfree.chart.renderer.category.*;<br /> import org.jfree.chart.renderer.*;<br /> import org.jfree.chart.ChartRenderingInfo;<br /> import org.jfree.chart.renderer.category.BarRenderer;<br /> import org.jfree.chart.renderer.category.LevelRenderer;<br /> import org.jfree.chart.renderer.category.LayeredBarRenderer;<br /> import java.sql.DriverManager;<br /> import java.sql.SQLException;<br /> import java.sql.Connection;<br /> import java.util.HashMap;<br /> import java.util.Map;<br /> import java.lang.String;<br /> import net.sf.jasperreports.engine.JRException;<br /> import net.sf.jasperreports.engine.JasperExportManager;<br /> import net.sf.jasperreports.view.JasperViewer;<br /> import net.sf.jasperreports.engine.xml.JRXmlLoader;<br /> import net.sf.jasperreports.engine.JasperCompileManager;<br /> import net.sf.jasperreports.engine.JasperFillManager;<br /> import net.sf.jasperreports.engine.JasperPrint;<br /> import net.sf.jasperreports.engine.design.JasperDesign;<br /> import net.sf.jasperreports.engine.JasperReport;<br /> import net.sf.jasperreports.engine.JRChartDataset; <br /> import net.sf.jasperreports.engine.JRChartPlot; <br /> import org.jfree.chart.renderer.category.BarRenderer3D; <br /> import org.jfree.chart.renderer.category.LineAndShapeRenderer;<br /> import org.jfree.chart.axis.CategoryLabelPositions;<br /> <br /> <br /> import org.jfree.chart.renderer.category.LineRenderer3D;<br /> import java.awt.*;<br /> import net.sf.jasperreports.engine.JRChart;<br /> import net.sf.jasperreports.engine.JRChartCustomizer;<br /> import org.jfree.chart.JFreeChart;<br /> import net.sf.jasperreports.engine.*;<br /> import java.awt.Color;<br /> import net.sf.jasperreports.engine.JRChart;<br /> import net.sf.jasperreports.engine.JRChartCustomizer;<br /> <br /> import org.jfree.chart.JFreeChart;<br /> import org.jfree.chart.axis.CategoryAxis;<br /> import org.jfree.chart.axis.CategoryLabelPositions;<br /> import org.jfree.chart.plot.CategoryPlot;<br /> import org.jfree.chart.renderer.category.BarRenderer3D;<br /> import java.lang.Object;<br /> <br /> <br /> <br /> public class LineChartCustomizer extends JRAbstractChartCustomizer {<br /> <br /> public void customize(JFreeChart chart, JRChart jasperChart) {<br /> <br /> LineAndShapeRenderer renderer = (LineAndShapeRenderer) chart.getCategoryPlot().getRenderer(); <br /> <br /> <br /> renderer.setSeriesPaint(1, Color.green); <br /> renderer.setSeriesPaint(4, Color.orange); <br /> <br /> chart.setTitle("Setting the title "«»); <br /> } <br /> <br /> <br /> }<br /> </td></tr></tbody></table><br /> Now this customize class ok running successfully with creating jar files.<br /> Now I want to create a logic to check the value of t1 t2 t3 t5 with respect to UCL and LCL. How can I fetch data from report.<br /> Or is there any other way to do this.<br /> Is there any way to pass value from iReport to customizer class ?<br /> <br /> What should I do. Please please help me. It’s urget for me.<br /> <br /> Any help would be greatly appreciated. <br /> Thanks in advance.<br /> [file name=query-37ab101e3a539a71be9c962f72749d92.doc size=49152]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/query-37ab101e3a539a71be9c962f72749d92.doc[/file]<br /> [file name=query-fb85ddd020eca5e8437b37d2b6de10db.doc size=49152]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/query-fb85ddd020eca5e8437b37d2b6de10db.doc[/file] |