Bar3D chart uses ChartDataModel as its data model. Bar3D chart extracts (x, y, z) value sets from the data model, maps and plots them. KEYS specify position on X-axis, VALUES - on Y-axis and EXTENT - on Z-axis.
This Series uses ChartDataModel as its data model. KEYS specify where bars should stand, VALUES specify height and EXTENTS specify where bars should stand on Z-axis. Bar width can be set using setBarWidth() method and depth - setBarDepth() methods.
Figure 4.2.2.1 3D Bar Demonstration
1 | import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import javax.swing.JFrame; import lt.monarch.chart.chart3D.Chart3D; import lt.monarch.chart.chart3D.axis.Axis3DX; import lt.monarch.chart.chart3D.axis.Axis3DY; import lt.monarch.chart.chart3D.axis.Axis3DZ; import lt.monarch.chart.chart3D.engine.Grid3D; import lt.monarch.chart.chart3D.engine.PlaneMapper3D; import lt.monarch.chart.chart3D.engine.SimpleProjector3D; import lt.monarch.chart.chart3D.series.Bar3DSeries; import lt.monarch.chart.engine.ChartObject; import lt.monarch.chart.mapper.LabelAxisMapper; import lt.monarch.chart.mapper.MathAxisMapper; import lt.monarch.chart.models.ChartDataModel; import lt.monarch.chart.plugins.ChartRotator; import lt.monarch.chart.plugins.ChartZoomer; import lt.monarch.chart.swing.JChartPanel; import lt.monarch.chart.view.LabeledChart; public class Bar3DDemo extends JFrame { private transient JChartPanel m_chartPanel; public Bar3DDemo() { setLayout(new BorderLayout()); initChart(); add(m_chartPanel, BorderLayout.CENTER); } protected void initChart() { int nr = 4; String x[] = { "2005", "2006", "2007", "2008" }; String zx[] = { "Lithuania", "Latvia", "Estonia" }; Double y[] = { 2924.3, 3616.4, 4343.2d, 4484.7d }; String z[] = { "Estonia", "Estonia", "Estonia", "Estonia" }; Double y2[] = { 1988.9, 2644.0, 3296.2, 3620.0 }; String z2[] = { "Latvia", "Latvia", "Latvia", "Latvia" }; Double y3[] = { 2007.2, 2340.8, 2856.6, 3271.6 }; String z3[] = { "Lithuania", "Lithuania", "Lithuania", "Lithuania" }; ChartDataModel model1 = new ChartDataModel(); for (int i = 0; i < nr; i++) { model1.add(new Object[] { x[i], y[i], z[i] }); } ChartDataModel model2 = new ChartDataModel(3); for (int i = 0; i < nr; i++) { model2.add(new Object[] { x[i], y2[i], z2[i] }); } ChartDataModel model3 = new ChartDataModel(); for (int i = 0; i < nr; i++) { model3.add(new Object[] { x[i], y3[i], z3[i] }); } // Setting mappers MathAxisMapper yMapper = new MathAxisMapper(); LabelAxisMapper xMapper = new LabelAxisMapper(x); LabelAxisMapper zMapper = new LabelAxisMapper(zx); yMapper.setRange(0, 5000); // Setting axes Axis3DX axisX = new Axis3DX(xMapper); Axis3DY axisY = new Axis3DY(yMapper); Axis3DZ axisZ = new Axis3DZ(zMapper); axisX.setTitle("Year"); axisY.setTitle("Euros per Inhabitant"); axisZ.setTitle("Countries"); // Setting Series Bar3DSeries series1 = new Bar3DSeries(model1, xMapper, yMapper, zMapper); series1.setName("Estonia"); series1.getPaintStyle().setBackground(new Color(143, 60, 168)); series1.getPaintStyle().setForeground(null); series1.getPaintStyle().setTransparencyValue(200); Bar3DSeries series2 = new Bar3DSeries(model2, xMapper, yMapper, zMapper); series2.getPaintStyle().setBackground(new Color(49, 119, 31)); series2.getPaintStyle().setForeground(null); series2.getPaintStyle().setTransparencyValue(200); series2.setName("Latvia"); Bar3DSeries series3 = new Bar3DSeries(model3, xMapper, yMapper, zMapper); series3.setName("Lithuania"); series3.getPaintStyle().setBackground(new Color(251, 178, 47, 60)); series3.getPaintStyle().setForeground(null); series3.getPaintStyle().setTransparencyValue(200); // Setting grid Grid3D grid_xy = new Grid3D(xMapper, yMapper, Grid3D.GridOrientation.XY); new PlaneMapper3D(); Grid3D grid_xz = new Grid3D(xMapper, zMapper, Grid3D.GridOrientation.XZ); Grid3D grid_yz = new Grid3D(yMapper, null, Grid3D.GridOrientation.YZ); // Setting chart Chart3D chart = new Chart3D(); chart.addPlugin(new ChartRotator()); chart.addPlugin(new ChartZoomer()); chart.setAxis(axisX, axisY, axisZ); chart.setObjects(new ChartObject[] { axisX, axisY, axisZ, series1, series2, series3, grid_xy, grid_xz, grid_yz }); /* * Setting chart scalings */ ((SimpleProjector3D) chart.projector()).setViewScaling(1.5525, 0.621, 0.621); ((SimpleProjector3D) chart.projector()).setRotationAngle(-0.25399); ((SimpleProjector3D) chart.projector()).setElevationAngle(0.446); LabeledChart m_chart = new LabeledChart(chart); m_chart.setTitle("Total Government Revenue in Euros per Inhabitant"); m_chartPanel = new JChartPanel(m_chart); } public static void main(String[] args) { Bar3DDemo frame = new Bar3DDemo(); frame.setSize(new Dimension(490, 400)); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setTitle("Total Government Revenue in Euros per Inhabitant"); frame.setVisible(true); } } |
This Series uses ChartDataModel as its data model. KEYS specify where bars should stand, VALUES specify height and EXTENTS specify height of bar.
Figure 4.2.3.1 Floating Bar 3D Demonstration
1 | import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import javax.swing.JFrame; import lt.monarch.chart.chart3D.Chart3D; import lt.monarch.chart.chart3D.axis.Axis3DX; import lt.monarch.chart.chart3D.axis.Axis3DY; import lt.monarch.chart.chart3D.axis.Axis3DZ; import lt.monarch.chart.chart3D.engine.Grid3D; import lt.monarch.chart.chart3D.engine.PlaneMapper3D; import lt.monarch.chart.chart3D.engine.SimpleProjector3D; import lt.monarch.chart.chart3D.engine.Grid3D.GridOrientation; import lt.monarch.chart.chart3D.series.*; import lt.monarch.chart.engine.*; import lt.monarch.chart.legend.Legend; import lt.monarch.chart.mapper.LabelAxisMapper; import lt.monarch.chart.mapper.MathAxisMapper; import lt.monarch.chart.models.ChartDataModel; import lt.monarch.chart.plugins.ChartRotator; import lt.monarch.chart.plugins.ChartZoomer; import lt.monarch.chart.style.enums.Orientation; import lt.monarch.chart.swing.JChartPanel; import lt.monarch.chart.view.LabeledChart; public class FloatingBar3DDemo extends JFrame { private transient JChartPanel m_chartPanel; public FloatingBar3DDemo() { setLayout(new BorderLayout()); initChart(); add(m_chartPanel, BorderLayout.CENTER); } protected void initChart() { ChartDataModel model1 = new ChartDataModel(); model1.add(new Object[] { "Jan", new Double(15.9), new Double(-5.1), "Jakar" }); model1.add(new Object[] { "Feb", new Double(11.4), new Double(-1.4), "Jakar" }); model1.add(new Object[] { "Mar", new Double(12.7), new Double(3.5), "Jakar" }); model1.add(new Object[] { "Apr", new Double(14.8), new Double(3.9), "Jakar" }); model1.add(new Object[] { "May", new Double(11.8), new Double(9.5), "Jakar" }); model1.add(new Object[] { "Jun", new Double(9), new Double(13.5), "Jakar" }); model1.add(new Object[] { "Jul", new Double(3.2), new Double(10.9), "Jakar" }); model1.add(new Object[] { "Aug", new Double(9.3), new Double(13.7), "Jakar" }); model1.add(new Object[] { "Sep", new Double(9.5), new Double(12.1), "Jakar" }); model1.add(new Object[] { "Oct", new Double(13.6), new Double(5.9), "Jakar" }); model1.add(new Object[] { "Nov", new Double(16.6), new Double(-0.5), "Jakar" }); model1.add(new Object[] { "Dec", new Double(14.6), new Double(-2.3), "Jakar" }); ChartDataModel model2 = new ChartDataModel(); model2.add(new Object[] { "Jan", new Double(14.8), new Double(-2.6), "Thimphu" }); model2.add(new Object[] { "Feb", new Double(14.4), new Double(0.6), "Thimphu" }); model2.add(new Object[] { "Mar", new Double(12.5), new Double(3.9), "Thimphu" }); model2.add(new Object[] { "Apr", new Double(12.9), new Double(7.1), "Thimphu" }); model2.add(new Object[] { "May", new Double(9.4), new Double(13.1), "Thimphu" }); model2.add(new Object[] { "Jun", new Double(9.2), new Double(15.2), "Thimphu" }); model2.add(new Object[] { "Jul", new Double(5.5), new Double(13.4), "Thimphu" }); model2.add(new Object[] { "Aug", new Double(9.2), new Double(15.8), "Thimphu" }); model2.add(new Object[] { "Sep", new Double(8.1), new Double(15), "Thimphu" }); model2.add(new Object[] { "Oct", new Double(11.5), new Double(10.4), "Thimphu" }); model2.add(new Object[] { "Nov", new Double(12.9), new Double(5), "Thimphu" }); model2.add(new Object[] { "Dec", new Double(15.6), new Double(-1.1), "Thimphu" }); /* * Creating mappers */ LabelAxisMapper xMapper = new LabelAxisMapper(); xMapper.registerKey("Jan"); xMapper.registerKey("Feb"); xMapper.registerKey("Mar"); xMapper.registerKey("Apr"); xMapper.registerKey("May"); xMapper.registerKey("Jun"); xMapper.registerKey("Jul"); xMapper.registerKey("Aug"); xMapper.registerKey("Sep"); xMapper.registerKey("Oct"); xMapper.registerKey("Nov"); xMapper.registerKey("Dec"); MathAxisMapper yMapper = new MathAxisMapper(-6, 25); LabelAxisMapper zMapper = new LabelAxisMapper(); zMapper.registerKey("Jakar"); zMapper.registerKey("Thimphu"); /* * Creating and setting X axis */ Axis3DX axisX = new Axis3DX(xMapper); axisX.setTitle("Months"); /* * Creating and setting Y axis */ Axis3DY axisY = new Axis3DY(yMapper); axisY.setTitle("Temperature (C)"); /* * Creating and setting Z axis */ Axis3DZ axisZ = new Axis3DZ(zMapper); /* * Creating and setting series */ Bar3DSeries bar1 = new Bar3DSeries(model1, xMapper, yMapper, zMapper); bar1.setOrientation(Orientation.VERTICAL); bar1.setName("Jakar: Elevation: 2600 meters, Latitude: 27 36N, Longitude: 090 49E"); bar1.setOrientation(Orientation.VERTICAL); bar1.setStrategy(Bar3DStrategies.FLOATING_BAR_STRATEGY); Bar3DSeries bar2 = new Bar3DSeries(model2, xMapper, yMapper, zMapper); bar2.setOrientation(Orientation.VERTICAL); bar2.setName("Thimphu: Elevation: 2300 meters, Latitude: 27 32N, Longitude: 089 43E"); bar1.getPaintStyle().setBackground(new Color(251, 178, 47, 60)); bar1.getPaintStyle().setForeground(new Color(251, 178, 47, 60).darker()); bar1.getPaintStyle().setTransparencyValue(200); bar2.getPaintStyle().setBackground(new Color(49, 119, 31)); bar2.getPaintStyle().setForeground(new Color(49, 119, 31).darker()); bar2.getPaintStyle().setTransparencyValue(200); bar2.setOrientation(Orientation.VERTICAL); bar2.setStrategy(Bar3DStrategies.FLOATING_BAR_STRATEGY); /* * Setting series and bar spacings */ Bar3DSeries.setBarSpacing(zMapper, 1f); Bar3DSeries.setSeriesSpacing(zMapper, 1f); Bar3DSeries.setBarSpacing(xMapper, 0.5f); Bar3DSeries.setSeriesSpacing(xMapper, 0.5f); /* * Creating and setting grid */ Grid3D gridX = new Grid3D(yMapper, zMapper, GridOrientation.YZ); gridX.getPaintStyle().setBackground(new Color(255, 255, 204, 50)); gridX.getPaintStyle().setTransparencyValue(100); Grid3D gridY = new Grid3D(xMapper, zMapper, GridOrientation.XZ); gridY.getPaintStyle().setBackground(new Color(255, 255, 204, 50)); gridY.getPaintStyle().setTransparencyValue(100); Grid3D gridZ = new Grid3D(xMapper, yMapper, GridOrientation.XY); gridZ.getPaintStyle().setBackground(new Color(255, 255, 204, 50)); gridZ.getPaintStyle().setTransparencyValue(100); /* * Set settings to chart */ Chart3D chart = new Chart3D(); chart.setObjects(new ChartObject[] { gridX, gridY, gridZ, bar1, bar2 }); chart.setAxis(axisX, axisY, axisZ); /* * Setting angles */ ((SimpleProjector3D)chart.projector()).setViewScaling(1.2, 0.5, 0.5); ((SimpleProjector3D)chart.projector()).setElevationAngle(0.45); ((SimpleProjector3D)chart.projector()).setRotationAngle(-0.55); /* * Creating legend */ Legend legend = new Legend(chart); legend.setMaxColumns(1); /* * Creating chart title */ LabeledChart m_chart = new LabeledChart(chart); m_chart.setBottomView(legend); m_chart.setTitle("Bhutan cities average temperatures"); chart.addPlugin(new ChartRotator()); m_chartPanel = new JChartPanel(m_chart); m_chartPanel.enableToolTips(); m_chartPanel.setHotSpotMap(new SimpleHotSpotMap()); } public static void main(String[] args) { FloatingBar3DDemo frame = new FloatingBar3DDemo(); frame.setSize(new Dimension(490, 400)); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setTitle("Bhutan cities average temperatures"); frame.setVisible(true); } } |
For this series, there is a possibility to set bar width, using setBarWidth() method.
series1.setBarWidth(0.08f); series2.setBarWidth(0.08f); series3.setBarWidth(0.08f); |
Figure 4.2.4.1 All Bars Width set to 0.08 Demonstration
Bar depth can be altered using setBarDepth() method.
series1.setBarDepth(0.01f); series2.setBarDepth(0.01f); series3.setBarDepth(0.04f); |
Cylinder Bar shape can be set using getStrategy().setShape(new Pole3D()).
Pole3D cylinder = new Pole3D(); // create polygon object cylinder.setPointsCount(20); // sets points of polygon Bar3DSeries.getStrategy().setShape(cylinder); //sets bar shape - cylinder |
Figure 4.2.4.3 Bar3DSeries Shape Cylinder Demonstration
Bar and Series spacing can be set using static methods setBarSpacing() and setSeriesSpacing().
Bar3DSeries.setBarSpacing(xMapper, 0.8f); //sets bar spacing for x-mapper Bar3DSeries.setSeriesSpacing(zMapper, 0.9f); //sets series spacing for z-mapper |
Figure 4.2.4.4 Bar3DSeries Spacing Demonstration