When the chart is set to a fixed length-width size, the graph often appears too coarse or too dense to present. Seriously affect the rendering of the chart, if it can be based on the number of data, the dynamic adjustment of the chart's long-width size is good.
The chart's length and width are fixed and cannot accommodate changes in the amount of data, resulting in graphs that cannot be viewed. For example you set up a width:300points; height:200points; When the amount of data is very small, the bar chart is very coarse (unsightly); When the amount of data is large, the histogram is very dense (cannot be seen). If it can be based on the amount of data, dynamically adjust the size of the chart chart is a good solution to the above problem. Fortunately, the support provided by Birt is still very powerful, providing JS, Java interface for dynamic setting
Rewrite the chart OnRender event via JavaScript and dynamically adjust the chart size based on the amount of data queried.
1 //gets the data amount of the chart bound dataset, passing in the variable var barcnt;2 3 /** 4 5 * Called after populating the series DataSet.6 7 * 8 9 * @param seriesTen One * Series A - * @param dataSet - the * DataSet - - * @param ICSC - + * Ichartscriptcontext - + */ A at - - functionafterdatasetfilled (series, DataSet, ICSC) - - { - in importpackage (Packages.java.io); - to importpackage (Packages.org.eclipse.birt.chart.model.type.impl); + - the * if(Series.getclass () = =Lineseriesimpl) { $ Panax NotoginsengSeries.getlineattributes (). setthickness (5); - the } + A if(Series.getclass () = =Barseriesimpl) { the + if(Series.getseriesidentifier () = = "MyY" ){ - $ varList =dataset.getvalues (); $ -barcnt =list.length; - the } - Wuyi } the - } Wu - //"Mybar" is a custom name for the chart data area
2: Get the value of variable barcnt, override set chart size
called before generation of the chart model to Generatedchartstate . * * @param chart * Chart * @param ICSC * Ichartscriptcontext * /function beforegeneration (chart, ICSC) { Chart.getblock (). getbounds (). SetWidth (50*barcnt); Chart.getblock (). getbounds (). SetHeight(+); }
Legend:
Birt's Chart adaptive width