Using Birt chart to make a chart, a problem has been encountered:
When the chart has a fixed length and width, it often appears too coarse or too dense for the graph to appear. Serious impact on the presentation of the chart, if you can according to the number of data, dynamically adjust the length of the chart of the width of the size is good.
For example Barnum = 5;
The setting chart.width = 50*barnum;
content:
One: Introduction of the production of charts
Two: Set Chart size Adaptive
One: The production of graphs
As with the normal Birt report making steps, the detailed steps are not much described here, see: Birt Chinese reference manual. CHM
1: New template file chartresizingtest.rptdesign, configuration data source Classicmodels
2: Set up test data set, statistics user ID, user name, order quantity. Pass in two parameters Maxid, MiniD to qualify the user ID range.
Select Classicmodels. CUSTOMERS. CustomerNumber, Classicmodels. CUSTOMERS. CUSTOMERNAME, COUNT (*) Ordernum from Classicmodels. Customers,classicmodels. ORDERS where Classicmodels. CUSTOMERS. CustomerNumber = Classicmodels. ORDERS. CustomerNumber and Classicmodels. CUSTOMERS. CustomerNumber >=? and Classicmodels. CUSTOMERS. CustomerNumber <=? GROUP by Classicmodels. CUSTOMERS. CustomerNumber, Classicmodels. CUSTOMERS. CUSTOMERNAME
3: Insert a statistical table and insert a histogram.
When you are done, the report template looks like the following figure Figure1
But such a chart has an obvious flaw, the chart is fixed, can not adapt to the changes in data volume, resulting in the graph can not be seen. For example you set up a width:300points; height:200points; When the amount of data is very small, the column chart is very thick (ugly), and when the amount of data is large, the column is very dense (not to be seen).
If you can according to the amount of data, dynamically adjust the size of the chart map is very good to solve the above problems. Fortunately, Birt provides the support is still very strong, provide JS, Java interface for dynamic settings. See below for details
Second, the dynamic adjustment chart size
Rewrite the chart OnRender event through JavaScript, dynamically resize the chart size based on the amount of query data.
1://gets the data amount of the chart bound dataset and passes the variable var barcnt;
/** * Called after populating the series DataSet. * * @param series * Series * @param DataSet * @param ICSC * Ichartscriptcontext/function afterdatasetfilled ( Series, DataSet, ICSC) {importpackage (Packages.java.io); Importpackage ( PACKAGES.ORG.ECLIPSE.BIRT.CHART.MODEL.TYPE.IMPL); if (series.getclass () = = Lineseriesimpl) {series.getlineattributes (). setthickness (5);} if (Series.getclass () = Barseriesimpl) {if (series.getseriesidentifier () = = "Mybar") {var list = dataset.getvalues (); barcnt = List.length;}} }
"Mybar" is the name of the chart data area customization
2: Get the value of the variable barcnt, override set chart size
/** * Called before generation of chart model to generatedchartstate. * * @param chart * Chart * @param ICSC * Ichartscriptcontext/function beforegeneration (chart, ICSC) {Chart.getblock ( ). GetBounds (). SetWidth (50*BARCNT); Chart.getblock (). getbounds (). SetHeight (400); }
OK, it's done. According to the size of chart bound dataset data, dynamically set chart width 50*barcnt; Full Birt template See "Birt Chart Dynamic Dimensions"
reference materials:
1:birt Chinese reference Manual. CHM--birt Basic Tutorial http://download.csdn.net/source/3318430
2:birt Chart Dynamic Dimension template source file: http://download.csdn.net/source/3392797
3:birt Chart width Eclipse forum post: http://www.eclipse.org/forums/index.php/m/367583/#msg_367583