我發現SWTChart library,只是想知道如何得到一個散點圖,點有不同的顏色和大小,就像這個example一樣。散點圖與不同的點顏色和大小
example http://matplotlib.org/_images/scatter_demo2.png
package org.swtchart.examples;
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 scatter chart.
*/
public class ScatterChartExample {
private static final double[] xSeries = { 0.0, 2.6, 6.5, 4.4, 5.6, 4.3,
3.4, 10.8, 2.1, 8.9 };
private static final double[] ySeries = { 1.3, 0.0, 3.9, 2.6, 1.1, 0.6,
3.1, 3.5, 5.6, 4.4 };
/**
* The main method.
*
* @param args
* the arguments
*/
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Scatter Chart");
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("Scatter Chart");
chart.getAxisSet().getXAxis(0).getTitle().setText("Score A");
chart.getAxisSet().getYAxis(0).getTitle().setText("Score B");
// create scatter series
ILineSeries scatterSeries = (ILineSeries) chart.getSeriesSet()
.createSeries(SeriesType.LINE, "scatter series");
scatterSeries.setLineStyle(LineStyle.NONE);
scatterSeries.setXSeries(xSeries);
scatterSeries.setYSeries(ySeries);
// adjust the axis range
chart.getAxisSet().adjustRange();
return chart;
}
}
怎麼可能得到一個散點圖,其中分有不同的顏色和大小?
預先感謝您。
我想我只是第一次嘗試從LineSeries這個簡單的代碼
package org.swtchart.examples;
import org.swtchart.Chart;
import org.swtchart.internal.series.LineSeries;
public class ILineSeriesTest extends LineSeries{
protected ILineSeriesTest(Chart chart, String id) {
super(chart, id);
}
}
在示例代碼繼承我把它改爲:
ILineSeriesTest scatterSeries = (ILineSeriesTest) chart.getSeriesSet()
.createSeries(SeriesType.LINE, "scatter series");
但是,我得到了以下錯誤:
Exception in thread "main" java.lang.ClassCastException: org.swtchart.internal.series.LineSeries cannot be cast to org.swtchart.examples.ILineSeriesTest
at org.swtchart.examples.ScatterChartExampleTest.createChart(ScatterChartExampleTest.java:67)
at org.swtchart.examples.ScatterChartExampleTest.main(ScatterChartExampleTest.java:38)
爲什麼它沒有解決?
預先感謝您。
另外考慮['XYBubbleRenderer'](http://www.jfree.org/jfreechart/api/javadoc/org /jfree/chart/renderer/xy/XYBubbleRenderer.html)。 – trashgod
@trashgod OP正在使用SWTChart,而不是JFreeChart。 – Baz