Jump to content
We've recently updated our Privacy Statement, available here ×

confused creating multiple XY-line chart


dhruvil.27392

Recommended Posts

Hello,
 
I want to create multiple XY-line in a single chart. so for that,  I have created  a coordinates model class with all getter and setters (xCoordinate,yCoordinate).
 
and as I want to have multiple lines i have created a List<List<Coordinates>> and this I have passed as coordinatedListBean. 
 
List<Coordinates> is a single XY-line
 
I want to create multiple xy-line chart using JRBeanCollectionDataSource and how to configure xy-line chart it in jasper studio
any guidance or reference on how to approach this problem will be appreciated
 
 
here is my code in Java
 
 
 
JRBeanCollectionDataSource coordiantesListBean = new JRBeanCollectionDataSource(listofCoordinatesList);
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream projectInputStream = classloader.getResourceAsStream("jasper/xylineChart.jasper");
 
/* parameters for reports */
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("XYChartDataSource", coordiantesListBean);
 
/* printing reports */
try {
JasperPrint jasperPrint = JasperFillManager.fillReport(projectInputStream, parameters,new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(jasperPrint, "C://test.pdf");
} catch (JRException e) {
e.printStackTrace();
}
 
 
 
 
jrxml file
 
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.0.final using JasperReports Library version 6.3.0  -->
<!-- 2016-07-21T11:11:57 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="demoLineChart" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="638aed34-048c-47f3-8be4-01df214447a7">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<subDataset name="XYDataSet" uuid="958712e6-d970-41e5-9d31-762170924adc">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="xCoordinate" class="java.lang.Double">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="yCoordinate" class="java.lang.Double">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
</subDataset>
<parameter name="XYChartDataSource" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="Field_1" class="java.lang.String"/>
<variable name="Variable_1" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="230" splitType="Stretch"/>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="118" splitType="Stretch">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<xyLineChart>
<chart>
<reportElement x="0" y="0" width="555" height="118" uuid="02fd6fc8-5e72-48fe-b279-831979998a4b">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<xyDataset>
<dataset>
<datasetRun subDataset="XYDataSet" uuid="086ccb57-f8f6-42c8-a940-f7fa59e24793">
<dataSourceExpression><![CDATA[$P{XYChartDataSource}]]></dataSourceExpression>
</datasetRun>
</dataset>
<xySeries autoSort="true">
<seriesExpression><![CDATA["SERIES 1"]]></seriesExpression>
<xValueExpression><![CDATA[$F{xCoordinate}]]></xValueExpression>
<yValueExpression><![CDATA[$F{yCoordinate}]]></yValueExpression>
</xySeries>
</xyDataset>
<linePlot>
<plot/>
<categoryAxisFormat>
<axisFormat/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat/>
</valueAxisFormat>
</linePlot>
</xyLineChart>
</band>
</summary>
</jasperReport>
 

 

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...