Libraries for pretty charts in SWT? [closed]
Asked Answered
B

11

18

I know the following libraries for drawing charts in an SWT/Eclipse RCP application:

Which other libraries are there for drawing pretty charts with SWT? Or charts in Java generally? After all, you can always display an image...

Bridgeport answered 22/8, 2008 at 16:39 Comment(0)
K
11

I have not used BIRT or JGraph, however I use JFreeChart in my SWT application. I have found the best way to use JFreeChart in SWT is by making a composite an AWT frame and using the AWT functionality for JFreeChart. The way to do this is by creating a composite

Composite comp = new Composite(parent, SWT.NONE | SWT.EMBEDDED);
Frame frame = SWT_AWT.new_Frame(comp);
JFreeChart chart = createChart();
ChartPanel chartPanel = new ChartPanel(chart);
frame.add(chartPanel);

There are several problems in regards to implementations across different platforms as well as the SWT code in it is very poor (in its defense Mr. Gilbert does not know SWT well and it is made for AWT). My two biggest problems are as AWT events bubble up through SWT there are some erroneous events fired and due to wrapping the AWT frame JFreeChart becomes substantially slower.

@zvikico

The idea of putting the chart into a web page is probably not a great way to go. There are a few problems first being how Eclipse handles integrating the web browser on different platforms is inconsistent. Also from my understanding of a few graphing packages for the web they are server side requiring that setup, also many companies including mine use proxy servers and sometimes this creates issues with the Eclipse web browsing.

Kile answered 4/9, 2008 at 2:59 Comment(2)
FYI, JFreeChart has got experimental SWT integration. We use it successfully in a production application.Bridgeport
Unfortunately the LGPL license of JFreeChart is not compatible to the Eclipse Public License (EPL).Rubberneck
S
9

SWTChart gives good results for line, scatter, bar, and area charts. The API is straight forward and there are numerous examples on the website. I went from finding it on google to viewing my data in less than an hour.

SWTChart

Spanishamerican answered 20/1, 2010 at 15:21 Comment(4)
How does SWTChart go with charting real-time data? From what I can tell, a data series is loaded into the chart in its entirety, and there's isn't a way to update it with new values as they become available. I guess this just concerns me performance-wise.Iroquois
SWTChart is licensed under EPL.Rubberneck
It does not seem to support svg or png export.Rubberneck
Stefan, you can save the result to an image by using the class made by David L. Moffett: #32356156Bullyrag
C
6

You might like this one too

It has the ability to plot real time data with your own data provider.

enter image description here

Colene answered 7/1, 2012 at 16:57 Comment(1)
It is now part of the Nebula Visualization Widgets which are licensed under EPL and the getting started page is here: git.eclipse.org/c/nebula/org.eclipse.nebula.git/plain/widgets/…Rubberneck
W
2

The one I've used are JChart2D and JFreeChart. I did a live plotter application over the summer and used JFreeChart for that. The guy who had started the project had used JChart2D but I found that it doesn't have enough options for tweaking the chart look and feel.

JChart2D is supposed to be very fast so if you need to do live plotting have a look at it, although JFreeChart didn't have any problems doing a plot a few times per second.

There also quite a list of charting libraries on java2s.com

Walloping answered 20/1, 2010 at 15:31 Comment(1)
Both JChart2D and JFreeChart are licensed under LGPL.Rubberneck
C
2

I was also looking for a charting library for an Eclipse RCP app, stumbled on Caleb's post here and can definitely recommend SWTChart now myself. It is a lot faster than JFreeChart for me, plus easily extensible. If I would really have to complain about something, I'd say the javadoc could be a bit more verbose, but this is just to say everything else is great.

Christianachristiane answered 2/2, 2012 at 22:29 Comment(0)
L
1

There’s also ILOG JViews Charts which looks pretty feature-complete… if you can afford it. Here is some additional infos on using it with eclipse.

Lorna answered 5/9, 2008 at 13:53 Comment(1)
JViews has been bought by RogueWave: roguewave.com/products/visualization/jviews/whats-newRubberneck
Y
1

I suggest you try jzy3d, a simple java library for plotting 3d data. It's for java, on AWT, Swing or SWT.

Yevetteyew answered 8/7, 2010 at 17:37 Comment(1)
Jz3d is licensed under BSD.Rubberneck
R
1

After evaluationg several options I decided to use a JavaScript library for showing plots in my Eclipse Plugin. As zvikico already suggested it is possible to show a html page in a browser. In the html page you can utilize one of the JavaScript libraries to do the actual plotting. If you use Chartist you can save the image as SVG file from the context menu.

Some JavaScript charting libraries:

Chartist Example image:

enter image description here

Example java code:

package org.treez.results.chartist;

import java.net.URL;

import javafx.application.Application;
import javafx.concurrent.Worker;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import netscape.javascript.JSObject;

public class WebViewSample extends Application {

    private Scene scene;

    @Override
    public void start(Stage stage) {
        // create the scene
        stage.setTitle("Web View");
        Browser browser = new Browser();
        scene = new Scene(browser, 750, 500, Color.web("#666970"));
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

class Browser extends Region {

    final WebView browser = new WebView();

    final WebEngine webEngine = browser.getEngine();

    public Browser() {

        //add the web view to the scene
        getChildren().add(browser);

        //add finished listener
        webEngine.getLoadWorker().stateProperty().addListener((obs, oldState, newState) -> {
            if (newState == Worker.State.SUCCEEDED) {
                executeJavaScript();
            }
        });

        // load the web page
        URL url = WebViewSample.class.getResource("chartist.html");
        String urlPath = url.toExternalForm();
        webEngine.load(urlPath);

    }

    private void executeJavaScript() {

        String script = "var chartist = new Chartist.Line(" + "'#chart'," + " " + "{"
                + " labels: [1, 2, 3, 4, 5, 6, 7, 8]," + "series: [" + " [5, 9, 7, 8, 5, 3, 5, 44]" + "]" + "}, " + ""
                + "{" + "  low: 0," + "  showArea: true" + "}" + "" + ");" + " var get = function(){return chartist};";

        webEngine.executeScript(script);

        Object resultJs = webEngine.executeScript("get()");

        //get line
        JSObject line = (JSObject) resultJs;
        String getKeys = "{var keys = [];for (var key in this) {keys.push(key);} keys;}";
        JSObject linekeys = (JSObject) line.eval(getKeys);

        JSObject options = (JSObject) line.eval("this.options");
        JSObject optionkeys = (JSObject) options.eval(getKeys);

        options.eval("this.showLine=false");

    }

    @Override
    protected void layoutChildren() {
        double w = getWidth();
        double h = getHeight();
        layoutInArea(browser, 0, 0, w, h, 0, HPos.CENTER, VPos.CENTER);
    }

    @Override
    protected double computePrefWidth(double height) {
        return 750;
    }

    @Override
    protected double computePrefHeight(double width) {
        return 500;
    }
}

Example html page:

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="chartist.min.css">       
</head>
<body>
    <div class="ct-chart" id="chart"></div>
    <script type="text/javascript" src="chartist.js"></script>
</body>
</html>

In order to get this working, chartist.js and chartist.min.css need to be downloaded and put at the same location as the html file. You could also include them from the web. See here for another example: https://www.snip2code.com/Snippet/233633/Chartist-js-example

Edit

I created a java wrapper for D3.js, see

https://github.com/stefaneidelloth/javafx-d3

Rubberneck answered 17/8, 2015 at 11:52 Comment(0)
T
0

There's also JGraph, but I'm not sure if that's only for graphs (i.e. nodes and edges), or if it does charts also.

Tenpins answered 22/8, 2008 at 16:46 Comment(0)
P
0

Here's something different: it's very to embed web pages in SWT views. I recently tried it and it works very well. You can see where this is going: there are plenty of beautiful charting components for HTML, it could be an option. Just make sure the component is client-side only (unless you want to start a server).

I haven't tested Flash, but I'm pretty sure you can get it to work (naturally, this means your software will require Flash plug-in installed).

Parental answered 25/8, 2008 at 12:13 Comment(0)
A
0

JCharts is another option. It is similar to JFreeChart but the documentation is free. It does not have direct support for SWT but you can always generate an image and embed it in an SWT frame.

Abbacy answered 7/9, 2008 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.