锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品国产精品亚洲人人,亚洲精品无码久久久,337P日本欧洲亚洲大胆精品http://www.tkk7.com/matthew2006/archive/2006/08/14/63475.htmlmatthewmatthewMon, 14 Aug 2006 06:39:00 GMThttp://www.tkk7.com/matthew2006/archive/2006/08/14/63475.htmlhttp://www.tkk7.com/matthew2006/comments/63475.htmlhttp://www.tkk7.com/matthew2006/archive/2006/08/14/63475.html#Feedback0http://www.tkk7.com/matthew2006/comments/commentRss/63475.htmlhttp://www.tkk7.com/matthew2006/services/trackbacks/63475.htmlJFreeChart綾伙細
void setAntiAlias(boolean flag) 瀛椾綋妯$硦杈圭晫
void setBackgroundImage(Image image) 鑳屾櫙鍥劇墖
void setBackgroundImageAlignment(int alignment) 鑳屾櫙鍥劇墖瀵歸綈鏂瑰紡錛堝弬鏁板父閲忓湪org.jfree.ui.Align綾諱腑瀹氫箟錛?br />void setBackgroundImageAlpha(float alpha) 鑳屾櫙鍥劇墖閫忔槑搴︼紙0.0锝?.0錛?br />void setBackgroundPaint(Paint paint) 鑳屾櫙鑹?br />void setBorderPaint(Paint paint) 杈圭晫綰挎潯棰滆壊
void setBorderStroke(Stroke stroke) 杈圭晫綰挎潯絎旇Е
void setBorderVisible(boolean visible) 杈圭晫綰挎潯鏄惁鍙



鈥斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺?br />

TextTitle綾伙細
void setFont(Font font) 鏍囬瀛椾綋
void setPaint(Paint paint) 鏍囬瀛椾綋棰滆壊
void setText(String text) 鏍囬鍐呭

鈥斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺?br />

StandardLegend(Legend)綾伙細
void setBackgroundPaint(Paint paint) 鍥劇ず鑳屾櫙鑹?br />void setTitle(String title) 鍥劇ず鏍囬鍐呭
void setTitleFont(Font font) 鍥劇ず鏍囬瀛椾綋
void setBoundingBoxArcWidth(int arcWidth) 鍥劇ず杈圭晫鍦嗚瀹?br />void setBoundingBoxArcHeight(int arcHeight) 鍥劇ず杈圭晫鍦嗚楂?br />void setOutlinePaint(Paint paint) 鍥劇ず杈圭晫綰挎潯棰滆壊
void setOutlineStroke(Stroke stroke) 鍥劇ず杈圭晫綰挎潯絎旇Е
void setDisplaySeriesLines(boolean flag) 鍥劇ず欏規槸鍚︽樉紺烘í綰匡紙鎶樼嚎鍥炬湁鏁堬級
void setDisplaySeriesShapes(boolean flag) 鍥劇ず欏規槸鍚︽樉紺哄艦鐘訛紙鎶樼嚎鍥炬湁鏁堬級
void setItemFont(Font font) 鍥劇ず欏瑰瓧浣?br />void setItemPaint(Paint paint) 鍥劇ず欏瑰瓧浣撻鑹?br />void setAnchor(int anchor) 鍥劇ず鍦ㄥ浘琛ㄤ腑鐨勬樉紺轟綅緗紙鍙傛暟甯擱噺鍦↙egend綾諱腑瀹氫箟錛?br />

鈥斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺?br />

Axis綾伙細
void setVisible(boolean flag) 鍧愭爣杞存槸鍚﹀彲瑙?br />void setAxisLinePaint(Paint paint) 鍧愭爣杞寸嚎鏉¢鑹詫紙3D杞存棤鏁堬級
void setAxisLineStroke(Stroke stroke) 鍧愭爣杞寸嚎鏉$瑪瑙︼紙3D杞存棤鏁堬級
void setAxisLineVisible(boolean visible) 鍧愭爣杞寸嚎鏉℃槸鍚﹀彲瑙侊紙3D杞存棤鏁堬級
void setFixedDimension(double dimension) 錛堢敤浜庡鍚堣〃涓澶氬潗鏍囪醬鐨勮緗級
void setLabel(String label) 鍧愭爣杞存爣棰?br />void setLabelFont(Font font) 鍧愭爣杞存爣棰樺瓧浣?br />void setLabelPaint(Paint paint) 鍧愭爣杞存爣棰橀鑹?br />void setLabelAngle(double angle)` 鍧愭爣杞存爣棰樻棆杞搴︼紙綰靛潗鏍囧彲浠ユ棆杞級
void setTickLabelFont(Font font) 鍧愭爣杞存爣灝哄煎瓧浣?br />void setTickLabelPaint(Paint paint) 鍧愭爣杞存爣灝哄奸鑹?br />void setTickLabelsVisible(boolean flag) 鍧愭爣杞存爣灝哄兼槸鍚︽樉紺?br />void setTickMarkPaint(Paint paint) 鍧愭爣杞存爣灝洪鑹?br />void setTickMarkStroke(Stroke stroke) 鍧愭爣杞存爣灝虹瑪瑙?br />void setTickMarksVisible(boolean flag) 鍧愭爣杞存爣灝烘槸鍚︽樉紺?br />

ValueAxis(Axis)綾伙細
void setAutoRange(boolean auto) 鑷姩璁劇疆鏁版嵁杞存暟鎹寖鍥?br />void setAutoRangeMinimumSize(double size) 鑷姩璁劇疆鏁版嵁杞存暟鎹寖鍥存椂鏁版嵁鑼冨洿鐨勬渶灝忚法搴?br />void setAutoTickUnitSelection(boolean flag) 鏁版嵁杞寸殑鏁版嵁鏍囩鏄惁鑷姩紜畾錛堥粯璁や負true錛?br />void setFixedAutoRange(double length) 鏁版嵁杞村浐瀹氭暟鎹寖鍥達紙璁劇疆100鐨勮瘽灝辨槸鏄劇ずMAXVALUE鍒癕AXVALUE-100閭f鏁版嵁鑼冨洿錛?br />void setInverted(boolean flag) 鏁版嵁杞存槸鍚﹀弽鍚戯紙榛樿涓篺alse錛?br />void setLowerMargin(double margin) 鏁版嵁杞翠笅錛堝乏錛夎竟璺?br />void setUpperMargin(double margin) 鏁版嵁杞翠笂錛堝彸錛夎竟璺?br />void setLowerBound(double min) 鏁版嵁杞翠笂鐨勬樉紺烘渶灝忓?br />void setUpperBound(double max) 鏁版嵁杞翠笂鐨勬樉紺烘渶澶у?br />void setPositiveArrowVisible(boolean visible) 鏄惁鏄劇ず姝e悜綆ご錛?D杞存棤鏁堬級
void setNegativeArrowVisible(boolean visible) 鏄惁鏄劇ず鍙嶅悜綆ご錛?D杞存棤鏁堬級
void setVerticalTickLabels(boolean flag) 鏁版嵁杞存暟鎹爣絳炬槸鍚︽棆杞埌鍨傜洿
void setStandardTickUnits(TickUnitSource source) 鏁版嵁杞寸殑鏁版嵁鏍囩錛堝彲浠ュ彧鏄劇ず鏁存暟鏍囩錛岄渶瑕佸皢AutoTickUnitSelection璁緁alse錛?br />

NumberAxis(ValueAxis)綾伙細
void setAutoRangeIncludesZero(boolean flag) 鏄惁寮哄埗鍦ㄨ嚜鍔ㄩ夋嫨鐨勬暟鎹寖鍥翠腑鍖呭惈0
void setAutoRangeStickyZero(boolean flag) 鏄惁寮哄埗鍦ㄦ暣涓暟鎹醬涓寘鍚?錛屽嵆浣?涓嶅湪鏁版嵁鑼冨洿涓?br />void setNumberFormatOverride(NumberFormat formatter) 鏁版嵁杞存暟鎹爣絳劇殑鏄劇ず鏍煎紡
void setTickUnit(NumberTickUnit unit) 鏁版嵁杞寸殑鏁版嵁鏍囩錛堥渶瑕佸皢AutoTickUnitSelection璁緁alse錛?br />

DateAxis(ValueAxis)綾伙細
void setMaximumDate(Date maximumDate) 鏃ユ湡杞翠笂鐨勬渶灝忔棩鏈?br />void setMinimumDate(Date minimumDate) 鏃ユ湡杞翠笂鐨勬渶澶ф棩鏈?br />void setRange(Date lower,Date upper) 鏃ユ湡杞磋寖鍥?br />void setDateFormatOverride(DateFormat formatter) 鏃ユ湡杞存棩鏈熸爣絳劇殑鏄劇ず鏍煎紡
void setTickUnit(DateTickUnit unit) 鏃ユ湡杞寸殑鏃ユ湡鏍囩錛堥渶瑕佸皢AutoTickUnitSelection璁緁alse錛?br />void setTickMarkPosition(DateTickMarkPosition position) 鏃ユ湡鏍囩浣嶇疆錛堝弬鏁板父閲忓湪org.jfree.chart.axis.DateTickMarkPosition綾諱腑瀹氫箟錛?br />

CategoryAxis(Axis)綾伙細
void setCategoryMargin(double margin) 鍒嗙被杞磋竟璺?br />void setLowerMargin(double margin) 鍒嗙被杞翠笅錛堝乏錛夎竟璺?br />void setUpperMargin(double margin) 鍒嗙被杞翠笂錛堝彸錛夎竟璺?br />void setVerticalCategoryLabels(boolean flag) 鍒嗙被杞存爣棰樻槸鍚︽棆杞埌鍨傜洿
void setMaxCategoryLabelWidthRatio(float ratio) 鍒嗙被杞村垎綾繪爣絳劇殑鏈澶у搴?br />

鈥斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺?br />

Plot綾伙細
void setBackgroundImage(Image image) 鏁版嵁鍖虹殑鑳屾櫙鍥劇墖
void setBackgroundImageAlignment(int alignment) 鏁版嵁鍖虹殑鑳屾櫙鍥劇墖瀵歸綈鏂瑰紡錛堝弬鏁板父閲忓湪org.jfree.ui.Align綾諱腑瀹氫箟錛?br />void setBackgroundPaint(Paint paint) 鏁版嵁鍖虹殑鑳屾櫙鍥劇墖鑳屾櫙鑹?br />void setBackgroundAlpha(float alpha) 鏁版嵁鍖虹殑鑳屾櫙閫忔槑搴︼紙0.0锝?.0錛?br />void setForegroundAlpha(float alpha) 鏁版嵁鍖虹殑鍓嶆櫙閫忔槑搴︼紙0.0锝?.0錛?br />void setDataAreaRatio(double ratio) 鏁版嵁鍖哄崰鏁翠釜鍥捐〃鍖虹殑鐧懼垎姣?br />void setOutLinePaint(Paint paint) 鏁版嵁鍖虹殑杈圭晫綰挎潯棰滆壊
void setOutLineStroke(Stroke stroke) 鏁版嵁鍖虹殑杈圭晫綰挎潯絎旇Е
void setNoDataMessage(String message) 娌℃湁鏁版嵁鏃舵樉紺虹殑娑堟伅
void setNoDataMessageFont(Font font) 娌℃湁鏁版嵁鏃舵樉紺虹殑娑堟伅瀛椾綋
void setNoDataMessagePaint(Paint paint) 娌℃湁鏁版嵁鏃舵樉紺虹殑娑堟伅棰滆壊

CategoryPlot(Plot)綾伙細
void setDataset(CategoryDataset dataset) 鏁版嵁鍖虹殑2緇存暟鎹〃
void setColumnRenderingOrder(SortOrder order) 鏁版嵁鍒嗙被鐨勬帓搴忔柟寮?br />void setAxisOffset(Spacer offset) 鍧愭爣杞村埌鏁版嵁鍖虹殑闂磋窛
void setOrientation(PlotOrientation orientation) 鏁版嵁鍖虹殑鏂瑰悜錛圥lotOrientation.HORIZONTAL鎴朠lotOrientation.VERTICAL錛?br />void setDomainAxis(CategoryAxis axis) 鏁版嵁鍖虹殑鍒嗙被杞?br />void setDomainAxisLocation(AxisLocation location) 鍒嗙被杞寸殑浣嶇疆錛堝弬鏁板父閲忓湪org.jfree.chart.axis.AxisLocation綾諱腑瀹氫箟錛?br />void setDomainGridlinesVisible(boolean visible) 鍒嗙被杞寸綉鏍兼槸鍚﹀彲瑙?br />void setDomainGridlinePaint(Paint paint) 鍒嗙被杞寸綉鏍肩嚎鏉¢鑹?br />void setDomainGridlineStroke(Stroke stroke) 鍒嗙被杞寸綉鏍肩嚎鏉$瑪瑙?br />void setRangeAxis(ValueAxis axis) 鏁版嵁鍖虹殑鏁版嵁杞?br />void setRangeAxisLocation(AxisLocation location) 鏁版嵁杞寸殑浣嶇疆錛堝弬鏁板父閲忓湪org.jfree.chart.axis.AxisLocation綾諱腑瀹氫箟錛?br />void setRangeGridlinesVisible(boolean visible) 鏁版嵁杞寸綉鏍兼槸鍚﹀彲瑙?br />void setRangeGridlinePaint(Paint paint) 鏁版嵁杞寸綉鏍肩嚎鏉¢鑹?br />void setRangeGridlineStroke(Stroke stroke) 鏁版嵁杞寸綉鏍肩嚎鏉$瑪瑙?br />void setRenderer(CategoryItemRenderer renderer) 鏁版嵁鍖虹殑琛ㄧず鑰咃紙璇﹁Renderer緇勶級
void addAnnotation(CategoryAnnotation annotation) 緇欐暟鎹尯鍔犱竴涓敞閲?br />void addRangeMarker(Marker marker,Layer layer) 緇欐暟鎹尯鍔犱竴涓暟鍊艱寖鍥村尯鍩?br />

PiePlot(Plot)綾伙細
void setDataset(PieDataset dataset) 鏁版嵁鍖虹殑1緇存暟鎹〃
void setIgnoreNullValues(boolean flag) 蹇界暐鏃犲肩殑鍒嗙被
void setCircular(boolean flag) 楗煎浘鏄惁涓瀹氭槸姝e渾
void setStartAngle(double angle) 楗煎浘鐨勫垵濮嬭搴?br />void setDirection(Rotation direction) 楗煎浘鐨勬棆杞柟鍚?br />void setExplodePercent(int section,double percent) 鎶藉彇鐨勯偅鍧楋紙1緇存暟鎹〃鐨勫垎綾諱笅鏍囷級浠ュ強鎶藉彇鍑烘潵鐨勮窛紱伙紙0.0锝?.0錛夛紝3D楗煎浘鏃犳晥
void setLabelBackgroundPaint(Paint paint) 鍒嗙被鏍囩鐨勫簳鑹?br />void setLabelFont(Font font) 鍒嗙被鏍囩鐨勫瓧浣?br />void setLabelPaint(Paint paint) 鍒嗙被鏍囩鐨勫瓧浣撻鑹?br />void setLabelLinkMargin(double margin) 鍒嗙被鏍囩涓庡浘鐨勮繛鎺ョ嚎杈硅窛
void setLabelLinkPaint(Paint paint) 鍒嗙被鏍囩涓庡浘鐨勮繛鎺ョ嚎棰滆壊
void setLabelLinkStroke(Stroke stroke) 鍒嗙被鏍囩涓庡浘鐨勮繛鎺ョ嚎絎旇Е
void setLabelOutlinePaint(Paint paint) 鍒嗙被鏍囩杈規棰滆壊
void setLabelOutlineStroke(Paint paint) 鍒嗙被鏍囩杈規絎旇Е
void setLabelShadowPaint(Paint paint) 鍒嗙被鏍囩闃村獎棰滆壊
void setMaximumLabelWidth(double width) 鍒嗙被鏍囩鐨勬渶澶ч暱搴︼紙0.0锝?.0錛?br />void setPieIndex(int index) 楗煎浘鐨勭儲寮曪紙澶嶅悎楗煎浘涓敤鍒幫級
void setSectionOutlinePaint(int section,Paint paint) 鎸囧畾鍒嗙被楗肩殑杈規棰滆壊
void setSectionOutlineStroke(int section,Stroke stroke) 鎸囧畾鍒嗙被楗肩殑杈規絎旇Е
void setSectionPaint(int section,Paint paint) 鎸囧畾鍒嗙被楗肩殑棰滆壊
void setShadowPaint(Paint paint) 楗煎浘鐨勯槾褰遍鑹?br />void setShadowXOffset(double offset) 楗煎浘鐨勯槾褰辯浉瀵瑰浘鐨勬按騫沖亸縐?br />void setShadowYOffset(double offset) 楗煎浘鐨勯槾褰辯浉瀵瑰浘鐨勫瀭鐩村亸縐?br />void setLabelGenerator(PieSectionLabelGenerator generator) 鍒嗙被鏍囩鐨勬牸寮忥紝璁劇疆鎴恘ull鍒欐暣涓爣絳懼寘鎷繛鎺ョ嚎閮戒笉鏄劇ず
void setToolTipGenerator(PieToolTipGenerator generator) MAP涓紶鏍囩Щ涓婄殑鏄劇ず鏍煎紡
void setURLGenerator(PieURLGenerator generator) MAP涓捇鍙栭摼鎺ユ牸寮?br />

PiePlot3D(PiePlot)綾伙細
void setDepthFactor(double factor) 3D楗煎浘鐨刏杞撮珮搴︼紙0.0锝?.0錛?br />

MultiplePiePlot(Plot)綾伙細
void setLimit(double limit) 姣忎釜楗煎浘涔嬮棿鐨勬暟鎹叧鑱旓紙璇︾粏姣旇緝澶嶆潅錛?br />void setPieChart(JFreeChart pieChart) 姣忎釜楗煎浘鐨勬樉紺烘柟寮忥紙瑙丣FreeChart綾諱釜PiePlot綾伙級

鈥斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺?br />

AbstractRenderer綾伙細
void setItemLabelAnchorOffset(double offset) 鏁版嵁鏍囩鐨勪笌鏁版嵁鐐圭殑鍋忕Щ
void setItemLabelsVisible(boolean visible) 鏁版嵁鏍囩鏄惁鍙
void setItemLabelFont(Font font) 鏁版嵁鏍囩鐨勫瓧浣?br />void setItemLabelPaint(Paint paint) 鏁版嵁鏍囩鐨勫瓧浣撻鑹?br />void setItemLabelPosition(ItemLabelPosition position) 鏁版嵁鏍囩浣嶇疆
void setPositiveItemLabelPosition(ItemLabelPosition position) 姝f暟鏍囩浣嶇疆
void setNegativeItemLabelPosition(ItemLabelPosition position) 璐熸暟鏍囩浣嶇疆
void setOutLinePaint(Paint paint) 鍥懼艦杈規鐨勭嚎鏉¢鑹?br />void setOutLineStroke(Stroke stroke) 鍥懼艦杈規鐨勭嚎鏉$瑪瑙?br />void setPaint(Paint paint) 鎵鏈夊垎綾誨浘褰㈢殑棰滆壊
void setShape(Shape shape) 鎵鏈夊垎綾誨浘褰㈢殑褰㈢姸錛堝鎶樼嚎鍥劇殑鐐癸級
void setStroke(Stroke stroke) 鎵鏈夊垎綾誨浘褰㈢殑絎旇Е錛堝鎶樼嚎鍥劇殑綰匡級
void setSeriesItemLabelsVisible(int series,boolean visible) 鎸囧畾鍒嗙被鐨勬暟鎹爣絳炬槸鍚﹀彲瑙?br />void setSeriesItemLabelFont(int series,Font font) 鎸囧畾鍒嗙被鐨勬暟鎹爣絳劇殑瀛椾綋
void setSeriesItemLabelPaint(int series,Paint paint) 鎸囧畾鍒嗙被鐨勬暟鎹爣絳劇殑瀛椾綋棰滆壊
void setSeriesItemLabelPosition(int series,ItemLabelPosition position) 鏁版嵁鏍囩浣嶇疆
void setSeriesPositiveItemLabelPosition(int series,ItemLabelPosition position) 姝f暟鏍囩浣嶇疆
void setSeriesNegativeItemLabelPosition(int series,ItemLabelPosition position) 璐熸暟鏍囩浣嶇疆
void setSeriesOutLinePaint(int series,Paint paint) 鎸囧畾鍒嗙被鐨勫浘褰㈣竟妗嗙殑綰挎潯棰滆壊
void setSeriesOutLineStroke(int series,Stroke stroke) 鎸囧畾鍒嗙被鐨勫浘褰㈣竟妗嗙殑綰挎潯絎旇Е
void setSeriesPaint(int series,Paint paint) 鎸囧畾鍒嗙被鍥懼艦鐨勯鑹?br />void setSeriesShape(int series,Shape shape) 鎸囧畾鍒嗙被鍥懼艦鐨勫艦鐘訛紙濡傛姌綰垮浘鐨勭偣錛?br />void setSeriesStroke(int series,Stroke stroke) 鎸囧畾鍒嗙被鍥懼艦鐨勭瑪瑙︼紙濡傛姌綰垮浘鐨勭嚎錛?br />

AbstractCategoryItemRenderer(AbstractRenderer)綾伙細
void setLabelGenerator(CategoryLabelGenerator generator) 鏁版嵁鏍囩鐨勬牸寮?br />void setToolTipGenerator(CategoryToolTipGenerator generator) MAP涓紶鏍囩Щ涓婄殑鏄劇ず鏍煎紡
void setItemURLGenerator(CategoryURLGenerator generator) MAP涓捇鍙栭摼鎺ユ牸寮?br />void setSeriesLabelGenerator(int series,CategoryLabelGenerator generator) 鎸囧畾鍒嗙被鐨勬暟鎹爣絳劇殑鏍煎紡
void setSeriesToolTipGenerator(int series,CategoryToolTipGenerator generator) 鎸囧畾鍒嗙被鐨凪AP涓紶鏍囩Щ涓婄殑鏄劇ず鏍煎紡
void setSeriesItemURLGenerator(int series,CategoryURLGenerator generator) 鎸囧畾鍒嗙被鐨凪AP涓捇鍙栭摼鎺ユ牸寮?br />

BarRenderer(AbstractCategoryItemRenderer)綾伙細
void setDrawBarOutline(boolean draw) 鏄惁鐢誨浘褰㈣竟妗?br />void setItemMargin(double percent) 姣忎釜BAR涔嬮棿鐨勯棿闅?br />void setMaxBarWidth(double percent) 姣忎釜BAR鐨勬渶澶у搴?br />void setMinimumBarLength(double min) 鏈鐭殑BAR闀垮害錛岄伩鍏嶆暟鍊煎お灝忚屾樉紺轟笉鍑?br />void setPositiveItemLabelPositionFallback(ItemLabelPosition position) 鏃犳硶鍦˙AR涓樉紺虹殑姝f暟鏍囩浣嶇疆
void setNegativeItemLabelPositionFallback(ItemLabelPosition position) 鏃犳硶鍦˙AR涓樉紺虹殑璐熸暟鏍囩浣嶇疆

BarRenderer3D(BarRenderer)綾伙細
void setWallPaint(Paint paint) 3D鍧愭爣杞寸殑澧欎綋棰滆壊

StackedBarRenderer(BarRenderer)綾伙細
娌℃湁鐗規畩鐨勮緗?br />

StackedBarRenderer3D(BarRenderer3D)綾伙細
娌℃湁鐗規畩鐨勮緗?br />

GroupedStackedBarRenderer(StackedBarRenderer)綾伙細
void setSeriesToGroupMap(KeyToGroupMap map) 灝嗗垎綾昏嚜鐢辯殑鏄犲皠鎴愯嫢騫蹭釜緇勶紙KeyToGroupMap.mapKeyToGroup(series,group)錛?br />

LayeredBarRenderer(BarRenderer)綾伙細
void setSeriesBarWidth(int series,double width) 璁懼畾姣忎釜鍒嗙被鐨勫搴︼紙娉ㄦ剰璁劇疆涓嶈浣挎煇鍒嗙被琚鐩栵級

WaterfallBarRenderer(BarRenderer)綾伙細
void setFirstBarPaint(Paint paint) 絎竴涓煴鍥劇殑棰滆壊
void setLastBarPaint(Paint paint) 鏈鍚庝竴涓煴鍥劇殑棰滆壊
void setPositiveBarPaint(Paint paint) 姝e兼煴鍥劇殑棰滆壊
void setNegativeBarPaint(Paint paint) 璐熷兼煴鍥劇殑棰滆壊

IntervalBarRenderer(BarRenderer)綾伙細
闇瑕佷紶IntervalCategoryDataset浣滀負鏁版嵁婧?br />

GanttBarRenderer(IntervalBarRenderer)綾伙細
void setCompletePaint(Paint paint) 瀹屾垚榪涘害棰滆壊
void setIncompletePaint(Paint paint) 鏈畬鎴愯繘搴﹂鑹?br />void setStartPercent(double percent) 璁劇疆榪涘害鏉″湪鏁存潯涓殑璧峰浣嶇疆錛?.0锝?.0錛?br />void setEndPercent(double percent) 璁劇疆榪涘害鏉″湪鏁存潯涓殑緇撴潫浣嶇疆錛?.0锝?.0錛?br />

StatisticBarRenderer(BarRenderer)綾伙細
闇瑕佷紶StatisticCategoryDataset浣滀負鏁版嵁婧?br />

LineAndShapeRenderer(AbstractCategoryItemRenderer)綾伙細
void setDrawLines(boolean draw) 鏄惁鎶樼嚎鐨勬暟鎹偣涔嬮棿鐢ㄧ嚎榪?br />void setDrawShapes(boolean draw) 鏄惁鎶樼嚎鐨勬暟鎹偣鏍規嵁鍒嗙被浣跨敤涓嶅悓鐨勫艦鐘?br />void setShapesFilled(boolean filled) 鎵鏈夊垎綾繪槸鍚﹀~鍏呮暟鎹偣鍥懼艦
void setSeriesShapesFilled(int series,boolean filled) 鎸囧畾鍒嗙被鏄惁濉厖鏁版嵁鐐瑰浘褰?br />void setUseFillPaintForShapeOutline(boolean use) 鎸囧畾鏄惁濉厖鏁版嵁鐐圭殑Paint涔熻鐢ㄤ簬鐢繪暟鎹偣褰㈢姸鐨勮竟妗?br />

LevelRenderer(AbstractCategoryItemRenderer)綾伙細
void setItemMargin(double percent) 姣忎釜鍒嗙被涔嬮棿鐨勯棿闅?br />void setMaxItemWidth(double percent) 姣忎釜鍒嗙被鐨勬渶澶у搴?br />

CategoryStepRenderer(AbstractCategoryItemRenderer)綾伙細
void setStagger(boolean shouldStagger) 涓嶅悓鍒嗙被鐨勫浘鏄惁浜ら敊

MinMaxCategoryRenderer(AbstractCategoryItemRenderer)綾伙細
void setDrawLines(boolean drawLines) 鏄惁鍦ㄦ瘡涓垎綾葷嚎闂寸敾榪炴帴綰?br />void setGroupPaint(Paint groupPaint) 涓緇勫浘褰㈣繛鎺ョ嚎鐨勯鑹?br />void setGroupStroke(Stroke groupStroke) 涓緇勫浘褰㈣繛鎺ョ嚎鐨勭瑪瑙?br />void setMaxIcon(Icon maxIcon) 鏈澶у肩殑ICON
void setMinIcon(Icon minIcon) 鏈灝忓肩殑ICON
void setObjectIcon(Icon objectIcon) 鎵鏈夊肩殑ICON

AreaRender(AbstractCategoryItemRenderer)綾伙細
娌℃湁鐗規畩鐨勮緗?br />

StackedAreaRender(AreaRender)綾伙細
娌℃湁鐗規畩鐨勮緗?/p>




matthew 2006-08-14 14:39 鍙戣〃璇勮
]]>
鍩轟簬J2EE鐨勯潰鍚戝璞″瀷鏁版嵁鐨勬姤琛ㄧ郴緇熺殑璁捐涓庡疄鐜幫紞杞創http://www.tkk7.com/matthew2006/archive/2006/08/14/63473.htmlmatthewmatthewMon, 14 Aug 2006 06:35:00 GMThttp://www.tkk7.com/matthew2006/archive/2006/08/14/63473.htmlhttp://www.tkk7.com/matthew2006/comments/63473.htmlhttp://www.tkk7.com/matthew2006/archive/2006/08/14/63473.html#Feedback0http://www.tkk7.com/matthew2006/comments/commentRss/63473.htmlhttp://www.tkk7.com/matthew2006/services/trackbacks/63473.html涓銆乯FreeChart浜х敓鍥懼艦鐨勬祦紼?/span>
鍒涘緩涓涓暟鎹簮錛坉ataset錛夋潵鍖呭惈灝嗚鍦ㄥ浘褰腑鏄劇ず鐨勬暟鎹?????>>鍒涘緩涓涓?JFreeChart 瀵硅薄鏉ヤ唬琛ㄨ鏄劇ず鐨勫浘褰?br />??????>>鎶婂浘褰㈣緭鍑?br />閲嶈鐨勭被鍜屾帴鍙o細
org.jfree.data.general.Dataset 鎵鏈夋暟鎹簮綾婚兘瑕佸疄鐜扮殑鎺ュ彛
org.jfree.chart.ChartFactory 鐢卞畠鏉ヤ駭鐢?JFreeChart 瀵硅薄
org.jfree.chart.JFreeChart 鎵鏈夊鍥懼艦鐨勮皟鏁撮兘鏄氳繃瀹冨櫌錛侊紒
org.jfree.chart.plot.Plot 閫氳繃JFreeChart 瀵硅薄鑾峰緱瀹冿紝鐒跺悗鍐嶉氳繃瀹冨鍥懼艦澶栭儴閮ㄥ垎錛堜緥錛氬潗鏍囪醬錛夎皟鏁?br />娉ㄦ剰錛氬畠鏈夊緢澶氬瓙綾伙紝涓鑸兘涓嬪棈閫犲瀷鍒板畠鐨勫瓙綾伙紒
org.jfree.chart.renderer.AbstractRenderer 閫氳繃JFreeChart 瀵硅薄鑾峰緱瀹冿紝鐒跺悗鍐嶉氳繃瀹冨鍥懼艦鍐呴儴閮ㄥ垎
錛堜緥錛氭姌綰跨殑綾誨瀷錛夎皟鏁淬傚悓鏍鳳紝閽堝涓嶅悓綾誨瀷鐨勬姤琛ㄥ浘錛屽畠鏈?br />鐫涓嶅悓鐨勫瓙綾誨疄鐜幫紒鍦ㄤ笅闈㈡垜浠畝縐板畠涓?Renderer
涓嬮潰鎴戜滑緇撳悎涓嶅悓綾誨瀷鐨勫浘褰㈡潵鍏蜂綋鍒嗘瀽榪欎釜嫻佺▼銆?br />
浜屻侀ゼ鍥?/span>
楗煎浘鐨刣ataset 涓鑸槸鐢≒ieDataset 鎺ュ彛錛屽叿浣撳疄鐜扮被鏄?DefaultPieDataset
1銆佸垱寤轟竴涓暟鎹簮錛坉ataset錛夛細
private static PieDataset createDataset()
{
DefaultPieDataset defaultpiedataset = new DefaultPieDataset(); //娉ㄦ剰鏄疍efaultPieDataset錛侊紒
defaultpiedataset.setValue(鈥漁ne鈥? new Double(43.200000000000003D));
defaultpiedataset.setValue(鈥漈wo鈥? new Double(10D));
defaultpiedataset.setValue(鈥漈hree鈥? new Double(27.5D));
defaultpiedataset.setValue(鈥滷our鈥? new Double(17.5D));
return defaultpiedataset;
}
2銆佺敱ChartFactory 浜х敓 JFreeChart 瀵硅薄
private static JFreeChart createChart(PieDataset piedataset)
{
JFreeChart jfreechart = ChartFactory.createPieChart(鈥漃ie Chart Demo 1鈥? //鍥懼艦鏍囬鍚嶇О
piedataset, // dataset
true, // legend?
true, // tooltips?
false); //URLs?
PiePlot pieplot = (PiePlot)jfreechart.getPlot(); //閫氳繃JFreeChart 瀵硅薄鑾峰緱 plot錛歅iePlot錛侊紒
pieplot.setNoDataMessage(鈥漀o data available鈥?; // 娌℃湁鏁版嵁鐨勬椂鍊欐樉紺虹殑鍐呭
return jfreechart;
}
涓浜涢噸瑕佺殑鏂規硶錛?br />pieplot.setExplodePercent(0,0.3D) //鎶奓able 涓衡漁ne鈥?鐨勯偅涓鍧椻濇寲鈥濆嚭鏉?0%
3銆佽緭鍑虹暐

涓夈佹煴鐘跺浘
鏌辯姸鍥劇殑dataset 涓鑸槸鐢–atagoryDataset鎺ュ彛(鍏蜂綋瀹炵幇綾繪槸DefaultCategoryDataset),涔熶細鐢?IntervalXYDataset
鎺ュ彛
1銆佸垱寤轟竴涓暟鎹簮錛坉ataset錛夛細
private static CategoryDataset createDataset()
{
String series1 = 鈥淔irst鈥?
String series2 = 鈥淪econd鈥?
String series3 = 鈥淭hird鈥?
String category1 = 鈥淐ategory 1鈥?
String category2 = 鈥淐ategory 2鈥?
String category3 = 鈥淐ategory 3鈥?
String category4 = 鈥淐ategory 4鈥?
String category5 = 鈥淐ategory 5鈥?
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
defaultcategorydataset.addValue(1.0D, series1, category1);
defaultcategorydataset.addValue(4D, series1, category2);
defaultcategorydataset.addValue(3D, series1, category3);
defaultcategorydataset.addValue(5D, series1, category4);
defaultcategorydataset.addValue(5D, series1, category5);

defaultcategorydataset.addValue(5D, series2, category1);
defaultcategorydataset.addValue(7D, series2, category2);
defaultcategorydataset.addValue(6D, series2, category3);
defaultcategorydataset.addValue(8D, series2, category4);
defaultcategorydataset.addValue(4D, series2, category5);

defaultcategorydataset.addValue(4D, series3, category1);
defaultcategorydataset.addValue(3D, series3, category2);
defaultcategorydataset.addValue(2D, series3, category3);
defaultcategorydataset.addValue(3D, series3, category4);
defaultcategorydataset.addValue(6D, series3, category5);
return defaultcategorydataset;
}
2銆佺敱ChartFactory 浜х敓 JFreeChart 瀵硅薄
private static JFreeChart createChart(CategoryDataset categorydataset)
{
JFreeChart jfreechart = ChartFactory.createBarChart(鈥滲ar Chart Demo鈥? //鍥懼艦鏍囬鍚嶇О
鈥淐ategory鈥?//domain 杞?Lable
榪欓噷鍏堢畝鍗曠悊瑙d負妯潗鏍嘗able濂戒簡
鈥淰alue鈥? //range 杞?Lable
榪欓噷涔熷厛綆鍗曠悊瑙d負綰靛潗鏍嘗able濂戒簡
categorydataset, // dataset
PlotOrientation.VERTICAL, //鍨傜洿鏄劇ず
true, // legend?
true, // tooltips?
false); //URLs?
jfreechart.setBackgroundPaint(Color.white); //璁懼畾鑳屾櫙鑹蹭負鐧借壊
CategoryPlot categoryplot = jfreechart.getCategoryPlot(); //鑾峰緱 plot錛欳ategoryPlot錛侊紒
categoryplot.setBackgroundPaint(Color.lightGray); //璁懼畾鍥捐〃鏁版嵁鏄劇ず閮ㄥ垎鑳屾櫙鑹?br />categoryplot.setDomainGridlinePaint(Color.white); //妯潗鏍囩綉鏍肩嚎鐧借壊
categoryplot.setDomainGridlinesVisible(true); //鍙
categoryplot.setRangeGridlinePaint(Color.white); //綰靛潗鏍囩綉鏍肩嚎鐧借壊
//涓嬮潰涓よ浣跨旱鍧愭爣鐨勬渶灝忓崟浣嶆牸涓烘暣鏁?br />NumberAxis numberaxis = (NumberAxis)categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
BarRenderer barrenderer = (BarRenderer)categoryplot.getRenderer(); //鑾峰緱renderer 娉ㄦ剰榪欓噷鏄笅鍡嶉犲瀷
鍒癇arRenderer錛侊紒
barrenderer.setDrawBarOutline(false); // Bar鐨勫杞粨綰夸笉鐢?br />GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue,
0.0F, 0.0F, new Color(0, 0, 64)); //璁懼畾鐗瑰畾棰滆壊
GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green,
0.0F, 0.0F, new Color(0, 64, 0));
GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red,
0.0F, 0.0F, new Color(64, 0, 0));
barrenderer.setSeriesPaint(0, gradientpaint); //緇檚eries1 Bar璁懼畾涓婇潰瀹氫箟鐨勯鑹?br />barrenderer.setSeriesPaint(1, gradientpaint1); //緇檚eries2 Bar 璁懼畾涓婇潰瀹氫箟鐨勯鑹?br />barrenderer.setSeriesPaint(2, gradientpaint2); //緇檚eries3 Bar 璁懼畾涓婇潰瀹氫箟鐨勯鑹?br />CategoryAxis categoryaxis = categoryplot.getDomainAxis(); //妯醬涓婄殑 Lable 45搴﹀炬枩
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
return jfreechart;
}
涓浜涢噸瑕佺殑鏂規硶錛氾紙澧炲姞涓鍧楁爣璁幫級
IntervalMarker intervalmarker = new IntervalMarker(4.5D, 7.5D);
intervalmarker.setLabel(鈥漈arget Range鈥?;
intervalmarker.setLabelFont(new Font(鈥漇ansSerif鈥? 2, 11));
intervalmarker.setLabelAnchor(RectangleAnchor.LEFT);
intervalmarker.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
intervalmarker.setPaint(new Color(222, 222, 255, 128));
categoryplot.addRangeMarker(intervalmarker, Layer.BACKGROUND);

鍥涖佹姌綰垮浘
鎶樼嚎鍥劇殑dataset 涓ょCatagoryDataset鎺ュ彛(鍏蜂綋瀹炵幇綾繪槸DefaultCategoryDataset),XYDataset 鎺ュ彛
1銆丆atagoryDataset鎺ュ彛錛?br />A銆佸垱寤轟竴涓暟鎹簮錛坉ataset錛夛細
private static CategoryDataset createDataset()
{
String series1 = 鈥淔irst鈥?
String series2 = 鈥淪econd鈥?
String series3 = 鈥淭hird鈥?
String type1 = 鈥淭ype 1鈥?
String type2 = 鈥淭ype 2鈥?
String type3 = 鈥淭ype 3鈥?
String type4 = 鈥淭ype 4鈥?
String type5 = 鈥淭ype 5鈥?
String type6 = 鈥淭ype 6鈥?
String type7 = 鈥淭ype 7鈥?
String type8 = 鈥淭ype 8鈥?
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
defaultcategorydataset.addValue(1.0D, series1, type1);
defaultcategorydataset.addValue(4D, series1, type2);
defaultcategorydataset.addValue(3D, series1, type3);
defaultcategorydataset.addValue(5D, series1, type4);
defaultcategorydataset.addValue(5D, series1, type5);
defaultcategorydataset.addValue(7D, series1, type6);
defaultcategorydataset.addValue(7D, series1, type7);
defaultcategorydataset.addValue(8D, series1, type8);

defaultcategorydataset.addValue(5D, series2, type1);
defaultcategorydataset.addValue(7D, series2, type2);
defaultcategorydataset.addValue(6D, series2, type3);
defaultcategorydataset.addValue(8D, series2, type4);
defaultcategorydataset.addValue(4D, series2, type5);
defaultcategorydataset.addValue(4D, series2, type6);
defaultcategorydataset.addValue(2D, series2, type7);
defaultcategorydataset.addValue(1.0D, series2, type8);

defaultcategorydataset.addValue(4D, series3, type1);
defaultcategorydataset.addValue(3D, series3, type2);
defaultcategorydataset.addValue(2D, series3, type3);
defaultcategorydataset.addValue(3D, series3, type4);
defaultcategorydataset.addValue(6D, series3, type5);
defaultcategorydataset.addValue(3D, series3, type6);
defaultcategorydataset.addValue(4D, series3, type7);
defaultcategorydataset.addValue(3D, series3, type8);
return defaultcategorydataset;
}
B銆佺敱ChartFactory 浜х敓 JFreeChart 瀵硅薄 (涓庝笂闈㈤噸澶嶇殑閮ㄥ垎灝變笉鍐嶆敞閲婏級
private static JFreeChart createChart(CategoryDataset categorydataset)
{
JFreeChart jfreechart = ChartFactory.createLineChart(鈥滾ine Chart Demo 1鈥?
鈥淭ype鈥?
鈥淰alue鈥?
categorydataset,
PlotOrientation.VERTICAL,
true,
true,
false);
jfreechart.setBackgroundPaint(Color.white);
CategoryPlot categoryplot = (CategoryPlot)jfreechart.getPlot();
categoryplot.setBackgroundPaint(Color.lightGray);
categoryplot.setRangeGridlinePaint(Color.white);
NumberAxis numberaxis = (NumberAxis)categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
numberaxis.setAutoRangeIncludesZero(true);
//鑾峰緱renderer 娉ㄦ剰榪欓噷鏄笅鍡嶉犲瀷鍒發ineandshaperenderer錛侊紒
LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer)categoryplot.getRenderer();
lineandshaperenderer.setShapesVisible(true); //series 鐐癸紙鍗蟲暟鎹偣錛夊彲瑙?br />lineandshaperenderer.setSeriesStroke(0, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] {
10F, 6F
}, 0.0F)); //瀹氫箟series涓衡滷irst鈥濈殑錛堝嵆series1錛夌偣涔嬮棿鐨勮繛綰?錛岃繖閲屾槸铏氱嚎錛岄粯璁ゆ槸鐩寸嚎
lineandshaperenderer.setSeriesStroke(1, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] {
6F, 6F
}, 0.0F)); //瀹氫箟series涓衡漇econd鈥濈殑錛堝嵆series2錛夌偣涔嬮棿鐨勮繛綰?br />lineandshaperenderer.setSeriesStroke(2, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] {
2.0F, 6F
}, 0.0F)); //瀹氫箟series涓衡漈hird鈥濈殑錛堝嵆series3錛夌偣涔嬮棿鐨勮繛綰?br />return jfreechart;
}
涓浜涢噸瑕佺殑鏂規硶錛?br />lineandshaperenderer.setLineVisible(true) //series 鐐癸紙鍗蟲暟鎹偣錛夐棿鏈夎繛綰垮彲瑙?br />2銆乆YDataset 鎺ュ彛錛?br />A銆佸垱寤轟竴涓暟鎹簮錛坉ataset錛夛細
private static XYDataset createDataset()
{
XYSeries xyseries = new XYSeries(鈥滷irst鈥?; //鍏堜駭鐢焁YSeries 瀵硅薄
xyseries.add(1.0D, 1.0D);
xyseries.add(2D, 4D);
xyseries.add(3D, 3D);
xyseries.add(4D, 5D);
xyseries.add(5D, 5D);
xyseries.add(6D, 7D);
xyseries.add(7D, 7D);
xyseries.add(8D, 8D);

XYSeries xyseries1 = new XYSeries(鈥漇econd鈥?;
xyseries1.add(1.0D, 5D);
xyseries1.add(2D, 7D);
xyseries1.add(3D, 6D);
xyseries1.add(4D, 8D);
xyseries1.add(5D, 4D);
xyseries1.add(6D, 4D);
xyseries1.add(7D, 2D);
xyseries1.add(8D, 1.0D);

XYSeries xyseries2 = new XYSeries(鈥漈hird鈥?;
xyseries2.add(3D, 4D);
xyseries2.add(4D, 3D);
xyseries2.add(5D, 2D);
xyseries2.add(6D, 3D);
xyseries2.add(7D, 6D);
xyseries2.add(8D, 3D);
xyseries2.add(9D, 4D);
xyseries2.add(10D, 3D);

XYSeriesCollection xyseriescollection = new XYSeriesCollection(); //鍐嶇敤XYSeriesCollection娣誨姞鍏YSeries 瀵硅薄
xyseriescollection.addSeries(xyseries);
xyseriescollection.addSeries(xyseries1);
xyseriescollection.addSeries(xyseries2);
return xyseriescollection;
}
B銆佺敱ChartFactory 浜х敓 JFreeChart 瀵硅薄
private static JFreeChart createChart(XYDataset xydataset)
{
JFreeChart jfreechart = ChartFactory.createXYLineChart(鈥滾ine Chart Demo 2鈥?
鈥淴鈥?
鈥淵鈥?
xydataset,
PlotOrientation.VERTICAL,
true,
true,
false);
jfreechart.setBackgroundPaint(Color.white);
XYPlot xyplot = (XYPlot)jfreechart.getPlot(); //鑾峰緱 plot錛歑YPlot錛侊紒
xyplot.setBackgroundPaint(Color.lightGray); //璁懼畾鍥捐〃鏁版嵁鏄劇ず閮ㄥ垎鑳屾櫙鑹?br />xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); //璁懼畾鍧愭爣杞翠笌鍥捐〃鏁版嵁鏄劇ず閮ㄥ垎璺濈
xyplot.setDomainGridlinePaint(Color.white); //緗戞牸綰塊鑹?br />xyplot.setRangeGridlinePaint(Color.white);
//鑾峰緱 renderer 娉ㄦ剰榪欓噷鏄疿YLineAndShapeRenderer 錛侊紒
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyplot.getRenderer();
xylineandshaperenderer.setShapesVisible(true); //鏁版嵁鐐瑰彲瑙?br />xylineandshaperenderer.setShapesFilled(true); //鏁版嵁鐐硅濉厖鍗充笉鏄┖蹇冪偣
NumberAxis numberaxis = (NumberAxis)xyplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
return jfreechart;
}
涓浜涢噸瑕佺殑鏂規硶錛?br />XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
xylineandshaperenderer.setSeriesLinesVisible(0, false); //絎竴涓猉YSeries鏁版嵁鐐歸棿榪炵嚎涓嶅彲瑙?br />xylineandshaperenderer.setSeriesShapesVisible(1, false); //絎簩涓猉YSeries鏁版嵁鐐逛笉鍙
xyplot.setRenderer(xylineandshaperenderer);

浜斻佹椂闂村簭鍒楀浘
鏃墮棿搴忓垪鍥懼拰鎶樼嚎鍥懼緢鐩鎬技錛屼笉鍚岀殑鏄畠鍦?domain杞寸殑鏁版嵁鏄椂闂磋屼笉鏄暟瀛椼?鏃墮棿搴忓垪鍥劇殑dataset 鏄?br />XYDataset 鎺ュ彛錛屽叿浣撳疄鐜扮被鏄疶imeSeriesCollection 錛屽拰涓婇潰綾諱技錛屾湁TimeSeries 瀵硅薄錛屽畠琚坊鍔犲叆
TimeSeriesCollection 銆?br />1銆佸垱寤轟竴涓暟鎹簮錛坉ataset錛夛細
private static XYDataset createDataset()
{
TimeSeries timeseries = new TimeSeries(鈥滾&G European Index Trust鈥?Month.class);
timeseries.add(new Month(2, 2001), 181.8D);//榪欓噷鐢ㄧ殑鏄疢onth.class錛屽悓鏍瘋繕鏈塂ay.class Year.class 絳夌瓑
timeseries.add(new Month(3, 2001), 167.3D);
timeseries.add(new Month(4, 2001), 153.8D);
timeseries.add(new Month(5, 2001), 167.6D);
timeseries.add(new Month(6, 2001), 158.8D);
timeseries.add(new Month(7, 2001), 148.3D);
timeseries.add(new Month(8, 2001), 153.9D);
timeseries.add(new Month(9, 2001), 142.7D);
timeseries.add(new Month(10, 2001), 123.2D);
timeseries.add(new Month(11, 2001), 131.8D);
timeseries.add(new Month(12, 2001), 139.6D);
timeseries.add(new Month(1, 2002), 142.9D);
timeseries.add(new Month(2, 2002), 138.7D);
timeseries.add(new Month(3, 2002), 137.3D);
timeseries.add(new Month(4, 2002), 143.9D);
timeseries.add(new Month(5, 2002), 139.8D);
timeseries.add(new Month(6, 2002), 137D);
timeseries.add(new Month(7, 2002), 132.8D);

TimeSeries timeseries1 = new TimeSeries(鈥滾&G UK Index Trust鈥?Month.class);
timeseries1.add(new Month(2, 2001), 129.6D);
timeseries1.add(new Month(3, 2001), 123.2D);
timeseries1.add(new Month(4, 2001), 117.2D);
timeseries1.add(new Month(5, 2001), 124.1D);
timeseries1.add(new Month(6, 2001), 122.6D);
timeseries1.add(new Month(7, 2001), 119.2D);
timeseries1.add(new Month(8, 2001), 116.5D);
timeseries1.add(new Month(9, 2001), 112.7D);
timeseries1.add(new Month(10, 2001), 101.5D);
timeseries1.add(new Month(11, 2001), 106.1D);
timeseries1.add(new Month(12, 2001), 110.3D);
timeseries1.add(new Month(1, 2002), 111.7D);
timeseries1.add(new Month(2, 2002), 111D);
timeseries1.add(new Month(3, 2002), 109.6D);
timeseries1.add(new Month(4, 2002), 113.2D);
timeseries1.add(new Month(5, 2002), 111.6D);
timeseries1.add(new Month(6, 2002), 108.8D);
timeseries1.add(new Month(7, 2002), 101.6D);
TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
timeseriescollection.addSeries(timeseries);
timeseriescollection.addSeries(timeseries1);
timeseriescollection.setDomainIsPointsInTime(true); //domain杞翠笂鐨勫埢搴︾偣浠h〃鐨勬槸鏃墮棿鐐硅屼笉鏄椂闂存
return timeseriescollection;
}
2銆佺敱ChartFactory 浜х敓 JFreeChart 瀵硅薄
private static JFreeChart createChart(XYDataset xydataset)
{
JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(鈥滾egal & General Unit Trust Prices鈥?
鈥淒ate鈥?
鈥淧rice Per Unit鈥?
xydataset,
true,
true,
false);
jfreechart.setBackgroundPaint(Color.white);
XYPlot xyplot = (XYPlot)jfreechart.getPlot(); //鑾峰緱 plot : XYPlot!!
xyplot.setBackgroundPaint(Color.lightGray);
xyplot.setDomainGridlinePaint(Color.white);
xyplot.setRangeGridlinePaint(Color.white);
xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
xyplot.setDomainCrosshairVisible(true);
xyplot.setRangeCrosshairVisible(true);
org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
if(xyitemrenderer instanceof XYLineAndShapeRenderer)
{
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyitemrenderer;
xylineandshaperenderer.setDefaultShapesVisible(true); //鏁版嵁鐐瑰彲瑙?br />xylineandshaperenderer.setDefaultShapesFilled(true); //鏁版嵁鐐規槸瀹炲績鐐?br />}
DateAxis dateaxis = (DateAxis)xyplot.getDomainAxis(); //瀵筪omain 杞翠笂鏃ユ湡鏄劇ず鏍煎紡瀹氫箟
dateaxis.setDateFormatOverride(new SimpleDateFormat(鈥滿MM-yyyy鈥?);
return jfreechart;
}
涓浜涢噸瑕佺殑鏂規硶錛?br />A銆佸鍔犳爣璁扮嚎錛?br />xyplot.addRangeMarker(new ValueMarker(550D)); //鏁板艱醬
Quarter quarter = new Quarter(2, 2002);
xyplot.addDomainMarker(new ValueMarker(quarter.getMiddleMillisecond())); //鏃墮棿杞?br />B銆佹暟鎹偣鐨勮皟鏁?br />XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyplot.getRenderer();
xylineandshaperenderer.setDefaultShapesVisible(true); //鏁版嵁鐐瑰彲瑙?br />xylineandshaperenderer.setSeriesFillPaint(0, Color.red); //鏁版嵁鐐瑰~鍏呬負綰㈣壊
xylineandshaperenderer.setSeriesFillPaint(1, Color.white); //鏁版嵁鐐瑰~鍏呬負鐧借壊
xylineandshaperenderer.setUseFillPaint(true); //搴旂敤
C銆佸鉤鍧囧兼洸綰?br />榪欎釜鏇茬嚎鏈変粈涔堢敤鍛紵寰堢畝鍗曠殑渚嬪瓙錛岃繖閲屾湁涓涓互鍗婂勾姣忓ぉ涓哄崟浣嶇殑鏁版嵁緇樺埗鐨勬洸綰匡紝鎴戜滑鎯崇湅鐪嬩互鏈堜負鍗曚綅鏁版嵁
鐨勫彉鍖栵紝榪欐椂灝卞彲浠ョ敤鍒板畠浜嗐?br />TimeSeries timeseries = createEURTimeSeries(); //灝辨槸浠ュ崐騫存瘡澶╀負鍗曚綅鐨勬暟鎹?br />TimeSeries timeseries1 = MovingAverage.createMovingAverage(timeseries,
鈥?0 day moving average鈥?
30, //30澶╀負涓涓懆鏈?br />30); //鏈寮濮嬬殑30澶╄煩榪?br />TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
timeseriescollection.addSeries(timeseries);
timeseriescollection.addSeries(timeseries1);
return timeseriescollection;

鍏佹葷粨涓涓?/span>
dataset plot renderer
楗煎浘 PieDataset錛圖efaultPieDataset錛?PiePlot 鈥斺?br />鏌辯姸鍥?CatagoryDataset錛圖efaultCategoryDataset錛?CategoryPlot BarRenderer
鎶樼嚎鍥?CatagoryDataset錛圖efaultCategoryDataset錛?CategoryPlot LineAndShapeRenderer
XYDataset錛圶YSeriesCollection錛?XYPlot XYLineAndShapeRenderer
鏃墮棿搴忓垪鍥?XYDataset 錛圱imeSeriesCollection錛?XYPlot XYLineAndShapeRenderer
榪欓噷鍙槸涓浜涘父鐢ㄧ殑鏂規硶錛屽叿浣撹繕鏄湅API
涓冦両tem Lable
榪欓噷浠ユ煴鐘跺浘涓轟緥璇存槑錛屽叿浣撴潵璇村氨鏄湪姣忎釜鏌辯姸涓婃樉紺哄畠鐨勬暟鎹紝鍏蜂綋鏈変笅闈㈠唴瀹癸細
A銆佷嬌 Item Lable 鍙
B銆佽皟鏁?Item Lable 鐨勯鑹層佸瓧浣撶瓑
C銆佽皟鏁?Item Lable 鐨勪綅緗?br />D銆佸畾鍒?Item Lable 鐨勫唴瀹?br />1銆佸垎閰嶄竴涓?Lable Generator 緇?renderer
BarRenderer barrenderer = (BarRenderer)categoryplot.getRenderer();
GategoryLableGenerator generator =new StandardGategoryLableGenerator(
鈥渰2}鈥? new DecimalFormat(鈥?.00鈥? //璋冩暣鏄劇ず鐨勬暟瀛楀拰瀛楃鏍煎紡
);
barrenderer.setLableGenerator(generator);
2銆佷嬌 Item Lable 鍙
barrenderer.setItemLableVisible(true);
3銆佽皟鏁?Item Lable 鐨勯鑹層佸瓧浣撶瓑
barrenderer.setItemLablePaint(Color.red);
barrenderer.setItemLableFont(new Font(鈥漇ansSerif鈥?Font.PLAIN,10));
4銆佽皟鏁?Item Lable 鐨勪綅緗?br />榪欓噷娑夊強鍒頒竴涓柊鐨勫璞?ItemLablePosition , ItemLablePosition鐨勬瀯閫犲嚱鏁版湁涓や釜鎴栧洓涓弬鏁?br />public ItemLabelPosition(ItemLabelAnchor itemLabelAnchor,
org.jfree.ui.TextAnchor textAnchor,
org.jfree.ui.TextAnchor rotationAnchor,
double angle)
itemLabelAnchor - Item Lable 鐨勪綅緗?錛堟渶閲嶈鐨勶紒錛侊級
textAnchor - Item Lable閲屽寘鍚殑姝f枃鐩稿浜嶪tem Lable 鐨勪綅緗?br />rotationAnchor - Item Lable閲屽寘鍚殑姝f枃鏃嬭漿鐨勪綅緗?br />angle - 鏃嬭漿鐨勮搴?br />ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE12,
TextAnchor.CENTER_RIGHT,
TextAnchor.CENTER_RIGHT,
-1.57D);
barrenderer.setPositiveItemLabelPosition(itemlabelposition);
榪欐牱灝卞彲浠ユ瘡涓煴鐘朵笂鏄劇ず瀹冪殑鏁版嵁浜嗭紝褰撶劧鍙互瀹氬埗 Item Lable 鐨勫唴瀹癸紝姣斿 Item Lable text 瓚呰繃100鐨勬墠
鏄劇ず錛岃繖鏍峰氨闇瑕佸畾鍒惰嚜宸辯殑綾伙紝瀹冭瀹炵幇GategoryLableGenerator 鎺ュ彛錛屽疄鐜癵enerateItemLable()鏂規硶


matthew 2006-08-14 14:35 鍙戣〃璇勮
]]>
JFreeChart 鍒濆http://www.tkk7.com/matthew2006/archive/2006/07/07/57143.htmlmatthewmatthewFri, 07 Jul 2006 07:26:00 GMThttp://www.tkk7.com/matthew2006/archive/2006/07/07/57143.htmlhttp://www.tkk7.com/matthew2006/comments/57143.htmlhttp://www.tkk7.com/matthew2006/archive/2006/07/07/57143.html#Feedback4http://www.tkk7.com/matthew2006/comments/commentRss/57143.htmlhttp://www.tkk7.com/matthew2006/services/trackbacks/57143.html鐢變簬欏圭洰闇姹傚師鍥狅紝涓婄綉鐪嬩簡浜汮freeChart鐨勪緥瀛愩傝嚜宸卞氨璇曠潃鐢ㄤ簡涓嬶細
BarCharDemo.jsp
<%@page contentType="text/html; charset=GB2312"%>

<%@page import="java.io.FileNotFoundException"%>
<%@page import="java.io.FileOutputStream"%>
<%@page import="org.apache.commons.logging.Log"%>
<%@page import="java.io.IOException"%>


<%@page import="org.apache.commons.logging.LogFactory"%>
<%@page import="org.jfree.chart.ChartFactory"%>
<%@page import="org.jfree.chart.ChartUtilities"%>
<%@page import="org.jfree.chart.JFreeChart"%>
<%@page import="org.jfree.chart.plot.PlotOrientation"%>
<%@page import="org.jfree.data.general.DefaultPieDataset"%>
<%@page import="org.jfree.data.general.PieDataset"%>
<%
DefaultPieDataset聽 dataset聽聽聽 = new DefaultPieDataset ();
聽 dataset.setValue("鑻規灉",100);聽
聽 dataset.setValue("姊?,200);
聽 dataset.setValue("棣欒晧",300);
聽 dataset.setValue("鑺掓灉",400);
聽 dataset.setValue("钁¤悇",500);


聽聽 JFreeChart chart聽聽聽聽聽 = ChartFactory.createPieChart3D(
聽聽聽 "姘存灉浜ч噺鍥?,聽聽聽聽聽聽 //鍥炬爣鏍囬
聽聽聽 dataset,聽聽聽聽聽聽 //鏁版嵁闆?br />聽聽聽 true,聽聽聽聽聽聽聽 //鏄惁鏄劇ず鍥句緥錛堢畝鍗曠殑鏌辮鍥懼繀欏繪槸fasle錛?br />聽聽聽 false,聽聽聽聽聽聽聽 //鏄惁鐢熸垚宸ュ叿
聽聽聽 false聽聽聽聽聽聽聽 //鏄惁鐢熸垚URL閾炬帴
聽聽聽 );

聽聽聽
聽聽聽 ChartUtilities.writeChartAsJPEG(response.getOutputStream(),chart,640,370);
%>

PieChartDemo.jsp
<%@page contentType="text/html; charset=GB2312"%>

<%@page import="java.io.FileNotFoundException"%>
<%@page import="java.io.FileOutputStream"%>
<%@page import="org.apache.commons.logging.Log"%>
<%@page import="java.io.IOException"%>

<%@page import="org.apache.commons.logging.LogFactory"%>
<%@page import="org.jfree.chart.ChartFactory"%>
<%@page import="org.jfree.chart.ChartUtilities"%>
<%@page import="org.jfree.chart.JFreeChart"%>
<%@page import="org.jfree.chart.plot.PlotOrientation"%>
<%@page import="org.jfree.data.category.CategoryDataset"%>
<%@page import="org.jfree.data.category.DefaultCategoryDataset"%>
<%
DefaultCategoryDataset dataset聽聽聽 = new DefaultCategoryDataset();
聽dataset.addValue(100, "鍖椾含", "鑻規灉");
聽 dataset.addValue(130, "涓婃搗", "鑻規灉");
聽 dataset.addValue(160, "騫垮窞", "鑻規灉");
聽 dataset.addValue(200, "鍖椾含", "姊ㄥ瓙");
聽 dataset.addValue(230, "涓婃搗", "姊ㄥ瓙");
聽 dataset.addValue(260, "騫垮窞", "姊ㄥ瓙");
聽 dataset.addValue(300, "鍖椾含", "钁¤悇");
聽 dataset.addValue(330, "涓婃搗", "钁¤悇");
聽 dataset.addValue(360, "騫垮窞", "钁¤悇");
聽 dataset.addValue(400, "鍖椾含", "棣欒晧");
聽 dataset.addValue(430, "涓婃搗", "棣欒晧");
聽 dataset.addValue(460, "騫垮窞", "棣欒晧");
聽 dataset.addValue(500, "鍖椾含", "鑽旀灊");
聽 dataset.addValue(530, "涓婃搗", "鑽旀灊");
聽 dataset.addValue(560, "騫垮窞", "鑽旀灊");

聽聽聽 JFreeChart chart聽聽聽聽聽 = ChartFactory.createBarChart3D(
聽聽聽 "姘存灉浜ч噺鍥?,聽聽聽聽聽聽 //鍥炬爣鏍囬
聽聽聽 "姘存灉",聽聽聽聽聽聽聽 //鐩綍杞存樉紺烘爣絳?錛坸杞達級
聽聽聽 "浜ч噺",聽聽聽聽聽聽聽 //鏁版嵁杞存樉紺烘爣絳?錛坹杞達級
聽聽聽 dataset,聽聽聽聽聽聽 //鏁版嵁闆?br />聽聽聽 PlotOrientation.VERTICAL,聽聽 //鍥炬爣鏂瑰悜錛氭按騫籌紝鍨傜洿
聽聽聽 true,聽聽聽聽聽聽聽 //鏄惁鏄劇ず鍥句緥錛堢畝鍗曠殑鏌辮鍥懼繀欏繪槸fasle錛?br />聽聽聽 false,聽聽聽聽聽聽聽 //鏄惁鐢熸垚宸ュ叿
聽聽聽 false聽聽聽聽聽聽聽 //鏄惁鐢熸垚URL閾炬帴
聽聽聽 );
聽聽聽
聽聽聽 ChartUtilities.writeChartAsJPEG(response.getOutputStream(),chart,640,370);
%>

TimeSeriesDemo錛堝湪欏甸潰涓婃樉紺猴級
棣栧厛閰嶇疆web.xml
<servlet>
聽聽<servlet-name>DisplayChart</servlet-name>
聽聽<servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
聽</servlet>


聽<servlet-mapping>
聽聽<servlet-name>DisplayChart</servlet-name>
聽聽<url-pattern>/servlet/DisplayChart</url-pattern>
聽</servlet-mapping>


TimeSeriesDemo.java

package net.neitbe.home.jfreechart.business;

import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.io.IOException;

import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.time.TimeSeriesDataItem;

/**
聽* @author neitbe
聽*/
public class TimeSeriesDemo {

聽private static Log log聽聽聽聽= LogFactory.getLog(TimeSeriesDemo.class);

聽//鏇茬嚎鍥炬爣棰?br />聽private String title聽聽聽聽= "瓚嬪娍鍒嗘瀽";
聽//鏇茬嚎鍥綳杞存彁紺?br />聽private String domain聽聽聽聽= "鏈堜喚璧板娍";
聽//鏇茬嚎鍥綴杞存彁紺?br />聽private String range聽聽聽聽= "搴旀敹浣欓";
聽//鏇茬嚎鍥捐嚜鏍囬
聽private String subtitleStr聽聽聽= "2005璐㈠勾鍒嗘瀽";

聽//鍒涘緩鏃墮棿鏁版嵁婧?br />聽//姣忎竴涓猅imeSeries鍦ㄥ浘涓婃槸涓鏉℃洸綰?br />聽private TimeSeries yongyou聽聽聽聽= new TimeSeries("鐢ㄥ弸");
聽private TimeSeries jindie聽聽聽聽= new TimeSeries("閲戠");
聽private TimeSeries dongruan聽聽聽聽= new TimeSeries("涓滆蔣");

聽//鏃墮棿鏇茬嚎鏁版嵁闆嗗悎
聽private static TimeSeriesCollection dataset聽= new TimeSeriesCollection();


聽private void setDataset() {
聽聽dataset.removeAllSeries();聽聽聽聽聽聽聽聽//鍦╦avaBean涓嬌鐢ㄦ綾昏繖涓緢閲嶈錛屼笉鐒朵細涓嶅仠鐨勫姞鍏ユ柊鐨凾imeSeries;
聽聽dataset.addSeries(this.yongyou);
聽聽dataset.addSeries(this.jindie);
聽聽dataset.addSeries(this.dongruan);
聽聽
聽}

聽private void setDongruan() {
聽聽this.dongruan.clear();聽聽聽聽聽//寰堥噸瑕侊紝涓嶇劧浼氭姤閿?br />聽聽/**
聽聽 * 鎶ラ敊
聽聽 * org.apache.jasper.JasperException: You are attempting to add an observation for the time period
聽聽 * 榪欓噷鏄湪綾誨睘鎬ч噷澹版槑TimeSeries鎵嶇敤鍒扮殑
聽聽 */
聽聽for(int i = 1999; i < 2005; i++) {
聽聽聽for(int mon = 0; mon < 12; mon++) {
聽聽聽聽
聽聽聽聽this.dongruan.add(new TimeSeriesDataItem(new Day(1,mon+1,i),new Double(300 - Math.random()*100)));
聽聽聽}
聽聽}
聽}

聽private void setJindie() {
聽聽
聽聽this.jindie.clear();聽聽聽聽//寰堥噸瑕侊紝涓嶇劧浼氭姤閿?br />聽聽for(int i = 1999; i < 2005; i++) {
聽聽聽for(int mon = 0; mon < 12; mon++) {
聽聽聽聽this.jindie.add(new TimeSeriesDataItem(new Day(1,mon+1,i),new Double(400 - Math.random()*100)));
聽聽聽}
聽聽}
聽}

聽private void setYongyou() {
聽聽this.yongyou.clear();聽聽聽//寰堥噸瑕侊紝涓嶇劧浼氭姤閿?br />聽聽for(int i = 1999; i < 2005; i++) {
聽聽聽for(int mon = 0; mon < 12; mon++) {
聽聽聽聽this.yongyou.add(new TimeSeriesDataItem(new Day(1,mon+1,i),new Double(500 - Math.random()*100)));
聽聽聽}
聽聽}
聽聽
聽}

聽private TimeSeriesCollection getDataset() {
聽聽this.setDongruan();
聽聽this.setJindie();
聽聽this.setYongyou();
聽聽this.setDataset();
聽聽return dataset;
聽}

聽public String drawPic(HttpSession session) {
聽聽String fileName聽聽聽聽聽聽聽= null;
聽聽JFreeChart chart聽聽聽聽聽聽= ChartFactory.createTimeSeriesChart(title,domain,range,getDataset(),true,true,false);
聽聽TextTitle subTitle聽聽聽聽聽聽= new TextTitle(subtitleStr,new Font("榛戜綋",Font.BOLD,12));
聽聽chart.addSubtitle(subTitle);
聽聽chart.setTitle(new TextTitle(title,new Font("闅朵功",Font.ITALIC,15)));
聽聽chart.setBorderPaint(new GradientPaint(0,0,Color.white,0,1000,Color.blue));
聽聽//String fileName聽聽聽聽聽聽聽= "D:\\fuit2.jpeg";
聽聽try {
聽聽聽ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());


聽聽聽log.debug("鍑嗗鍒涘緩鍥劇墖鈥︹?);
聽聽聽fileName聽聽聽聽聽聽聽= ServletUtilities.saveChartAsJPEG(chart,600,600,info,session);
聽聽聽log.debug("鍥劇墖鍒涘緩鎴愬姛錛?);
聽聽} catch (IOException e) {
聽聽聽log.error("IO寮傚父錛?,e);
聽聽}
聽聽log.debug("榪斿洖鐨勬枃浠跺悕涓猴細" + fileName);
聽聽return fileName;
聽}

聽/*public static void main(String[] args) {
聽聽TimeSeriesDemo聽timeSeriesDemo聽聽聽= new TimeSeriesDemo();
聽聽timeSeriesDemo.drawPic();
聽}*/



}


index.jsp欏甸潰錛?br /> <%@ page language="java" contentType="text/html; charset=GBK"
聽聽聽 pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
<jsp:useBean id="timeSeries" scope="session" class="net.neitbe.home.jfreechart.business.TimeSeriesDemo"/>
</head>
<body>
<%
聽String fileName聽聽聽= timeSeries.drawPic(request.getSession());
聽String graphURL聽聽聽= request.getContextPath()+"/servlet/DisplayChart?filename=" + fileName;
%>
<%=graphURL%><br/>
<img src="<%= graphURL %>" width="400" height="400" border="1"/>
</body>
</html>



matthew 2006-07-07 15:26 鍙戣〃璇勮
]]>
Jasperreport榪炵畫鎵撳嵃澶氫釜鎶ヨ〃妯℃澘錛嶅師鍒?/title><link>http://www.tkk7.com/matthew2006/archive/2006/07/01/56099.html</link><dc:creator>matthew</dc:creator><author>matthew</author><pubDate>Sat, 01 Jul 2006 08:52:00 GMT</pubDate><guid>http://www.tkk7.com/matthew2006/archive/2006/07/01/56099.html</guid><wfw:comment>http://www.tkk7.com/matthew2006/comments/56099.html</wfw:comment><comments>http://www.tkk7.com/matthew2006/archive/2006/07/01/56099.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/matthew2006/comments/commentRss/56099.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/matthew2006/services/trackbacks/56099.html</trackback:ping><description><![CDATA[Jasperreport榪炵畫鎵撳嵃澶氫釜鎶ヨ〃妯℃澘錛岃繖涓棶棰樹竴鐩村洶鎵版垜寰堜箙銆傜綉涓婃煡浜嗗緢澶氳祫鏂欓兘娌℃湁鍏蜂綋鐨勮В鍐沖姙娉曪紝閫氳繃鏌ヨjasperreport鐨凙PI鍙戠幇鎻愪緵浜嗚В鍐寵繖涓棶棰樼殑鏂規硶銆備互涓嬫槸鎴戠殑榪囩▼璁板綍錛?br /><br /><strong>闂鎻忚堪</strong>錛氫竴鑸姤琛ㄨ璁″拰鎵撳嵃涓紝涓昏鏄鍗曚釜鎶ヨ〃妯℃澘榪涜鏁版嵁濉厖銆佹墦鍗般佸鍑恒備絾鏄紝涔熸湁涓埆鎯呭喌闇瑕佽繛緇墦鍗板涓姤琛ㄦā鏉褲傛瘮濡傦紝鏀垮簻鏈哄叧鐨勪笂鎶ユ潗鏂欙紝灞炰簬涓涓畬鏁寸殑鏂囨。銆傚鏋滀竴涓竴涓ā鏉挎墦鍗頒細鏄懼緱闈炲父楹葷儲銆?br /><br /><strong>闂瑙e喅榪囩▼錛?/strong>涓鑸垜浠鍑烘姤琛ㄦ枃浠舵槸浣跨敤榪欎釜璇彞錛?br />exporter.setParamete(JRExporterParameter.JASPER_PRINT, jasperprint);浣嗘槸瀹冩槸瀵瑰崟涓ā鏉胯繘琛屾搷浣滐紝閫氳繃鏌ユ壘jasperreport鐨凙PI鍙戠幇榪樻彁渚涗簡榪欐牱涓涓鍙ワ細<br />exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperprint);鍙互榪炵畫瀵瑰涓姤琛ㄦā鏉挎搷浣溿傚畠鐨勬柟娉曟槸閫氳繃涓涓猯ist鏉ュ瓨鍌ㄥ涓狫asperPrint瀵硅薄錛屼粠鑰屽疄鐜板涓姤琛ㄦā鏉跨殑鎵撳嵃銆傚湪鎴戣В鍐抽棶棰樼殑榪囩▼涓彂鐜板鍑篜DF鏂囦歡鏍煎紡姣旇緝綆鍗曪紝浣嗘槸瀵煎嚭WORD鏂囨。鏃跺彂鐜扮紪鐮佹牸寮忓嚭鐜伴棶棰橈紝鑰佹槸鍑虹幇涔辯爜銆傚嵆浣胯繖鏍? exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "GB2312");涔熸病鏈夌敤銆傚悗鏉ユ祻瑙堜竴綃囪創瀛愶細鈥滃鍑篹xcel鏃跺嚭鐜頒貢鐮侀棶棰樷濓紝鍜屾垜鐨勯棶棰樺樊涓嶅銆傜粓浜庡ぇ鍔熷憡鎴愶紒<img src ="http://www.tkk7.com/matthew2006/aggbug/56099.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/matthew2006/" target="_blank">matthew</a> 2006-07-01 16:52 <a href="http://www.tkk7.com/matthew2006/archive/2006/07/01/56099.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>jasper report 浣跨敤 hibernate 鏁版嵁婧愭ц兘浼樺寲http://www.tkk7.com/matthew2006/archive/2006/06/29/55810.htmlmatthewmatthewThu, 29 Jun 2006 12:00:00 GMThttp://www.tkk7.com/matthew2006/archive/2006/06/29/55810.htmlhttp://www.tkk7.com/matthew2006/comments/55810.htmlhttp://www.tkk7.com/matthew2006/archive/2006/06/29/55810.html#Feedback0http://www.tkk7.com/matthew2006/comments/commentRss/55810.htmlhttp://www.tkk7.com/matthew2006/services/trackbacks/55810.html 錛堣漿璐達細Autohr John Ferguson Smart 錛?br />聽 聽 聽 娉? 浣跨敤浜?hibernate 鐨勫垎欏靛姛鑳斤紝瀵瑰ぇ鏁版嵁閲忔煡璇㈤噰鐢ㄥ垎孌佃鍏ユ柟娉曪紝閬垮厤浜嗕竴嬈¤鍏ュ甫鏉ョ殑鎬ц兘涓嬮檷錛屼竴鑸湪Tomcat 鐜涓嬶紝褰揕ist涓殑 Object > 10000 涓鑸細瀵艱嚧 OutOfMemory銆?br />

Introduction
In the article, we examine a performance-optimised approach for using Hibernate queries to generate reports with JasperReports.

聽 JasperReports is a powerful and flexible Open Source reporting tool. Combined with the graphical design tool iReport, for example, you get a complete Java Open Source reporting solution. In this article, we will investigate how you can integrate JasperReports reporting with Hibernate data sources in an optimal manner, without sacrificing ease-of-use or performance.

聽 Basic Hibernate/JasperReports integration
To integrate Hibernate and JasperReports, you have to define a JasperReports data source. One simple and intuitive approach is to use the JRBeanCollectionDataSource data source (This approach is presented here) :

-------------------------------------------------------------------------------------------------------
List results = session.find("from com.acme.Sale");

聽 Map parameters = new HashMap();
聽 parameters.put("Title", "Sales Report");

聽 InputStream reportStream
聽 聽 聽 聽 聽 聽 = this.class.getResourceAsStream("/sales-report.xml");
聽 JasperDesign jasperDesign = JasperManager.loadXmlDesign(reportStream);
聽 JasperReport jasperReport = JasperManager.compileReport(jasperDesign);

JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(results);
聽 JasperPrint jasperPrint = JasperManager.fillReport(jasperReport,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 parameters,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 ds);

聽 JasperExportManager.exportReportToPdfFile(jasperPrint, "sales-report.pdf");

------------------------------------------------------------------------------------------------------------

聽 This approach will work well for small lists. However, for reports involving tens or hundreds of thousands of lines, it is inefficiant, memory-consuming, and slow. Indeed, experience shows that, when running on a standard Tomcat configuration, a list returning as few as 10000 business objects can cause OutOfMemory exceptions. It also wastes time building a bulky list of objects before processing them, and pollutes the Hibernate session (and possibly second-level caches with temporary objects.

Optimised Hibernate/JasperReports integration
We need a way to efficiently read and process Hibernate queries, without creating too many unnecessary temporary objects in memory. One possible way to do this is the following :

Define an optimised layer for executing Hibernate queries efficiently
Define an abstraction layer for these classes which is compatible with JasperReports
Wrap this data access layer in a JasperReports class that can be directly plugged into JasperReports
The Hibernate Data Access Layer : The QueryProvider interface and its implementations
We start with the optimised Hibernate data access. (you may note that this layer is not actually Hibernate-specific, so other implementations could implement other types of data access without impacting the design).

This layer contains two principal classes :

The CriteriaSet class
The QueryProvider interface


聽 A CriteriaSet is simply a JavaBean which contains parameters which may be passed to the Hibernate query. It is simply a generic way of encapsulating a set of parameters. A QueryProvider provides a generic way of returning an arbitrary subset of the query results set. The essential point is that query results are read in small chunks, not all at once. This allows more efficient memory handling and better performance.


------------------------------------------------------------------------------------------------------------
/**
聽 * A QueryProvidor provides a generic way of fetching a set of objects.
聽 */
聽 public interface QueryProvider {

聽 聽 /**
聽 聽 聽 * Return a set of objects based on a given criteria set.
聽 聽 聽 * @param firstResult the first result to be returned
聽 聽 聽 * @param maxResults the maximum number of results to be returned
聽 聽 聽 * @return a list of objects
聽 聽 聽 */
聽 聽 List getObjects(CriteriaSet criteria,
聽 聽 聽 聽 聽 聽 聽 聽 int firstResult,
聽 聽 聽 聽 聽 聽 聽 聽 int maxResults) throws HibernateException;
聽 }
----------------------------------------------------------------------------------------------------------

聽 A typical implementation of this class simply builds a Hibernate query using the specified criteria set and returns the requested subset of results. For example :

-----------------------------------------------------------------------------------------------------------

public class ProductQueryProvider implements QueryProvider {

聽 聽 public List getObjects(CriteriaSet criteria,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 int firstResult,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 int maxResults)
聽 聽 聽 聽 聽 throws HibernateException {
聽 聽 聽 //
聽 聽 聽 // Build query criteria
聽 聽 聽 //
聽 聽 聽 Session sess = SessionManager.currentSession();
聽 聽 聽 ProductCriteriaSet productCriteria
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 = (ProductCriteriaSet) criteria;
聽 聽 聽 Query query = session.find("from com.acme.Product p "
聽 聽 聽 聽 聽 聽 聽 + "where p.categoryCode = :categoryCode ");

聽 聽 聽 query.setParameter("categoryCode",
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 productCriteria.getCategoryCode();
聽 聽 聽 return query.setCacheable(true)
聽 聽 聽 聽 聽 聽 聽 .setFirstResult(firstResult)
聽 聽 聽 聽 聽 聽 聽 .setMaxResults(maxResults)
聽 聽 聽 聽 聽 聽 聽 .setFetchSize(100)
聽 聽 聽 聽 聽 聽 聽 .list();
聽 聽 }
聽 }
-------------------------------------------------------------------------------------------------

聽 A more sophisticated implementation is helpful for dynamic queries. We define an abstract BaseQueryProvider class which can be used for dynamic query generation. This is typically useful when the report has to be generated using several parameters, some of which are optionnal.. Each derived class overrides the buildCriteria() method. This method builds a Hibernate Criteria object using the specified Criteria set as appropriate :

---------------------------------------------------------------------------------------------------

public abstract class BaseQueryProvider implements QueryProvider {

聽 聽 public List getObjects(CriteriaSet criteria, int firstResult, int maxResults)
聽 聽 聽 聽 聽 throws HibernateException {

聽 聽 聽 聽 聽 Session sess = SessionManager.currentSession();
聽 聽 聽 聽 聽 Criteria queryCriteria = buildCriteria(criteria, sess);
聽 聽 聽 聽 聽 return queryCriteria.setCacheable(true)
聽 聽 聽 聽 聽 聽 聽 聽 聽 .setFirstResult(firstResult)
聽 聽 聽 聽 聽 聽 聽 聽 聽 .setMaxResults(maxResults)
聽 聽 聽 聽 聽 聽 聽 聽 聽 .setFetchSize(100)
聽 聽 聽 聽 聽 聽 聽 聽 聽 .list();

聽 聽 }

聽 聽 protected abstract Criteria buildCriteria(CriteriaSet criteria, Session sess);
聽 }
-------------------------------------------------------------------------------------------------

A typical implementation is shown here :

--------------------------------------------------------------------------------------------------

public class SalesQueryProvider extends BaseQueryProvider {

聽 聽 protected Criteria buildCriteria(CriteriaSet criteria,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 Session sess) {
聽 聽 聽 //
聽 聽 聽 // Build query criteria
聽 聽 聽 //
聽 聽 聽 SalesCriteriaSet salesCriteria
聽 聽 聽 聽 聽 聽 聽 聽 聽 = (SalesCriteriaSet) criteria;

聽 聽 聽 Criteria queryCriteria
聽 聽 聽 聽 聽 聽 聽 聽 聽 = sess.createCriteria(Sale.class);

聽 聽 聽 if (salesCriteria.getStartDate() != null) {
聽 聽 聽 聽 聽 queryCriteria.add(
聽 聽 聽 聽 聽 聽 聽 Expression.eq("getStartDate",
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 salesCriteria.getStartDate()));
聽 聽 聽 }
聽 聽 聽 // etc...

聽 聽 聽 return queryCriteria;
聽 聽 }
聽 }
------------------------------------------------------------------------------------------------

聽 Note that a QueryProvider does not need to return Hibernate-persisted objects. Large-volume queries can sometimes be more efficiently implemented by returning custom-made JavaBeans containing just the required columns. HQL allows you to to this quite easily :

---------------------------------------------------------------------------------------------------
public class CityQueryProvider implements QueryProvider {

聽 聽 public List getObjects(CriteriaSet criteria,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 int firstResult,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 int maxResults)
聽 聽 聽 聽 聽 throws HibernateException {
聽 聽 聽 //
聽 聽 聽 // Build query criteria
聽 聽 聽 //
聽 聽 聽 Session sess = SessionManager.currentSession();
聽 聽 聽 Query query
聽 聽 聽 聽 聽 聽 = session.find(
聽 聽 聽 聽 聽 聽 聽 聽 "select new CityItem(city.id, "
聽 聽 聽 聽 聽 聽 聽 + " 聽 聽 聽 聽 聽 聽 city.name, "
聽 聽 聽 聽 聽 聽 聽 + " 聽 聽 聽 聽 city.electrityCompany.name) "
聽 聽 聽 聽 聽 聽 聽 + " from City city "
聽 聽 聽 聽 聽 聽 聽 + " left join city.electrityCompany");

聽 聽 聽 return query.setCacheable(true)
聽 聽 聽 聽 聽 聽 聽 .setFirstResult(firstResult)
聽 聽 聽 聽 聽 聽 聽 .setMaxResults(maxResults)
聽 聽 聽 聽 聽 聽 聽 .setFetchSize(100)
聽 聽 聽 聽 聽 聽 聽 .list();
聽 聽 }
聽 }
-------------------------------------------------------------------------------------------------

Hibernate data access abstraction : the ReportDataSource interface
Next, we define a level of abstraction between the Hibernate querying and the JasperReport classes. The ReportDataSource does this :

--------------------------------------------------------------------------------------------------
public interface ReportDataSource extends Serializable {
聽 聽 Object getObject(int index);
聽 }


--------------------------------------------------------------------------------------------------

聽 The standard implementation of this interface reads Hibernate objects using a given QueryProvider and returns them to JasperReports one by one. Here is the source code of this class (getters, setters, logging code and error-handling code have been removed for clarty) :

---------------------------------------------------------------------------------------------------
public class ReportDataSourceImpl implements ReportDataSource {

聽 聽 private CriteriaSet criteriaSet;
聽 聽 private QueryProvider queryProvider;
聽 聽 private List resultPage;
聽 聽 private int pageStart = Integer.MAX_VALUE;
聽 聽 private int pageEnd = Integer.MIN_VALUE;
聽 聽 private static final int PAGE_SIZE = 50;

聽 聽 //
聽 聽 // Getters and setters for criteriaSet and queryProvider
聽 聽 //
聽 聽 ...

聽 聽 public List getObjects(int firstResult,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 int maxResults) {

聽 聽 聽 聽 List queryResults = getQueryProvider()
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 .getObjects(getCriteriaSet(),
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 firstResult,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 maxResults);
聽 聽 聽 聽 if (resultPage == null) {
聽 聽 聽 聽 聽 resultPage = new ArrayList(queryResults.size());
聽 聽 聽 聽 }
聽 聽 聽 聽 resultPage.clear();
聽 聽 聽 聽 for(int i = 0; i < queryResults.size(); i++) {
聽 聽 聽 聽 聽 resultPage.add(queryResults.get(i));
聽 聽 聽 聽 }
聽 聽 聽 聽 pageStart = firstResult;
聽 聽 聽 聽 pageEnd = firstResult + queryResults.size() - 1;
聽 聽 聽 聽 return resultPage;
聽 聽 }
public final Object getObject(int index) {
聽 聽 聽 if ((resultPage == null)
聽 聽 聽 聽 聽 || (index < pageStart)
聽 聽 聽 聽 聽 || (index > pageEnd)) {
聽 聽 聽 聽 聽 resultPage = getObjects(index, PAGE_SIZE);
聽 聽 聽 }
聽 聽 聽 Object result = null;
聽 聽 聽 int pos = index - pageStart;
聽 聽 聽 if ((resultPage != null)
聽 聽 聽 聽 聽 && (resultPage.size() > pos)) {
聽 聽 聽 聽 聽 result = resultPage.get(pos);
聽 聽 聽 }
聽 聽 聽 return result;
聽 聽 }
聽 }

---------------------------------------------------------------------------------------------------

Finally, we have to be able to call the Hibernate data source from JasperReports. To do so, we start by looking at the JasperManager fillReport() method, which takes a JRDataSource object as its third parameter and uses it to generate the report :

---------------------------------------------------------------------------------------------------
JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, parameters, ds);

---------------------------------------------------------------------------------------------------


To implement our own optimised JRDataSource, we extended the JRAbstractBeanDataSource class. This class is presented here (logging and error-handling code has been removed for clarty).

---------------------------------------------------------------------------------------------------
public class ReportSource extends JRAbstractBeanDataSource {

聽 聽 private ReportDataSource dataSource;
聽 聽 protected int index = 0;
聽 聽 protected Object bean;
聽 聽 private static Map fieldNameMap = new HashMap();

聽 聽 public ReportSource(ReportDataSource dataSource) {
聽 聽 聽 super(true);
聽 聽 聽 this.dataSource = dataSource;
聽 聽 聽 index = 0;
聽 聽 }

聽 聽 public boolean next() throws JRException {
聽 聽 聽 bean = dataSource.getObject(index++);
聽 聽 聽 return (bean != null);
聽 聽 }

聽 聽 public void moveFirst() throws JRException {
聽 聽 聽 index = 0;
聽 聽 聽 bean = dataSource.getObject(index);
聽 聽 }

聽 聽 public Object getFieldValue(JRField field) throws JRException {
聽 聽 聽 String nameField = getFieldName(field.getName());
聽 聽 聽 return PropertyUtils.getProperty(bean, nameField);
聽 聽 }
/**
聽 聽 * Replace the character "_" by a ".".
聽 聽 *
聽 聽 * @param fieldName the name of the field
聽 聽 * @return the value in the cache or make
聽 聽 * the replacement and return this value
聽 聽 */
聽 聽 private String getFieldName(String fieldName) {
聽 聽 聽 String filteredFieldName
聽 聽 聽 聽 聽 = (String) fieldNameMap.get(fieldName);
聽 聽 聽 if (filteredFieldName == null) {
聽 聽 聽 聽 聽 filteredFieldName = fieldName.replace('_','.');
聽 聽 聽 聽 聽 fieldNameMap.put(fieldName,filteredFieldName);
聽 聽 聽 }
聽 聽 聽 return filteredFieldName;
聽 聽 }
聽 }

---------------------------------------------------------------------------------------------------

This class is basically just a proxy between JasperReports and the Hibernate data source object. The only tricky bit is field name handling. For some reason, JasperReports does not accept field names containing dots (ex. "product.code"). However, when you retrieve a set of Hibernate-persisted business objects, you often need to access object attributes. To get around this, we replace the "." by a "_" in the JasperReport template (ex. "product_code" instead of "product.code"), and convert back to a conventional JavaBean format in the getFieldName() method.

Putting it all together
So, when you put it all together, you get something like this :

---------------------------------------------------------------------------------------------------
List results = session.find("from com.acme.Sale");

聽 Map parameters = new HashMap();
聽 parameters.put("Title", "Sales Report");

聽 InputStream reportStream
聽 聽 聽 聽 聽 = this.class.getResourceAsStream("/sales-report.xml");
聽 JasperDesign jasperDesign
聽 聽 聽 聽 聽 = JasperManager.loadXmlDesign(reportStream);
聽 JasperReport jasperReport
聽 聽 聽 聽 聽 = JasperManager.compileReport(jasperDesign);

聽 ReportDataSource hibernateDataSource
聽 聽 聽 聽 聽 = new ReportDataSourceImpl();
聽 hibernateDataSource.setQueryProvider(new SalesQueryProvider());
聽 hibernateDataSource.setCriteriaSet(salesCriteria);
聽 ReportSource rs = new ReportSource(hibernateDataSource);

聽 JasperPrint jasperPrint
聽 聽 聽 聽 聽 聽 = JasperManager.fillReport(jasperReport,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 parameters,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 rs);
聽 JasperExportManager.exportReportTsoPdfFile(jasperPrint,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 "sales-report.pdf");

---------------------------------------------------------------------------------------------------

Further JasperReports optimisations

Compiled Report caching
In the previous code, the JasperReport is loaded and compiled before it is run. In a serverside application, for optimal performance, the reports should be loaded and compiled once and then cached. This will save several seconds on each query generation.

Optimising Hibernate Queries
The first cause of slow report generation is sub-optimal querying. Hibernate is a high-performance persistence library which gives excellent results when correctly used. So you should treate any report which takes an excessive time to generate as suspicious. Common Hibernate optimisation strategies include :

Correct use of joins
Correct use of lazy associations
Reading a subset of columns rather than whole Hibernate-persisted objects
Some Hibernate query optimisation techniques are discussed here.

Conclusion

JasperReports is a powerful and flexible reporting tool. To achieve high-performance Hibernate intergration however, some extra work is needed. One way is by writing optimised data access classes which can be plugged into the JasperReports architecture. Using this approach, you can take advantage of the full power of Hibernate in your JasperReports reporting solutions.



matthew 2006-06-29 20:00 鍙戣〃璇勮
]]>
jasper report 浣跨敤 hibernate 鏁版嵁婧?杞?hibernate 瀹樻柟緗戠珯鎻愪緵)http://www.tkk7.com/matthew2006/archive/2006/06/29/55808.htmlmatthewmatthewThu, 29 Jun 2006 11:58:00 GMThttp://www.tkk7.com/matthew2006/archive/2006/06/29/55808.htmlhttp://www.tkk7.com/matthew2006/comments/55808.htmlhttp://www.tkk7.com/matthew2006/archive/2006/06/29/55808.html#Feedback0http://www.tkk7.com/matthew2006/comments/commentRss/55808.htmlhttp://www.tkk7.com/matthew2006/services/trackbacks/55808.html 娉? 姝ゆ柟娉曚嬌鐢ㄧ畝鍗曪紝浣嗘槸娌℃湁鍒嗛〉璇誨彇鏁版嵁錛岄傚悎鏁版嵁閲忎笉澶ф儏鍐典笅鐨勬姤琛?br />
鍘熸枃錛?/font> http://www.hibernate.org/79.html

Using JasperReports with Hibernate
This section will demonstrate a couple of ways to use the results of a Hibernate query as the datasource of a report in JasperReports.

When the Hibernate query returns a simple collection of objects, The JRBeanCollectionDataSource class in the JasperReports library will work fine.

--------------------------------------------------------------------------------------------------------
List cats = session.find("from eg.Cat");

Map parameters = new HashMap();
parameters.put("Title", "The Cat Report");

InputStream reportStream = this.class.getResourceAsStream("/the-cat-report.xml");
JasperDesign jasperDesign = JasperManager.loadXmlDesign(reportStream);
JasperReport jasperReport = JasperManager.compileReport(jasperDesign);

JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(cats);
JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, parameters, ds);

JasperManager.printReportToPdfFile(jasperPrint, "the-cat-report.pdf");

--------------------------------------------------------------------------------------------------------

聽 However, when the Hibernate query returns tuples of objects (each tuple as an array, each array as an element in the returned List), things get a little tricky. Jasper needs a way to reference each object in the array by a field name. This class is a good solution, but at this time you are required to pass an array of field names matching the results of the query.

--------------------------------------------------------------------------------------------------------
public class HibernateQueryResultDataSource implements JRDataSource {

private String[] fields;
private Iterator iterator;
private Object currentValue;

public HibernateQueryResultDataSource(List list, String[] fields) {
聽 this.fields = fields;
聽 this.iterator = list.iterator();
}

public Object getFieldValue(JRField field) throws JRException {
聽 Object value = null;
聽 int index = getFieldIndex(field.getName());
聽 if (index > -1) {
聽 聽 Object[] values = (Object[])currentValue;
聽 聽 value = values[index];
聽 }
聽 return value;
}

public boolean next() throws JRException {
聽 currentValue = iterator.hasNext() ? iterator.next() : null;
聽 return (currentValue != null);
}

private int getFieldIndex(String field) {
聽 int index = -1;
聽 for (int i = 0; i < fields.length; i++) {
聽 聽 if (fields
.equals(field)) {
聽 聽 index = i;
聽 聽 break;
聽 聽 }
聽 }
聽 return index;
}

}

--------------------------------------------------------------------------------------------------------

Now running your report would look something like this:


--------------------------------------------------------------------------------------------------------
List cats = session.find("select cat.type, cat.birthdate, cat.name from eg.DomesticCat cat");

Map parameters = new HashMap();
parameters.put("Title", "The Cat Report");

InputStream reportStream = this.class.getResourceAsStream("/the-cat-report.xml");
JasperDesign jasperDesign = JasperManager.loadXmlDesign(reportStream);
JasperReport jasperReport = JasperManager.compileReport(jasperDesign);

String[] fields = new String[] { "type", "birthdate", "name"};
HibernateQueryResultDataSource ds = new HibernateQueryResultDataSource(cats, fields);
JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, parameters, ds);

JasperManager.printReportToPdfFile(jasperPrint, "the-cat-report.pdf");

--------------------------------------------------------------------------------------------------------


Another, alternate implementation, from Erik Romson:


--------------------------------------------------------------------------------------------------------
public class HibernateQueryResultDataSource implements JRDataSource
{
聽 private static final transient Logger logger =
聽 聽 Logger.Factory.getInstance(HibernateQueryResultDataSource.class);
聽 protected HashMap fieldsToIdxMap=new HashMap();
聽 protected Iterator iterator;
聽 protected Object currentValue;
聽 List values;

聽 public HibernateQueryResultDataSource(List list, String query)
聽 {
聽 聽 int start =query.indexOf("select ");
聽 聽 int stop =query.indexOf(" from ");
聽 聽 Assertion.assertTrue(
聽 聽 聽 (start!=-1) &&
聽 聽 聽 (stop!=-1),
聽 聽 聽 "The query "+
聽 聽 聽 query+
聽 聽 聽 " must be of the form select x,x from ..."
聽 聽 );
聽 聽 start+="select".length();
聽 聽 String parameters=query.substring(start,stop);
聽 聽 parameters=parameters.trim();
聽 聽 Assertion.assertTrue(
聽 聽 聽 聽 parameters.length()>0,
聽 聽 聽 聽 "The query "+
聽 聽 聽 聽 query+
聽 聽 聽 聽 " seems to be weird"
聽 聽 );
聽 聽 StringTokenizer tokenizer=new StringTokenizer(parameters,",");
聽 聽 int idx=0;
聽 聽 while( tokenizer.hasMoreTokens() )
聽 聽 {
聽 聽 聽 聽 String parameter=tokenizer.nextToken();
聽 聽 聽 聽 fieldsToIdxMap.put( parameter.trim(), new Integer(idx) );
聽 聽 聽 聽 idx++;
聽 聽 }
聽 聽 values=list;
聽 聽 this.iterator = list.iterator();
聽 }
public Object getFieldValue(JRField field) throws JRException
聽 {
聽 聽 String fieldName=field.getName().replace('_','.');
聽 聽 //JasperReports does not allow '.' in field names, so we
聽 聽 //use '_' for nested properties instead and must convert here
聽 聽 //(comment added by kbrown)
聽 聽 Integer idxInt=(Integer) fieldsToIdxMap.get(fieldName);
聽 聽 if (idxInt==null)
聽 聽 {
聽 聽 聽 聽 Assertion.fail(
聽 聽 聽 聽 聽 "The field \""+
聽 聽 聽 聽 聽 fieldName+
聽 聽 聽 聽 聽 "\" did not have an index mapping. Should be one off "+
聽 聽 聽 聽 聽 fieldsToIdxMap.keySet()
聽 聽 聽 聽 );
聽 聽 }
聽 聽 Object[] values = (Object[]) currentValue;
聽 聽 Assertion.assertTrue(
聽 聽 聽 聽 idxInt.intValue()
聽 聽 聽 聽 "The index from field "+
聽 聽 聽 聽 fieldName+
聽 聽 聽 聽 " was illegal"
聽 聽 );
聽 聽 Object value= values[ idxInt.intValue() ];
聽 聽 if ( logger.isDebugEnabled() )
聽 聽 {
聽 聽 聽 聽 logger.debug("fetched value "+value+" from field "+fieldName);
聽 聽 }
聽 聽 return value;
聽 }

聽 public boolean next() throws JRException
聽 {
聽 聽 currentValue = iterator.hasNext() ? iterator.next() : null;
聽 聽 return currentValue != null;
聽 }

聽 public List getValues()
聽 {
聽 聽 return values;
聽 }
}

--------------------------------------------------------------------------------------------------------

Using JasperReports with Hibernate
This section will demonstrate a couple of ways to use the results of a Hibernate query as the datasource of a report in JasperReports.

When the Hibernate query returns a simple collection of objects, The JRBeanCollectionDataSource class in the JasperReports library will work fine.

List cats = session.find("from eg.Cat");

Map parameters = new HashMap();
parameters.put("Title", "The Cat Report");

InputStream reportStream = this.class.getResourceAsStream("/the-cat-report.xml");
JasperDesign jasperDesign = JasperManager.loadXmlDesign(reportStream);
JasperReport jasperReport = JasperManager.compileReport(jasperDesign);

JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(cats);
JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, parameters, ds);

JasperManager.printReportToPdfFile(jasperPrint, "the-cat-report.pdf");
However, when the Hibernate query returns tuples of objects (each tuple as an array, each array as an element in the returned List), things get a little tricky. Jasper needs a way to reference each object in the array by a field name. This class is a good solution, but at this time you are required to pass an array of field names matching the results of the query.

public class HibernateQueryResultDataSource implements JRDataSource {

private String[] fields;
private Iterator iterator;
private Object currentValue;

public HibernateQueryResultDataSource(List list, String[] fields) {
聽 this.fields = fields;
聽 this.iterator = list.iterator();
}

public Object getFieldValue(JRField field) throws JRException {
聽 Object value = null;
聽 int index = getFieldIndex(field.getName());
聽 if (index > -1) {
聽 聽 Object[] values = (Object[])currentValue;
聽 聽 value = values[index];
聽 }
聽 return value;
}

public boolean next() throws JRException {
聽 currentValue = iterator.hasNext() ? iterator.next() : null;
聽 return (currentValue != null);
}

private int getFieldIndex(String field) {
聽 int index = -1;
聽 for (int i = 0; i < fields.length; i++) {
聽 聽 if (fields
.equals(field)) {
聽 聽 index = i;
聽 聽 break;
聽 聽 }
聽 }
聽 return index;
}

}
Now running your report would look something like this:

List cats = session.find("select cat.type, cat.birthdate, cat.name from eg.DomesticCat cat");

Map parameters = new HashMap();
parameters.put("Title", "The Cat Report");

InputStream reportStream = this.class.getResourceAsStream("/the-cat-report.xml");
JasperDesign jasperDesign = JasperManager.loadXmlDesign(reportStream);
JasperReport jasperReport = JasperManager.compileReport(jasperDesign);

String[] fields = new String[] { "type", "birthdate", "name"};
HibernateQueryResultDataSource ds = new HibernateQueryResultDataSource(cats, fields);
JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, parameters, ds);

JasperManager.printReportToPdfFile(jasperPrint, "the-cat-report.pdf");

--------------------------------------------------------------------------------

Another, alternate implementation, from Erik Romson:

public class HibernateQueryResultDataSource implements JRDataSource
{
聽 private static final transient Logger logger =
聽 聽 Logger.Factory.getInstance(HibernateQueryResultDataSource.class);
聽 protected HashMap fieldsToIdxMap=new HashMap();
聽 protected Iterator iterator;
聽 protected Object currentValue;
聽 List values;

聽 public HibernateQueryResultDataSource(List list, String query)
聽 {
聽 聽 int start =query.indexOf("select ");
聽 聽 int stop =query.indexOf(" from ");
聽 聽 Assertion.assertTrue(
聽 聽 聽 (start!=-1) &&
聽 聽 聽 (stop!=-1),
聽 聽 聽 "The query "+
聽 聽 聽 query+
聽 聽 聽 " must be of the form select x,x from ..."
聽 聽 );
聽 聽 start+="select".length();
聽 聽 String parameters=query.substring(start,stop);
聽 聽 parameters=parameters.trim();
聽 聽 Assertion.assertTrue(
聽 聽 聽 聽 parameters.length()>0,
聽 聽 聽 聽 "The query "+
聽 聽 聽 聽 query+
聽 聽 聽 聽 " seems to be weird"
聽 聽 );
聽 聽 StringTokenizer tokenizer=new StringTokenizer(parameters,",");
聽 聽 int idx=0;
聽 聽 while( tokenizer.hasMoreTokens() )
聽 聽 {
聽 聽 聽 聽 String parameter=tokenizer.nextToken();
聽 聽 聽 聽 fieldsToIdxMap.put( parameter.trim(), new Integer(idx) );
聽 聽 聽 聽 idx++;
聽 聽 }
聽 聽 values=list;
聽 聽 this.iterator = list.iterator();
聽 }

聽 public Object getFieldValue(JRField field) throws JRException
聽 {
聽 聽 String fieldName=field.getName().replace('_','.');
聽 聽 //JasperReports does not allow '.' in field names, so we
聽 聽 //use '_' for nested properties instead and must convert here
聽 聽 //(comment added by kbrown)
聽 聽 Integer idxInt=(Integer) fieldsToIdxMap.get(fieldName);
聽 聽 if (idxInt==null)
聽 聽 {
聽 聽 聽 聽 Assertion.fail(
聽 聽 聽 聽 聽 "The field \""+
聽 聽 聽 聽 聽 fieldName+
聽 聽 聽 聽 聽 "\" did not have an index mapping. Should be one off "+
聽 聽 聽 聽 聽 fieldsToIdxMap.keySet()
聽 聽 聽 聽 );
聽 聽 }
聽 聽 Object[] values = (Object[]) currentValue;
聽 聽 Assertion.assertTrue(
聽 聽 聽 聽 idxInt.intValue()
聽 聽 聽 聽 "The index from field "+
聽 聽 聽 聽 fieldName+
聽 聽 聽 聽 " was illegal"
聽 聽 );
聽 聽 Object value= values[ idxInt.intValue() ];
聽 聽 if ( logger.isDebugEnabled() )
聽 聽 {
聽 聽 聽 聽 logger.debug("fetched value "+value+" from field "+fieldName);
聽 聽 }
聽 聽 return value;
聽 }

聽 public boolean next() throws JRException
聽 {
聽 聽 currentValue = iterator.hasNext() ? iterator.next() : null;
聽 聽 return currentValue != null;
聽 }

聽 public List getValues()
聽 {
聽 聽 return values;
聽 }
}

--------------------------------------------------------------------------------

Using the information from this page I've made a patch to JasperReports 0.6.5. You can find the patch at:
http://www.waltermourao.com.br/JasperReports/jr65_hql.zip or you can download the full version from: http://www.waltermourao.com.br/JasperReports/jasperreports-hql-0.6.5.zip



matthew 2006-06-29 19:58 鍙戣〃璇勮
]]>
JasperReport 鐢ㄦ埛鎵嬪唽錛嶈漿璐?/title><link>http://www.tkk7.com/matthew2006/archive/2006/06/07/51021.html</link><dc:creator>matthew</dc:creator><author>matthew</author><pubDate>Wed, 07 Jun 2006 01:30:00 GMT</pubDate><guid>http://www.tkk7.com/matthew2006/archive/2006/06/07/51021.html</guid><wfw:comment>http://www.tkk7.com/matthew2006/comments/51021.html</wfw:comment><comments>http://www.tkk7.com/matthew2006/archive/2006/06/07/51021.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/matthew2006/comments/commentRss/51021.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/matthew2006/services/trackbacks/51021.html</trackback:ping><description><![CDATA[     鎽樿: JasperReport 鐢ㄦ埛鎵嬪唽鐨勭炕璇? 1 綆浠? 聽聽聽聽聽聽 JasperReport 鏄竴涓己澶с佺伒媧葷殑鎶ヨ〃鐢熸垚宸ュ叿錛岃兘澶熷睍紺轟赴瀵岀殑欏甸潰鍐呭...  <a href='http://www.tkk7.com/matthew2006/archive/2006/06/07/51021.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/matthew2006/aggbug/51021.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/matthew2006/" target="_blank">matthew</a> 2006-06-07 09:30 <a href="http://www.tkk7.com/matthew2006/archive/2006/06/07/51021.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>jasperreport+ireport鎶ヨ〃璁捐涓亣鍒扮殑闂http://www.tkk7.com/matthew2006/archive/2006/06/06/50879.htmlmatthewmatthewTue, 06 Jun 2006 11:43:00 GMThttp://www.tkk7.com/matthew2006/archive/2006/06/06/50879.htmlhttp://www.tkk7.com/matthew2006/comments/50879.htmlhttp://www.tkk7.com/matthew2006/archive/2006/06/06/50879.html#Feedback3http://www.tkk7.com/matthew2006/comments/commentRss/50879.htmlhttp://www.tkk7.com/matthew2006/services/trackbacks/50879.html闂1:鏈甯歌鐨勯棶棰樺氨鏄腑鏂囬棶棰橈紝涓嶈兘鏄劇ず涓枃鎴栬呮槸涔辯爜銆?br />瑙e喅鍔炴硶錛氬湪闇瑕佹樉紺轟腑鏂囩殑field閲岄潰(鍖呮嫭闈欐佺殑)璁劇疆PDF font name:STSong-Light,PDF encoding:UniGB-UCS2-H (Chinese Simplified)銆傚嵆鍙紒

闂2:璁捐闈欐佹姤琛ㄦā鏉挎椂錛寃ord杈撳嚭鏍煎紡闂錛岄瑙堟椂鎬繪槸絀虹櫧欏點?br />瑙e喅鍔炴硶錛氬彲浠ラ氳繃璁劇疆鎶ヨ〃灞炴т腑鐨勨滃綋娌℃湁鏁版嵁鏃剁殑鏄劇ず鏂瑰紡鈥濅負錛氶櫎detail澶栫殑鎵鏈夊湴鏂廣?br />
闂3:褰撹緭鍑篐TML鏍煎紡鎶ヨ〃鏃舵繪槸鍑虹幇絀虹櫧欏甸棶棰樸?br />瑙e喅鍔炴硶:鍘熷洜鏄垜鐢ㄧ殑jasperreport鐗堟湰鏄?.2.2,鍦ㄨ繖涓増鏈腑鍑虹幇涓涓皬bug錛屽氨鏄紪璇戣緭鍑虹殑html婧愪唬鐮佷負</title>錛孖E涓嶈兘緙栬瘧銆傚姙娉曟槸淇敼婧愮爜錛屾垨鑰呮墜宸ユ坊鍔犱唬鐮佹妸</title>鏀逛負<title></title>錛屾渶鍚庝篃鍙互鎶婁綘鐨刲ib鐩綍涓嬬殑jasperreport鐨刯ar鍖呯殑鐗堟湰鎹負1.2.1
....寰呯畫


matthew 2006-06-06 19:43 鍙戣〃璇勮
]]>
Ireport+Jasperreport鎶ヨ〃璁捐錛嶈漿璐?/title><link>http://www.tkk7.com/matthew2006/archive/2006/06/06/50873.html</link><dc:creator>matthew</dc:creator><author>matthew</author><pubDate>Tue, 06 Jun 2006 11:11:00 GMT</pubDate><guid>http://www.tkk7.com/matthew2006/archive/2006/06/06/50873.html</guid><wfw:comment>http://www.tkk7.com/matthew2006/comments/50873.html</wfw:comment><comments>http://www.tkk7.com/matthew2006/archive/2006/06/06/50873.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/matthew2006/comments/commentRss/50873.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/matthew2006/services/trackbacks/50873.html</trackback:ping><description><![CDATA[     鎽樿: 絎竴閮ㄥ垎錛氫嬌鐢╥Report鍒朵綔鎶ヨ〃鐨勮緇嗚繃紼嬶紙Windows鐜涓嬶級 1 銆佸墠璦 鍦ㄧ綉緇滀笂鍙互鎼滅儲鍒板緢澶氫嬌鐢? iReport 鍜? Jasperreport 閰嶅悎瀹炵幇鍚勭鎶ヨ〃浠誨姟鐨勬枃绔狅紝浣嗘槸鎴戣寰楀緢灝戞湁涓綃囷紙鍑犱箮娌℃湁錛夊仛涓涓瘮杈冭緇嗙殑浠嬬粛濡備綍浣跨敤...  <a href='http://www.tkk7.com/matthew2006/archive/2006/06/06/50873.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/matthew2006/aggbug/50873.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/matthew2006/" target="_blank">matthew</a> 2006-06-06 19:11 <a href="http://www.tkk7.com/matthew2006/archive/2006/06/06/50873.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鍏充簬Java鎶ヨ〃錛峧asperreporthttp://www.tkk7.com/matthew2006/archive/2006/06/06/50868.htmlmatthewmatthewTue, 06 Jun 2006 10:53:00 GMThttp://www.tkk7.com/matthew2006/archive/2006/06/06/50868.htmlhttp://www.tkk7.com/matthew2006/comments/50868.htmlhttp://www.tkk7.com/matthew2006/archive/2006/06/06/50868.html#Feedback0http://www.tkk7.com/matthew2006/comments/commentRss/50868.htmlhttp://www.tkk7.com/matthew2006/services/trackbacks/50868.html

matthew 2006-06-06 18:53 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 拍拍拍又黄又爽无挡视频免费| a在线视频免费观看在线视频三区 a毛片成人免费全部播放 | 亚洲国产91精品无码专区| 亚洲综合激情五月色一区| 99久久久精品免费观看国产| 亚洲精品456在线播放| 青青草a免费线观a| 亚洲色无码专区一区| 成年丰满熟妇午夜免费视频| 亚洲国产成人精品无码区花野真一 | 亚洲精品成人图区| 3d动漫精品啪啪一区二区免费| 亚洲天天做日日做天天欢毛片| 无码少妇精品一区二区免费动态| 亚洲成人动漫在线| 91麻豆最新在线人成免费观看| 亚洲精品国产日韩| 又粗又硬免费毛片| 久久99免费视频| 亚洲w码欧洲s码免费| 免费国产综合视频在线看 | 亚洲欧洲国产经精品香蕉网| 扒开双腿猛进入爽爽免费视频| 免费福利资源站在线视频| 亚洲国产一成人久久精品| 免费观看激色视频网站bd| 高潮毛片无遮挡高清免费视频| 亚洲人成人77777网站| 2019中文字幕在线电影免费| 亚洲一区二区三区在线观看网站| 免费一区二区视频| 四虎国产成人永久精品免费| 亚洲日韩精品无码专区加勒比☆| 亚洲线精品一区二区三区影音先锋 | 114一级毛片免费| 五月天国产成人AV免费观看| 亚洲日本在线观看| 亚洲AV无码乱码在线观看牲色| 久久免费动漫品精老司机| 亚洲国产成人久久精品大牛影视| 亚洲av无码国产精品夜色午夜|