基于SWT的Java图表类库SWTChart

jopen 9年前

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();

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();

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();

SWTChart还可以绘制更多的图表类型,具体可以阅读SWTChart的官方文档,可以在文末的链接中获取。