eclipse SWT 中漂亮图表的库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:08:10  来源:igfitidea点击:

Libraries for pretty charts in SWT?

javaeclipsechartsswt

提问by Martin Klinke

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

我知道以下用于在 SWT/Eclipse RCP 应用程序中绘制图表的库:

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

还有哪些其他库可以用 SWT 绘制漂亮的图表?或者Java中的图表一般?毕竟,您始终可以显示图像...

采纳答案by Ryan P

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

我没有使用过 BIRT 或 JGraph,但是我在我的 SWT 应用程序中使用了 JFreeChart。我发现在 SWT 中使用 JFreeChart 的最佳方法是制作一个复合 AWT 框架并使用 JFreeChart 的 AWT 功能。这样做的方法是创建一个复合

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.

在跨平台实现方面存在几个问题,而且其中的 SWT 代码非常糟糕(在辩护中,吉尔伯特先生不太了解 SWT,它是为 AWT 编写的)。我的两个最大问题是当 AWT 事件通过 SWT 冒泡时,会触发一些错误的事件,并且由于包装 AWT 框架 JFreeChart 变得非常慢。

@zvikico

@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.

将图表放入网页的想法可能不是一个好方法。首先存在几个问题,即 Eclipse 处理在不同平台上集成 Web 浏览器的方式不一致。此外,根据我对一些用于 Web 的图形包的理解,它们是需要该设置的服务器端,包括我在内的许多公司也使用代理服务器,有时这会导致 Eclipse 网络浏览出现问题。

回答by Caleb Peterson

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 为折线图、散点图、条形图和面积图提供了良好的结果。API 很简单,网站上有很多示例。我从在谷歌上找到它在不到一个小时的时间内查看了我的数据。

SWTChart

SWT图表

回答by jkschneider

You might like thisone too

你可能会喜欢一个太

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

它能够使用您自己的数据提供者绘制实时数据。

enter image description here

在此处输入图片说明

回答by vambo

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.

我也在寻找 Eclipse RCP 应用程序的图表库,偶然发现了 Caleb 的帖子,现在我自己绝对可以推荐 SWTChart。对我来说,它比 JFreeChart 快得多,而且易于扩展。如果我真的不得不抱怨某些事情,我会说 javadoc 可能会更冗长,但这只是说其他一切都很棒。

回答by Matti Lyra

The one I've used are JChart2Dand 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和 JFreeChart。我在夏天做了一个实时绘图仪应用程序,并为此使用了 JFreeChart。启动该项目的人使用过 JChart2D,但我发现它没有足够的选项来调整图表的外观和感觉。

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.

JChart2D 应该非常快,所以如果您需要进行实时绘图,请查看它,尽管 JFreeChart 每秒绘制几次绘图没有任何问题。

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

java2s.com上还有相当多的图表库列表

回答by Martin

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

我建议您尝试jzy3d,这是一个用于绘制 3d 数据的简单 Java 库。它适用于 Java、AWT、Swing 或 SWT。

回答by Stefan

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.

在评估了几个选项后,我决定使用 JavaScript 库在我的 Eclipse 插件中显示绘图。正如 zvikico 已经建议的那样,可以在浏览器中显示 html 页面。在 html 页面中,您可以使用 JavaScript 库之一来进行实际绘图。如果您使用 Chartist,您可以从上下文菜单中将图像另存为 SVG 文件。

Some JavaScript charting libraries:

一些 JavaScript 图表库:

Chartist Example image:

图表示例图像

enter image description here

在此处输入图片说明

Example java code:

示例Java代码

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:

示例 html 页面

<!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

为了让这个工作,chartist.js 和 chartist.min.css 需要下载并放在与 html 文件相同的位置。您也可以从网络中包含它们。请参见此处的另一个示例:https: //www.snip2code.com/Snippet/233633/Chartist-js-example

Edit

编辑

I created a java wrapper for D3.js, see

我为 D3.js 创建了一个 java 包装器,请参阅

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

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

回答by Tibi

There's also ILOG JViews Chartswhich looks pretty feature-complete… if you can afford it. Hereis some additional infos on using it with eclipse.

还有ILOG JViews Charts,它看起来功能齐全……如果您负担得起的话。 这里有一些关于在 eclipse 中使用它的附加信息。

回答by Chris Dail

JChartsis 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.

JCharts是另一种选择。它类似于 JFreeChart,但文档是免费的。它不直接支持 SWT,但您始终可以生成图像并将其嵌入 SWT 框架中。

回答by FreeMemory

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.

还有 JGraph,但我不确定它是否仅适用于图形(即节点和边),或者它是否也适用于图表。