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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | import java.awt.*;
import javax.swing.JFrame;
import lt.monarch.chart.chart2D.*;
import lt.monarch.chart.chart2D.axis.*;
import lt.monarch.chart.chart2D.engine.PlaneMapper2D;
import lt.monarch.chart.chart2D.series.ContourSeries;
import lt.monarch.chart.engine.*;
import lt.monarch.chart.legend.ColorScaleLegend;
import lt.monarch.chart.mapper.MathAxisMapper;
import lt.monarch.chart.marker.*;
import lt.monarch.chart.models.*;
import lt.monarch.chart.style.AspectRatio;
import lt.monarch.chart.style.enums.*;
import lt.monarch.chart.swing.JChartPanel;
import lt.monarch.chart.view.LabeledChart;
public class ContourSeriesDemo extends JFrame
{
private transient JChartPanel m_chartPanel;
public ContourSeriesDemo ()
{
setLayout(new BorderLayout());
initChart();
add(m_chartPanel, BorderLayout.CENTER);
}
public strictfp void initChart()
{
/*
* Setting mappers
*/
MathAxisMapper xMapper = new MathAxisMapper(0, 1000);
MathAxisMapper yMapper = new MathAxisMapper(0, 1800);
/*
* Setting Axes
*/
Axis2DX axisX = new Axis2DX(xMapper);
axisX.setTitle("km");
axisX.getTitleSettings().setHorizontalAlignment(Alignment.RIGHT);
axisX.getTitleSettings().setPosition(TitlePosition.INLINE);
axisX.setScrollable(true);
Axis2DY axisY = new Axis2DY(yMapper);
axisY.setTitle("km");
axisY.getTitleSettings().setVerticalAlignment(Alignment.TOP);
axisY.getTitleSettings().setPosition(TitlePosition.INLINE);
axisY.setScrollable(true);
/*
* Setting ChartDataModel
*/
ChartDataModel data = generteDataModel();
/*
* Setting Series
*/
ContourSeries series = new ContourSeries(data, xMapper, yMapper);
series.setContourCount(23);
series.getPaintStyle().setForeground(null);
series.setAspectRatio(AspectRatio.NONE);
series.setName("Relative height, m");
// setting colours
series.setColorPalette(getColors());
/*
* Setting grid
*/
Grid grid = new Grid(new PlaneMapper2D(), xMapper, yMapper);
/*
* Setting marker
*/
ChartDataModel markerData = new ChartDataModel();
markerData.add(new DataColumnType[] { DataColumnType.KEY, DataColumnType.VALUE, DataColumnType.LABEL }, new Object[] { 770, 610, "Tsiafajavona Mountain" });
DotMarker marker = new DotMarker();
marker.setMarkerSize(8.0);
marker.getPaintStyle().setBackground(Color.RED);
marker.getPaintStyle().setForeground(Color.BLACK);
LabeledMarker labeledMarker = new LabeledMarker(marker, new MetaDataModel());
labeledMarker.getTextStyle().setColor(Color.BLACK);
series.setMarkers(labeledMarker, markerData);
/*
* Setting chart
*/
Chart2D chart = new Chart2D();
chart.setObjects(new ChartObject[] { grid, axisX, axisY, series });
chart.setXAxis(axisX);
chart.setYAxis(axisY);
LabeledChart m_chart = new LabeledChart(chart);
m_chart.setTitle("Madagascar Surface");
/*
* Setting Legend
*/
ColorScaleLegend legend = new ColorScaleLegend(chart);
m_chart.setRightView(legend);
/*
* Setting JChartPanel
*/
m_chartPanel = new JChartPanel(m_chart);
m_chartPanel.setHotSpotMap(new SimpleHotSpotMap());
}
public static void main(String[] args)
{
ContourSeriesDemo frame = new ContourSeriesDemo();
frame.setSize(new Dimension(900, 600));
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setTitle("Madagascar Surface");
frame.setVisible(true);
}
/*
* private method which returns chart's data model
*/
private strictfp ChartDataModel generteDataModel()
{
ChartDataModel data = new ChartDataModel();
data.add(new Object[] { new Object[] { 0, 0, 0, 0, 0, 0, 0 } });
data.add(new Object[] { new Object[] { 110, 110, 154, 88, 110, 572, 154 } });
data.add(new Object[] { new Object[] { 88, 88, 88, 66, 110, 264, 572 } });
data.add(new Object[] { new Object[] { 88, 110, 88, 66, 1298, 1804, 418 } });
data.add(new Object[] { new Object[] { 110, 132, 704, 1606, 1694, 1782, 22 } });
data.add(new Object[] { new Object[] { 66, 858, 1276, 2046, 1650, 1034, 44 } });
data.add(new Object[] { new Object[] { 110, 792, 1364, 1364, 1804, 1122, 110 } });
data.add(new Object[] { new Object[] { 88, 44, 1694, 1408, 2134, 1078, 110 } });
data.add(new Object[] { new Object[] { 88, 1012, 2002, 1364, 1914, 176, 66 } });
data.add(new Object[] { new Object[] { 88, 1012, 1782, 1738, 1298, 88, 66 } });
data.add(new Object[] { new Object[] { 44, 308, 2816, 1584, 968, 88, 66 } });
data.add(new Object[] { new Object[] { 88, 1034, 1804, 1694, 110, 110, 88 } });
data.add(new Object[] { new Object[] { 88, 792, 880, 660, 110, 88, 88 } });
data.add(new Object[] { new Object[] { 88, 88, 88, 88, 110, 88, 66 } });
System.gc();
return data;
}
/*
* private method which returns an array of colours for chart
*/
private Color[] getColors()
{
return new Color[] {
new Color(41, 53, 150), new Color(41, 53, 140), new Color(41, 63, 130), new Color(41, 73, 130), new Color(62, 79, 145), new Color(82, 105, 140), new Color(83, 113, 130), new Color(85, 120, 121), new Color(85, 120, 121), new Color(86, 128, 111), new Color(87, 135, 101), new Color(89, 143, 92), new Color(90, 150, 82), new Color(111, 163, 95), new Color(133, 176, 108), new Color(154, 190, 122), new Color(175, 203, 135), new Color(175, 203, 135), new Color(218, 229, 161), new Color(227, 213, 139), new Color(237, 198, 118), new Color(237, 178, 98), new Color(255, 166, 74), new Color(247, 155, 84), new Color(239, 144, 95), new Color(239, 144, 95), new Color(222, 121, 115) };
}
} |