I have added DB query, with that I am able to view data in details view.
But not able to plot scatter chart. There is one column for X axis and one column for Y axis and one for label name. How to plot this using iReport?
I have added scatter chart palette but not getting any documentation of how to set columns for X and Y axis to plot all points. I am getting only one point in scatter chart.
Your first problem is to pass a datasource to the chart, if you are using main datasource, you need to put the chart in the summary
band, since your datasource is not ready in title
band and is iterating on detail
band, hence it will not work correctly (note: if you use your datasource also in detail band it need to be a JRRewindableDataSource).
If you need to use it in other bands then summary
band I suggest you make a subreport and included this in desired band passing chart datasource or the connection to the subreport.
The scatter plot is achieved using a <scatterChart>
and the <xyDataset>
, to set series and x,y data you use the <xySeries>
tag
In iReport, Right click chart, select Chart Data, select tab Details and add XY series
<xySeries>
<seriesExpression><![CDATA[$F{Series}]]></seriesExpression>
<xValueExpression><![CDATA[$F{X}]]></xValueExpression>
<yValueExpression><![CDATA[$F{Y}]]></yValueExpression>
</xySeries>
If you have only 1 series you can pass a dummy variable in seriesExpression
<seriesExpression><![CDATA["dummy"]]></seriesExpression>
Full jrxml example
<?xml version="1.0" encoding="UTF-8"?>
<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="ScatterPlot" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ebc92eb9-c769-4888-98de-b1d60670725c">
<queryString>
<![CDATA[]]>
</queryString>
<field name="Series" class="java.lang.String"/>
<field name="X" class="java.lang.Double"/>
<field name="Y" class="java.lang.Double"/>
<columnHeader>
<band height="20">
<staticText>
<reportElement x="100" y="0" width="100" height="20" uuid="978a0093-4e67-40e3-baee-8340ccc23b8f"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[X]]></text>
</staticText>
<staticText>
<reportElement x="0" y="0" width="100" height="20" uuid="b97c9f78-ad74-4d9f-af46-ee3fc3e5351f"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[Series]]></text>
</staticText>
<staticText>
<reportElement x="200" y="0" width="100" height="20" uuid="e50dab9b-c8f7-4cc0-a8f7-3ca4438c746b"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[Y]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20">
<textField pattern="###0.00">
<reportElement x="100" y="0" width="100" height="20" uuid="8d365885-a6f8-40be-8ad0-012e45a37543"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{X}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="f08b3a38-8130-4609-b70d-b10b9d8d648b"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{Series}]]></textFieldExpression>
</textField>
<textField pattern="###0.00">
<reportElement x="200" y="0" width="100" height="20" uuid="83638866-5bd1-4ee4-ac1a-455c406f3621"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{Y}]]></textFieldExpression>
</textField>
</band>
</detail>
<summary>
<band height="257" splitType="Stretch">
<scatterChart>
<chart>
<reportElement x="4" y="16" width="280" height="237" uuid="b9968e83-13aa-48fc-acf5-3d646f45f28d"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<xyDataset>
<xySeries>
<seriesExpression><![CDATA[$F{Series}]]></seriesExpression>
<xValueExpression><![CDATA[$F{X}]]></xValueExpression>
<yValueExpression><![CDATA[$F{Y}]]></yValueExpression>
</xySeries>
</xyDataset>
<scatterPlot isShowLines="false" isShowShapes="true">
<plot/>
<xAxisFormat>
<axisFormat/>
</xAxisFormat>
<yAxisFormat>
<axisFormat/>
</yAxisFormat>
</scatterPlot>
</scatterChart>
</band>
</summary>
</jasperReport>
csv data example
+--------+-----+-----+
| Series | X | Y |
+--------+-----+-----+
| A | 1.2 | 0.3 |
| A | 0.5 | 0.2 |
| B | 0.7 | 0.6 |
| B | 0.1 | 0.5 |
+--------+-----+-----+
Result
To configure your chart use the properties settings on chart, if you need special configuration that you can not achieve with the properties you can implement a ChartCustomizer
see this for example