nehachd38 Posted September 26, 2018 Share Posted September 26, 2018 Hi, I am new to Jasper and creating X-Y chart . On x-axis I want to dispay month name but currently numbers 4.0, 4.5 , 5.0 like this are coming.I am using below sql query :select `description - output`.Keywords,month(details.Date),count(distinct `description - output`.`Incident ID`)fromidg_dataquality_db.`description - output`,idg_dataquality_db.detailswhere`description - output`.`Incident ID` = details.`Incident ID`group by `description - output`.Keywords, month(details.Date)If I use monthname in query the Jasper studio is giving error : java.lang.String cannot be cast to java.lang.Number Below is my whole source code: <?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.3.0.final using JasperReports Library version 6.3.0 --><!-- 2018-09-26T12:55:12 --><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="Keyword trend over a period of Time" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="108161ea-b60a-409a-b1fd-615f83762f54"> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="DQ Dashboards"/> <property name="com.jaspersoft.studio.data.sql.tables" value=""/> <queryString> <![CDATA[select `description - output`.Keywords,month(details.Date),count(distinct `description - output`.`Incident ID`)fromidg_dataquality_db.`description - output`,idg_dataquality_db.detailswhere`description - output`.`Incident ID` = details.`Incident ID`group by `description - output`.Keywords, month(details.Date)]]> </queryString> <field name="Keywords" class="java.lang.String"/> <field name="month(details.Date)" class="java.lang.Integer"/> <field name="count(distinct `description - output`.`Incident ID`)" class="java.lang.Long"/> <background> <band splitType="Stretch"/> </background> <title> <band height="46" splitType="Stretch"> <staticText> <reportElement x="0" y="0" width="560" height="30" uuid="a7a3a2f6-309f-48e4-bcb7-a797e01a9e78"/> <textElement textAlignment="Center"> <font size="18" isBold="true"/> </textElement> <text><![CDATA[Keyword Trend over a period of Time]]></text> </staticText> </band> </title> <summary> <band height="250" splitType="Stretch"> <property name="com.jaspersoft.studio.unit.height" value="pixel"/> <xyLineChart> <chart evaluationTime="Report"> <reportElement x="0" y="0" width="560" height="250" uuid="42d9a7f3-ede2-4eaf-b4fd-4544070f526c"/> <chartTitle/> <chartSubtitle/> <chartLegend/> </chart> <xyDataset> <xySeries autoSort="true"> <seriesExpression><![CDATA[$F{Keywords}]]></seriesExpression> <xValueExpression><![CDATA[$F{month(details.Date)}]]></xValueExpression> <yValueExpression><![CDATA[$F{count(distinct `description - output`.`Incident ID`)}]]></yValueExpression> </xySeries> </xyDataset> <linePlot> <plot/> <categoryAxisFormat> <axisFormat/> </categoryAxisFormat> <valueAxisFormat> <axisFormat/> </valueAxisFormat> </linePlot> </xyLineChart> </band> </summary></jasperReport> Please help me to write a expression to type cast and dislay month name instead of numbers. Link to comment Share on other sites More sharing options...
reportdev Posted September 26, 2018 Share Posted September 26, 2018 You are using xyLineChart. xyLineChart tries to increment the X and Y axes. so it wont be possible for you to provide a String for incrementer.Try using lineChart instead and it should work Link to comment Share on other sites More sharing options...
nehachd38 Posted September 27, 2018 Author Share Posted September 27, 2018 Thanks line chart worked. but Month names are displaying alphabetically. I need in order April May June July August. But its coming like April August July June. Any idea how to solve Link to comment Share on other sites More sharing options...
reportdev Posted September 27, 2018 Share Posted September 27, 2018 try sorting your data either using Sort Fields or Order by in the SQL itself. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now