gpt4 book ai didi

java - JFreeChart 饼图未在 RCP View 部分中展开

转载 作者:行者123 更新时间:2023-12-02 11:45:05 25 4
gpt4 key购买 nike

使用 GridLayout 时,JFreeChart 饼图不会扩展以填充复合面板。我正在尝试在 Eclipse Indigo 的 View 部分中使用它,但它似乎只有在 shell 中使用 FillLayout 时才有效...

public class SWTPieChart {  
public static void main(String[] args) {
JFreeChart chart = createChart(createDataset());
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(600, 400);
shell.setLayout(new FillLayout());
shell.setText("JFreeChart with GridLayout");

Composite panel = new Composite(shell, SWT.BORDER);
panel.setLayout(new GridLayout(1, true));
panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

final ChartComposite frame = new ChartComposite(panel, SWT.NONE, chart, true);
frame.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
}

private static PieDataset createDataset() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("One", new Double(43.2));
dataset.setValue("Two", new Double(10.0));
dataset.setValue("Three", new Double(27.5));
dataset.setValue("Four", new Double(17.5));
dataset.setValue("Five", new Double(11.0));
dataset.setValue("Six", new Double(19.4));
return dataset;
}

private static JFreeChart createChart(PieDataset dataset) {
JFreeChart chart = ChartFactory.createPieChart3D("3D Pie Chart", dataset, true, true, false);

PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setSectionOutlinesVisible(true);
plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
plot.setNoDataMessage("No data available");
plot.setCircular(true);
return chart;
}
}

最佳答案

您错误地将布局数据设置为组合(面板)而不是图表(框架)。

由于复合 Material 位于带有 FillLayout 的外壳内,因此不必设置任何布局数据。

图表位于带有 GridLayout 的组合内部,因此必须为其指定布局数据:

 Composite panel = new Composite(shell, SWT.BORDER);
panel.setLayout(new GridLayout(1, true));

final ChartComposite frame = new ChartComposite(panel, SWT.NONE, chart, true);
frame.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

关于java - JFreeChart 饼图未在 RCP View 部分中展开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48268585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com