charts API help

By: soujiro_as - soujiro_as
charts API help
2005-12-06 10:58
Hi, I try to instantiate a JRBasePiePlot but this needs an interface (JChartPlot) as parameter, later, I instantiate a JFreeChart but I can´t cast this for use in my JasperDesign object.

How can I implements charts with the JasperReports API?.

P.D. Sorry by my poor English.




By: Lucian Chirita - lucianc
RE: charts API help
2005-12-07 01:47
Hi

If you want to create a pie chart via API, you should do
JRDesignChart pieChart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_PIE);
JRDesignPiePlot piePlot = (JRDesignPiePlot) pieChart.getPlot();
piePlot.set...

HTH,
Lucian




By: Bill Babcock - billbabcock
RE: charts API help
2006-02-01 07:55
When I look at the API for the JRDesignChart() method, it doesn't take a JasperDesign obj as a param.

I'm also needing to create charts via the API, and with only the noxml example, and the various java files spread out thru the demos as the only info (yes, I bought the Ultimate guide - but it doesn't talk about the API usage at all), it would be a great help to get a pointer at some working code that showed this start to finish.




By: soujiro_as - soujiro_as
RE: charts API help
2006-03-09 10:50
Yes, I agree with billbabcock, a complete example of a chart implemented through the chart API would be a good help.




By: Bill Babcock - billbabcock
RE: charts API help
2006-02-01 11:04
hrmmm...amazing what upgrading to the current release will do...ok - so the params are ok.

Any examples? :-)




By: soujiro_as - soujiro_as
RE: charts API help
2006-03-21 13:52
Here are my TimeSeries chart example:

private JRDesignChart createTimeSeriesReport(JasperDesign jasperDesign){
String dateIntType=ReportGeneratorConstants.FIELD_TYPE_DATEINT;
String dateExpression="String.valueOf(new com.jatun.titus.reportgenerator.reportfieldformatter.Formatter().format(String.valueOf($F{dateStart}),\""+dateIntType+"\",\"dd/MM/yy\",\"en\", TimeZone.getDefault().getID()))";
JRDesignChart timeSeriesChart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_TIMESERIES);

JRDesignTimeSeriesDataset timeSeriesDataset= (JRDesignTimeSeriesDataset) timeSeriesChart.getDataset();
timeSeriesDataset.setTimePeriod(Year.class);

timeSeriesDataset.setIncrementType(JRVariable.RESET_TYPE_GROUP);
timeSeriesDataset.setIncrementGroup((JRGroup)jasperDesign.getGroupsMap().get("contactTypeGroup"));

JRDesignTimeSeries timeSeries=new JRDesignTimeSeries();
JRDesignExpression seriesExpression=new JRDesignExpression();
seriesExpression.setValueClassName("java.lang.String");
seriesExpression.setText("new String(\"contactType\")");
timeSeries.setSeriesExpression(seriesExpression);

JRDesignExpression timePeriodExpression=new JRDesignExpression();
timePeriodExpression.setValueClassName("java.util.Date");
timePeriodExpression.setText("new java.util.Date("+dateExpression+")");
timeSeries.setTimePeriodExpression(timePeriodExpression);

JRDesignExpression valueExpression=new JRDesignExpression();
valueExpression.setValueClassName("java.lang.Integer");
valueExpression.setText("$V{contactTypeGroup_COUNT}");
timeSeries.setValueExpression(valueExpression);

timeSeriesDataset.addTimeSeries(timeSeries);

timeSeriesChart.setDataset(timeSeriesDataset);
return(timeSeriesChart);
}

This code get's a Exception, because the "timeSeriesChart.getDataset()" returns null, then I give a look to the source code and found something interesting in the JRDesignChart class:
........
case CHART_TYPE_TIMESERIES:
//FIXME CHARTS why only one dataset?
//dataset = new JRDesignTimeSeriesDataset( dataset );
plot = new JRDesignTimeSeriesPlot( plot );
break;
......
case CHART_TYPE_XYBAR:
plot = new JRDesignBarPlot(plot);
break;

In the first case sentence, the creation of the dataset was commented, and in the second, the creation of the dataset don´t exists. I'm usign JasperReports 1.1.0. To fix this, I uncommented the line in the first case sentence, and in the second, I put the line "dataset = new JRDesignXyDataset(dataset);", this is o.k.? or I'm wrong. I generate the jar using ant, and the TimeSeries chart was finally generated.




By: soujiro_as - soujiro_as
RE: charts API help
2006-03-21 12:18
I have implemented an example of a some charts, i.e. for a pie chart:

private JRDesignChart createPieChart(JasperDesign jasperDesign){
JRDesignChart designChart=new JRDesignChart(jasperDesign,JRChart.CHART_TYPE_PIE);

JRDesignPieDataset pieDataset=(JRDesignPieDataset) designChart.getDataset();
pieDataset.setIncrementType(JRVariable.RESET_TYPE_GROUP);
pieDataset.setIncrementGroup((JRGroup)jasperDesign.getGroupsMap().get("contactTypeGroup"));
JRDesignExpression keyExpression=new JRDesignExpression();
keyExpression.setValueClassName("java.lang.Integer");
keyExpression.setText("$F{contactType}");
pieDataset.setKeyExpression(keyExpression);

JRDesignExpression valueExpression=new JRDesignExpression();
valueExpression.setValueClassName("java.lang.Integer");
valueExpression.setText("$V{contactTypeGroup_COUNT}");
pieDataset.setValueExpression(valueExpression);
designChart.setDataset(pieDataset);
return(designChart);
}

This work similarly for tyhe other types of charts, only the dataset changes, but for a XYBar or a TimeSeries chart, the "designChart.getDataset()" function returns null.

How I have to get the dataset for a XYBar and a TimeSeries chart?




By: jokrasa - jokrasa
RE: charts API help
2006-06-16 08:13
Trying to figure out how to use this code(below):

The question is how do I pass/feed the actual HashMap (or values) into the dataset.

Can't find this anywhere!

Where does the return value (designChart) go?

private JRDesignChart createPieChart(JasperDesign jasperDesign){
JRDesignChart designChart=new JRDesignChart(jasperDesign,JRChart.CHART_TYPE_PIE);

JRDesignPieDataset pieDataset=(JRDesignPieDataset) designChart.getDataset();
pieDataset.setIncrementType(JRVariable.RESET_TYPE_GROUP);
pieDataset.setIncrementGroup((JRGroup)jasperDesign.getGroupsMap().get("contactTypeGroup"));
JRDesignExpression keyExpression=new JRDesignExpression();
keyExpression.setValueClassName("java.lang.Integer");
keyExpression.setText("$F{contactType}");
pieDataset.setKeyExpression(keyExpression);

JRDesignExpression valueExpression=new JRDesignExpression();
valueExpression.setValueClassName("java.lang.Integer");
valueExpression.setText("$V{contactTypeGroup_COUNT}");
pieDataset.setValueExpression(valueExpression);
designChart.setDataset(pieDataset);
return(designChart);
}

any help greatly appreciated!
2004 IR Help's picture
Joined: Aug 17 2006 - 3:49am
Last seen: 17 years 1 month ago

4 Answers:


Hi Folks,

 

I also need help in creating noxmldesign for creating Stacked bar 3d chart.

I had problem in setting dataset in code.

 

Can any one post the complete code for creating Stacked bar 3d chart.

 

Thanks in advance.

 

babuprasad02's picture
Joined: Jul 21 2010 - 11:47pm
Last seen: 7 years 4 months ago

Jasper community edition used the JFreeChart as the charting package. Try checking out the JFreeChart forums

http://www.jfree.org/phpBB2/index.php

svenn's picture
15212
Joined: Mar 19 2007 - 5:57am
Last seen: 16 years 6 months ago

Hi,

For additional guidance, JR provides an API writer tool which is called by running the

>ant clean writeApi

command when running a sample. So, go to the demo/samples/charts directory and run the 'ant clean writeApi' command. In the build/reports directory you'll find one .java file per each jrxml. Take a look into the StackedBar3DChartReport.java to see how related objects are created on the fly.

Hope this helps,

sanda

shertage's picture
22370
Joined: Sep 26 2006 - 8:06pm
Last seen: 2 months 3 weeks ago

shertage
Wrote:

Hi,

For additional guidance, JR provides an API writer tool which is called by running the

>ant clean writeApi

command when running a sample. So, go to the demo/samples/charts directory and run the 'ant clean writeApi' command. In the build/reports directory you'll find one .java file per each jrxml. Take a look into the StackedBar3DChartReport.java to see how related objects are created on the fly.

Hope this helps,

sanda

I had converted all my jrxml to java files and want to know what are the jar files needed to use in my application.

sample code needed.

 

regards,

babs

 

babuprasad02's picture
Joined: Jul 21 2010 - 11:47pm
Last seen: 7 years 4 months ago
Feedback