基于SWT的Java圖表類庫SWTChart

jopen 10年前發布 | 30K 次閱讀 SWTChart 圖表/報表制作

SWTChart是一款基于SWT的Java圖表類庫,也正因為是基于SWT的緣故,SWTChart應用起來非常方便,而且也相當輕巧。

SWTChart支持多種圖表類型,包括:線圖 、散點圖 、堆棧圖 、對數標度 、分類軸 、多軸 、柱形圖 、面積圖 、步驟圖 、軸取向 、系列標簽等。

swtchart.png

高可擴展性

所有SWTChart小部件是基于SWT的,這樣就可以輕松實現窗口小部件,也可以很容易地擴展功能。作為SWTChart一個例 子,SWTChart Extension與SWTChart捆綁在一起,這樣你就可以得到一些想法如何擴展它。 SWTChart Extension有鼠標縮放,或者用方向鍵翻頁的功能。當然,除了一些公共的API外,我們也可以直接定制SWTChart,因為SWTChart是完 全開源的。

高性能

SWTChart提供處理一系列大數據的能力。即使出百萬個數據點,重新繪制或調整圖表面板并不需要很長一段時間。內部算法不是簡單地以一定時間間隔采樣數據,而是根據當前屏幕分辨率來計算需要顯示多少個點。因此,即使有在大量的數據點,也不會再屏幕上不顯示。

輕量級

SWTChart具有輕量級的基本特點。 SWTChart jar文件的文件大小約為180KB,包括源代碼。這很容易讓你發布你的應用程序。

使用方法

SWTChart繪制線形圖

// create a chart
Chart chart = new Chart(composite, SWT.NONE);

// set titles chart.getTitle().setText("Line Chart Example"); chart.getAxisSet().getXAxis(0).getTitle().setText("Data Points"); chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");

// create line series ILineSeries lineSeries = (ILineSeries) chart.getSeriesSet() .createSeries(SeriesType.LINE, "line series"); lineSeries.setYSeries(ySeries);

// adjust the axis range chart.getAxisSet().adjustRange();</pre>

SWTChart繪制柱形圖:

// create a chart
Chart chart = new Chart(composite, SWT.NONE);

// set titles chart.getTitle().setText("Bar Chart Example"); chart.getAxisSet().getXAxis(0).getTitle().setText("Data Points"); chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");

// create bar series IBarSeries barSeries = (IBarSeries) chart.getSeriesSet() .createSeries(SeriesType.BAR, "bar series"); barSeries.setYSeries(ySeries);

// adjust the axis range chart.getAxisSet().adjustRange();</pre>

SWTChart繪制堆棧圖:

// create a chart
Chart chart = new Chart(composite, SWT.NONE);

// set titles chart.getTitle().setText("Stack Series Example"); chart.getAxisSet().getXAxis(0).getTitle().setText("Month"); chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");

// set category chart.getAxisSet().getXAxis(0).enableCategory(true); chart.getAxisSet().getXAxis(0).setCategorySeries( new String[] { "Jan", "Feb", "Mar", "Apr", "May" });

// create bar series IBarSeries barSeries1 = (IBarSeries) chart.getSeriesSet().createSeries( SeriesType.BAR, "bar series 1"); barSeries1.setYSeries(ySeries1); barSeries1.setBarColor(Display.getDefault().getSystemColor( SWT.COLOR_GREEN));

IBarSeries barSeries2 = (IBarSeries) chart.getSeriesSet().createSeries( SeriesType.BAR, "bar series 2"); barSeries2.setYSeries(ySeries2);

// enable stack series barSeries1.enableStack(true); barSeries2.enableStack(true);

// adjust the axis range chart.getAxisSet().adjustRange();</pre>

SWTChart還可以繪制更多的圖表類型,具體可以閱讀SWTChart的官方文檔,可以在文末的鏈接中獲取。

本文鏈接:http://www.codeceo.com/article/swt-java-swtchart.html
 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!