pawel_r Posted September 22, 2009 Share Posted September 22, 2009 HiI was looking for a way to put Date on the domain axis of the Bubble chart. I found a suggestion that possibly a chart theme can be a solution here but I am a little lost with example in dist/sample directory -they all seem to only change how chart looks, not what kind of data can be parsed by it.I was trying to do some kind of trick, like putting Date as category, unfortunatelly Bubble chart doesn't have such posibility. The best I got was to simply do $F{SOME_DATE}.getDate()*100+$F{SOME_DATE}.getMonth() but I would like to be able to put it in more readible form (with some separetor between day and month). Is that possible? I am looking for any clue which could potentially be leading to better solution Link to comment Share on other sites More sharing options...
pawel_r Posted September 22, 2009 Author Share Posted September 22, 2009 It seems I found answer for my question - Jfree chart doesn't allow Date to be value for bubble chart axishttp://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/ChartFactory.html#createBubbleChart(java.lang.String,%20java.lang.String,%20java.lang.String,%20org.jfree.data.xy.XYZDataset,%20org.jfree.chart.plot.PlotOrientation,%20boolean,%20boolean,%20boolean)Even though if someone has an idea how to make the Date values as much human readible as possible please share it :) Link to comment Share on other sites More sharing options...
lucianc Posted September 22, 2009 Share Posted September 22, 2009 Use the date timestamp as X value for the chart, and a customizer that formats the values as dates (see below).Regards,LucianCode:package jr;import java.text.DateFormat;import java.text.FieldPosition;import java.text.NumberFormat;import java.text.ParsePosition;import java.util.Date;import net.sf.jasperreports.engine.JRAbstractChartCustomizer;import net.sf.jasperreports.engine.JRChart;import org.jfree.chart.JFreeChart;import org.jfree.chart.axis.NumberAxis;public class BubbleDateCustomizer extends JRAbstractChartCustomizer{ public void customize(JFreeChart chart, JRChart jasperChart) { NumberAxis domainAxis = (NumberAxis) chart.getXYPlot().getDomainAxis(); final DateFormat dateFormat = DateFormat.getDateInstance(); domainAxis.setNumberFormatOverride(new NumberFormat() { public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { return format((long) number, toAppendTo, pos); } public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { return dateFormat.format(new Date(number), toAppendTo, pos); } public Number parse(String source, ParsePosition parsePosition) { throw new UnsupportedOperationException(); } }); }} Link to comment Share on other sites More sharing options...
rm_3 Posted October 20, 2015 Share Posted October 20, 2015 hi lucianc,i tried zour customiyer on my bubble chart. basically it works but i get output i dont understand.the data i get from database looks like this:For domain axis i use the long-value of the timestamp (xaxis).in case i run the report i get only one (wrong) date displayed repatedly on domain-axis:is the dataset causing the problem because values between the timestamps are missing ??maybe you or anybody else can help me with this because i have no clue whats going wrong... Link to comment Share on other sites More sharing options...
rm_3 Posted December 8, 2015 Share Posted December 8, 2015 I found another solution for this:Clue is to create a NEW date axis and after this you can set it as domain axis... 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