1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JFrame;
import lt.monarch.chart.chart2D.Chart2D;
import lt.monarch.chart.chart2D.Grid;
import lt.monarch.chart.chart2D.axis.Axis2DX;
import lt.monarch.chart.chart2D.axis.Axis2DY;
import lt.monarch.chart.chart2D.engine.PlaneMapper2D;
import lt.monarch.chart.chart2D.series.BubbleSeries;
import lt.monarch.chart.engine.ChartObject;
import lt.monarch.chart.mapper.ColorMapper;
import lt.monarch.chart.mapper.LabelAxisMapper;
import lt.monarch.chart.mapper.MathAxisMapper;
import lt.monarch.chart.models.ChartDataModel;
import lt.monarch.chart.models.DataValueType;
import lt.monarch.chart.plugins.BoxZoomer;
import lt.monarch.chart.style.enums.TitlePosition;
import lt.monarch.chart.swing.JChartPanel;
import lt.monarch.chart.view.LabeledChart;
public class BubbleSeriesDemo extends JFrame {
private transient JChartPanel m_chartPanel;
public BubbleSeriesDemo() {
setLayout(new BorderLayout());
initChart();
add(m_chartPanel, BorderLayout.CENTER);
}
private void initChart() {
/*
* Creating mappers
*/
String planets[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter",
"Saturn", "Uranus", "Neptune" };
LabelAxisMapper xMapper = new LabelAxisMapper(planets);
MathAxisMapper yMapper = new MathAxisMapper(-100000, 2200000);
/*
* Creating color mapper
*/
ColorMapper color = new ColorMapper(DataValueType.VALUE);
color.setColors(Color.red, Color.blue);
/*
* Creating data
*/
ChartDataModel dataModel = new ChartDataModel(3);
dataModel.add(new Object[] { "Mercury", new Double(330), 2440000d });
dataModel.add(new Object[] { "Venus", new Double(4870), 6051000d });
dataModel.add(new Object[] { "Earth", new Double(5970), 6378000d });
dataModel.add(new Object[] { "Mars", new Double(642), 3397000d });
dataModel
.add(new Object[] { "Jupiter", new Double(1900000), 71492000d });
dataModel.add(new Object[] { "Saturn", new Double(569000), 60268000d });
dataModel.add(new Object[] { "Uranus", new Double(86600), 25559000d });
dataModel
.add(new Object[] { "Neptune", new Double(103000), 24764000d });
/*
* Creating the X and Y axes
*/
Axis2DX axisX = new Axis2DX(xMapper);
Axis2DY axisY = new Axis2DY(yMapper);
axisY.setScrollable(true);
axisY.setTitle("Mass, Zkg ");
axisX.setTitle("Planets");
axisX.setScrollable(true);
axisY.getTitleSettings().setTitlePosition(TitlePosition.BELOW);
axisX.getTitleSettings().setTitlePosition(TitlePosition.BELOW);
/*
* Creating series
*/
BubbleSeries bubble = new BubbleSeries(dataModel, new PlaneMapper2D(),
xMapper, yMapper);
/*
* Sets the colour mapper for the series
*/
bubble.setColorMapper(color);
/*
* Creating grid
*/
Grid grid = new Grid(new PlaneMapper2D(), xMapper, yMapper);
/*
* Creating and setting chart
*/
Chart2D chart = new Chart2D();
chart.setObjects(new ChartObject[] { grid, bubble });
chart.setYAxis(axisY);
chart.setXAxis(axisX);
chart.addPlugin(new BoxZoomer(xMapper, yMapper));
/*
* Creating the title
*/
LabeledChart m_chart = new LabeledChart(chart);
m_chart.setTitle("Planets by Radius and Mass");
/*
* Setting chart title
*/
m_chartPanel = new JChartPanel(m_chart);
}
public static void main(String[] args) {
BubbleSeriesDemo frame = new BubbleSeriesDemo();
frame.setSize(new Dimension(600, 400));
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setTitle("Planets by Radius and Mass");
frame.setVisible(true);
}
} |