JAVA SWTchart 更改 Y 轴符号而不更改图形的其余部分

标签 java swt swtchart

我正在使用 JAVA、SWT 和 SWTChart 来可视化潜水资料。为了以正确的形状可视化潜水剖面,我使用负深度值,这是必要的但不正确。因此我想删除或反转 y 轴标题处的符号。

这是一个例子:

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.swtchart.Chart;
import org.swtchart.ILineSeries;
import org.swtchart.LineStyle;
import org.swtchart.ISeries.SeriesType;
/**
* An example for line chart.
*/
public class ScatterChartExample {
private static final double[] xSeries = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
private static final double[] ySeries = { 0, -1.3, -2.0, -3.9, -5.6, -4.1, -5.3, -7.0, -3.9, -3.6, -1.1, 0};
/**
* The main method.
*
* @param args
* the arguments
*/
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Dive Profile");
shell.setSize(500, 400);
shell.setLayout(new FillLayout());
createChart(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
/**
* create the chart.
*
* @param parent
* The parent composite
* @return The created chart
*/
static public Chart createChart(Composite parent) {
// create a chart
Chart chart = new Chart(parent, SWT.NONE);
// set titles
chart.getTitle().setText("Dive profile");
chart.getAxisSet().getXAxis(0).getTitle().setText("Time");
chart.getAxisSet().getYAxis(0).getTitle().setText("Depth");
// create scatter series
ILineSeries series = (ILineSeries) chart.getSeriesSet()
.createSeries(SeriesType.LINE, "series");
series.setLineStyle(LineStyle.SOLID);
series.enableArea(true);
series.setXSeries(xSeries);
series.setYSeries(ySeries);
// adjust the axis range
chart.getAxisSet().adjustRange();
return chart;
}
}

有什么想法吗???

问候

最佳答案

好的,这是一个使用字体“Arial”的修改版本的解决方案。我刚刚删除了“-”字符。

这是代码:

private static final double[] xSeries = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
private static final double[] ySeries = { 0, -1.3, -2.0, -3.9, -5.6, -4.1, -5.3, -7.0, -3.9, -3.6, -1.1, 0 };

private static Font           font;

/**
 * The main method.
 *
 * @param args
 *            the arguments
 */
public static void main(String[] args)
{
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Dive Profile");
    shell.setSize(500, 400);
    shell.setLayout(new FillLayout());

    display.loadFont("baz.ttf");

    font = new Font(display, "Baz", 12, SWT.NONE);

    createChart(shell);

    shell.open();
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
        {
            display.sleep();
        }
    }
    display.dispose();

    font.dispose();
}

/**
 * create the chart.
 *
 * @param parent
 *            The parent composite
 * @return The created chart
 */
static public Chart createChart(Composite parent)
{
    // create a chart
    Chart chart = new Chart(parent, SWT.NONE);
    // set titles
    chart.getTitle().setText("Dive profile");
    chart.getAxisSet().getXAxis(0).getTitle().setText("Time");
    chart.getAxisSet().getYAxis(0).getTitle().setText("Depth");
    chart.getAxisSet().getYAxis(0).getTick().setFont(font);
    chart.getAxisSet().getXAxis(0).getTick().setFont(font);
    // create scatter series
    ILineSeries series = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "series");
    series.setLineStyle(LineStyle.SOLID);
    series.enableArea(true);
    series.setXSeries(xSeries);
    series.setYSeries(ySeries);
    // adjust the axis range
    chart.getAxisSet().adjustRange();
    return chart;
}

这是字体(如果需要,您可以创建自己的字体):

https://dl.dropboxusercontent.com/u/498403/baz.ttf

看起来像这样:

enter image description here

<小时/>

更新

作为替代方案,您始终可以通过 ChartComposite 在 SWT 中使用 JFreeChart。 Her是一个教程。

关于JAVA SWTchart 更改 Y 轴符号而不更改图形的其余部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25386103/

相关文章:

Java 8 嵌套流 : return a value in last stream

java - SWT Java : how to change colour of text in Label control?

swt - SWT 列表小部件的垂直滚动条

java - swt 标签顶部有额外空间(边框内)

java - swtchart 不显示在对话框中

javascript - 如何使用ajax和Stringify在java中解码json输入

java - 如何检查某人是否在 tic tac toe gui 游戏中获胜? (java)

java - 使用 Jackson JSON 反序列化和嵌套类?