📄 symbolicyplotdemo.java
字号:
// subplot2.setSeriesPaint(0, Color.green);
XYPlot subplot3 = new XYPlot(series3, valueAxis1, null, renderer);
// subplot3.setSeriesPaint(0, Color.yellow);
XYPlot subplot4 = new XYPlot(series4, valueAxis2, null, renderer);
// subplot4.setSeriesPaint(0, Color.gray);
XYPlot subplot5 = new XYPlot(series5, valueAxis2, null, renderer);
// subplot5.setSeriesPaint(0, Color.orange);
XYPlot subplot6 = new XYPlot(series6, valueAxis2, null, renderer);
// subplot6.setSeriesPaint(0, Color.magenta);
XYPlot subplot7 = new XYPlot(series7, valueAxis2, null, renderer);
// subplot7.setSeriesPaint(0, Color.cyan);
mainPlot.add(subplot0, 1);
mainPlot.add(subplot1, 1);
mainPlot.add(subplot2, 1);
mainPlot.add(subplot3, 1);
mainPlot.add(subplot4, 1);
mainPlot.add(subplot5, 1);
mainPlot.add(subplot6, 1);
mainPlot.add(subplot7, 1);
// make the top level JFreeChart object
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, mainPlot, true);
// then customise it a little...
chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));
// and present it in a frame...
JFrame ySymbolicFrame = new ChartFrame(frameTitle, chart);
ySymbolicFrame.pack();
RefineryUtilities.positionFrameRandomly(ySymbolicFrame);
ySymbolicFrame.show();
}
/**
* Displays a vertically combined symbolic plot.
*
* @param frameTitle the frame title.
* @param data1 dataset 1.
* @param data2 dataset 2.
*/
private static void displayYSymbolicCombinedVertically(String frameTitle,
SampleYSymbolicDataset data1,
SampleYSymbolicDataset data2) {
String title = "Animals Vertically Combined";
String xAxisLabel = "Miles";
String yAxisLabel = null;
// create master dataset...
CombinedDataset data = new CombinedDataset();
data.add(data1);
data.add(data2);
// decompose data...
XYDataset series0 = new SubSeriesDataset(data, 0);
XYDataset series1 = new SubSeriesDataset(data, 1);
XYDataset series2 = new SubSeriesDataset(data, 2);
XYDataset series3 = new SubSeriesDataset(data, 3);
XYDataset series4 = new SubSeriesDataset(data, 4);
XYDataset series5 = new SubSeriesDataset(data, 5);
XYDataset series6 = new SubSeriesDataset(data, 6);
XYDataset series7 = new SubSeriesDataset(data, 7);
// common horizontal and vertical axes
ValueAxis valueAxis = new NumberAxis(xAxisLabel);
SymbolicAxis symbolicAxis1
= new SymbolicAxis(yAxisLabel, ((YisSymbolic) data1).getYSymbolicValues());
SymbolicAxis symbolicAxis2
= new SymbolicAxis(yAxisLabel, ((YisSymbolic) data2).getYSymbolicValues());
// create the main plot...
CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(valueAxis);
// and the sub-plots...
XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
XYPlot subplot0 = new XYPlot(series0, null, symbolicAxis1, renderer);
// subplot0.setSeriesPaint(0, Color.red);
XYPlot subplot1 = new XYPlot(series1, null, symbolicAxis1, renderer);
// subplot1.setSeriesPaint(0, Color.blue);
XYPlot subplot2 = new XYPlot(series2, null, symbolicAxis1, renderer);
// subplot2.setSeriesPaint(0, Color.green);
XYPlot subplot3 = new XYPlot(series3, null, symbolicAxis1, renderer);
// subplot3.setSeriesPaint(0, Color.yellow);
XYPlot subplot4 = new XYPlot(series4, null, symbolicAxis2, renderer);
// subplot4.setSeriesPaint(0, Color.gray);
XYPlot subplot5 = new XYPlot(series5, null, symbolicAxis2, renderer);
// subplot5.setSeriesPaint(0, Color.orange);
XYPlot subplot6 = new XYPlot(series6, null, symbolicAxis2, renderer);
// subplot6.setSeriesPaint(0, Color.magenta);
XYPlot subplot7 = new XYPlot(series7, null, symbolicAxis2, renderer);
// subplot7.setSeriesPaint(0, Color.cyan);
// add the subplots to the main plot...
mainPlot.add(subplot0, 1);
mainPlot.add(subplot1, 1);
mainPlot.add(subplot2, 1);
mainPlot.add(subplot3, 1);
mainPlot.add(subplot4, 1);
mainPlot.add(subplot5, 1);
mainPlot.add(subplot6, 1);
mainPlot.add(subplot7, 1);
// construct the chart...
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, mainPlot, true);
chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));
// and present it in a frame...
JFrame frame = new ChartFrame(frameTitle, chart);
frame.pack();
RefineryUtilities.positionFrameRandomly(frame);
frame.show();
}
/**
* Creates a XY graph with symbolic value on Y axis.
*
* @param title the chart title.
* @param xAxisLabel the x-axis label.
* @param yAxisLabel the y-axis label.
* @param data the data.
* @param legend a flag controlling whether or not the legend is created for the chart.
*
* @return the chart.
*/
public static JFreeChart createYSymbolicPlot(String title, String xAxisLabel,
String yAxisLabel, XYDataset data,
boolean legend) {
ValueAxis valueAxis = new NumberAxis(xAxisLabel);
SymbolicAxis symbolicAxis
= new SymbolicAxis(yAxisLabel, ((YisSymbolic) data).getYSymbolicValues());
XYPlot plot = new XYPlot(data, valueAxis, symbolicAxis, null);
XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES,
new SymbolicXYToolTipGenerator());
plot.setRenderer(renderer);
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
/**
* Creates a sample symbolic dataset.
*
* @return the dataset.
*/
public static SampleYSymbolicDataset createYSymbolicSample1() {
String[] sData = {"Lion", "Elephant", "Monkey", "Hippopotamus", "Giraffe"};
SampleYSymbolicDataset data
= new SampleYSymbolicDataset("AY Sample", 20, sData, 4, 20,
new String[] {"A Fall", "A Spring", "A Summer", "A Winter"});
return data;
}
/**
* Creates a sample symbolic dataset.
*
* @return The dataset.
*/
public static SampleYSymbolicDataset createYSymbolicSample2() {
String[] sData = {"Giraffe", "Gazelle", "Zebra", "Gnu"};
SampleYSymbolicDataset data
= new SampleYSymbolicDataset("BY Sample", 40, sData, 4, 20,
new String[] {"B Fall", "B Spring", "B Summer", "B Winter"});
return data;
}
/**
* The starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) {
SampleYSymbolicDataset s1 = createYSymbolicSample1();
SampleYSymbolicDataset s2 = createYSymbolicSample2();
displayYSymbolic("Example 1", s1, "Animal A", "Miles", "Animal");
displayYSymbolic("Example 2", s2, "Animal B", "Miles", "Animal");
displayYSymbolicCombinedHorizontally("Example 3", (SampleYSymbolicDataset) s1.clone(),
(SampleYSymbolicDataset) s2.clone());
displayYSymbolicCombinedVertically("Example 4", (SampleYSymbolicDataset) s1.clone(),
(SampleYSymbolicDataset) s2.clone());
displayYSymbolicOverlaid("Example 5", (SampleYSymbolicDataset) s1.clone(),
(SampleYSymbolicDataset) s2.clone());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -