Birt's Chart adaptive width

Source: Internet
Author: User
Tags custom name

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.