Radar chart automatically determines the number of axes required by finding the maximum number of items in each data model.
A radar chart is a graphical method of displaying multivariate data in the form of a two-dimensional chart of three or more quantitative variables represented on axes starting from the same point. The relative position and angle of the axes is typically uninformative.
The radar chart is also known as web chart, spider chart and star chart.
Radar series uses ChartDataModel as its data model. Setting RadarSeries:
1 | //setting RadarSeries object named radar where // dataModel is an instance of ChartDataModel // mapper - instances of AxisMapper RadarSeries radar = new RadarSeries(mapper, dataModel); |
Figure 4.1.9.1 Radar Series Demonstration
1 | import java.awt.BasicStroke; 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.GridRegularPolygon; import lt.monarch.chart.chart2D.axis.RadarAxisSet; import lt.monarch.chart.chart2D.engine.PlaneMapper2D; import lt.monarch.chart.chart2D.engine.PolarProjector; import lt.monarch.chart.chart2D.series.RadarSeries; import lt.monarch.chart.chart2D.series.RadarStrategies; import lt.monarch.chart.engine.ChartObject; import lt.monarch.chart.legend.Legend; import lt.monarch.chart.mapper.AbstractRadarMapper; import lt.monarch.chart.mapper.MathAxisMapper; import lt.monarch.chart.mapper.RadarMapper; import lt.monarch.chart.marker.DotMarker; import lt.monarch.chart.marker.SquareMarker; import lt.monarch.chart.models.ChartDataModel; import lt.monarch.chart.swing.JChartPanel; import lt.monarch.chart.view.LabeledChart; public class RadarStrategy_sample extends JFrame { private transient JChartPanel m_chartPanel; public RadarStrategy_sample() { setLayout(new BorderLayout()); initChart(); add(m_chartPanel, BorderLayout.CENTER); } private void initChart() { /* * Creating data */ // 1996 ChartDataModel model1 = new ChartDataModel(new Object[][]{ { 65.5, 73.1, 73.0, 61.1, 67.0, 65.8, 37.4, 82.6, 96.0, 61.8, 63.8, 74.6, 69.3, 64.8, 61.7, 78.6, 67.5, 84.5 }}); // 2007 ChartDataModel model2 = new ChartDataModel(new Object[][]{ { 82.7, 93.9 , 93.9 , 85.3, 91.4 , 64.8, 69.9, 76.6 , 94.8, 65.5, 87.0, 80.0, 65.9 , 70.0 , 83.0, 82.3 , 72.8 , 93.8 }}); String[] labels = new String[]{ "Estonia", "Ireland","Poland", "Latvia", "Lithuania", "Portugal", "Romania", "France", "Sweden", "United States","Czech Republic" ,"Denmark", "Greece" ,"Spain", "Hungary", "Netherlands", "Austria" ,"Finland" }; /* * Creating mappers */ MathAxisMapper axisMapper = new MathAxisMapper(20,100); AbstractRadarMapper mapper = new RadarMapper(axisMapper); /* * Creating radar axes */ // Set Initial axis position mapper.setInitAxisPosition(0); // Set axis count mapper.setAxisCount(model1.getPointCount()); RadarAxisSet axis = new RadarAxisSet(mapper); // Set axis titles for (int i = 0; i < labels.length; i++) axis.setTitle(i, labels[i]); axis.getPaintStyle().setForeground(Color.LIGHT_GRAY); //Set Series RadarSeries series1 = new RadarSeries(mapper, model1); RadarSeries series2 = new RadarSeries(mapper, model2); BasicStroke bs = new BasicStroke(5f); series1.getPaintStyle().setForeground(new Color (213,115,255)); series1.getPaintStyle().setStroke(bs); series2.getPaintStyle().setForeground(new Color (128,214,249)); series2.getPaintStyle().setStroke(bs); // Set Strategy series1.setStrategy(RadarStrategies.RADAR_STRATEGY); series2.setStrategy(RadarStrategies.RADAR_STRATEGY); //Set series name series1.setName("1996"); series2.setName("2007"); /* * Add markers */ SquareMarker sm = new SquareMarker(); DotMarker dm = new DotMarker(); sm.getPaintStyle().setForeground(new Color (213,115,255)); dm.getPaintStyle().setForeground(new Color (242,215,124)); series1.addMarker(sm); series2.addMarker(dm); /* * Grid setting */ GridRegularPolygon grid = new GridRegularPolygon(new PlaneMapper2D(), mapper, mapper); grid.getPaintStyle().setBackground(new Color(247,251,254)); grid.getPaintStyle().setTransparencyValue(50); Chart2D radar = new Chart2D(new PolarProjector()); radar.setObjects(new ChartObject[] { grid,axis, series1, series2}); // Set chart LabeledChart topChart = new LabeledChart(radar); topChart.setTitle("18-year-olds in education(%)"); topChart.setRightView(new Legend(radar)); m_chartPanel = new JChartPanel(topChart); } public static void main(String[] args) { RadarStrategy_sample frame = new RadarStrategy_sample(); frame.setSize(new Dimension(600, 400)); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setTitle("18-year-olds in education(%)"); frame.setVisible(true); } } |
A Polar Chart is a circular graph on which data is displayed in terms of values and angles. The KEY value define the angle at which the data points will be plotted. The VALUE defines the distance of the data points from the center of the graph.
Setting Radar - Polar Series:
// setting strategy for object named radar which is an instance of RadarSeries radar.setStrategy(RadarStrategies.POLAR_RADAR_STRATEGY); |
Figure 4.1.9.2 Radar - Polar Series Demonstration
1 | import java.awt.BasicStroke; 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.GridCircle; import lt.monarch.chart.chart2D.axis.RadarAxisSet; import lt.monarch.chart.chart2D.engine.PlaneMapper2D; import lt.monarch.chart.chart2D.engine.PolarProjector; import lt.monarch.chart.chart2D.series.RadarSeries; import lt.monarch.chart.chart2D.series.RadarStrategies; import lt.monarch.chart.engine.ChartObject; import lt.monarch.chart.legend.Legend; import lt.monarch.chart.mapper.AbstractRadarMapper; import lt.monarch.chart.mapper.MathAxisMapper; import lt.monarch.chart.mapper.RadarMapper; import lt.monarch.chart.marker.DotMarker; import lt.monarch.chart.marker.SquareMarker; import lt.monarch.chart.models.ChartDataModel; import lt.monarch.chart.plugins.ToolTipManager; import lt.monarch.chart.swing.JChartPanel; import lt.monarch.chart.view.LabeledChart; public class RadarPolar_sample extends JFrame { private transient JChartPanel m_chartPanel; public RadarPolar_sample() { setLayout(new BorderLayout()); initChart(); add(m_chartPanel, BorderLayout.CENTER); } private void initChart() { /* * Set Data Model */ ChartDataModel model1= new ChartDataModel (); ChartDataModel model2= new ChartDataModel (); int Points = 360; String[] aTitle = new String[37]; for ( int i= 0; i < Points; i=i+10) { double angle = 2*Math.PI *i/ 360; model1.add(new Object[] {angle,(Math.sin(angle)+Math.cos(angle))}); model2.add(new Object[] {angle,(Math.sin(2*angle)+Math.cos(angle))}); aTitle[i/10]= "" + i; } /* * Set Mappers */ MathAxisMapper axisMapper = new MathAxisMapper(0,2); AbstractRadarMapper mapper = new RadarMapper(axisMapper); double angle1 = 2*Math.PI *30/ 360; // Set Initial ARadar axis position mapper.setInitAxisPosition(angle1); // Set Axis Count mapper.setAxisCount(model1.getPointCount()); /* * Axis settings */ RadarAxisSet axis = new RadarAxisSet(mapper); axis.setShowAxisLabels(true); for (int i=0; i <= 36; i++){ axis.setTitle(i,aTitle[i]); } axis.getPaintStyle().setForeground(Color.LIGHT_GRAY); /* * Stroke style settings */ BasicStroke strokeB = new BasicStroke(5.0f); BasicStroke stroke2 = new BasicStroke(3.0f); /* * Set series */ RadarSeries series1 = new RadarSeries(mapper, model1); RadarSeries series2 = new RadarSeries(mapper, model2); series1.getPaintStyle().setForeground(new Color (209,193,141)); series2.getPaintStyle().setForeground(new Color(86,192,206)); series1.getPaintStyle().setStroke(strokeB); series2.getPaintStyle().setStroke(stroke2); series1.setStrategy(RadarStrategies.POLAR_RADAR_STRATEGY); series2.setStrategy(RadarStrategies.POLAR_RADAR_STRATEGY); series1.setName("Sin(x)+Cos(x)"); series2.setName("Sin(2*x)+Cos(x)"); /* * Marker Settings */ SquareMarker sm = new SquareMarker(); sm.getPaintStyle().setBackground(new Color(241,174,44)); sm.getPaintStyle().setForeground(new Color(241,174,44)); sm.setMarkerSize(7d); DotMarker dm = new DotMarker(); dm.getPaintStyle().setBackground(new Color(86,192,206)); dm.getPaintStyle().setForeground(new Color(86,192,206)); dm.setMarkerSize(7d); series1.addMarker(sm); series2.addMarker(dm); /* * Set Grid */ GridCircle grid = new GridCircle(new PlaneMapper2D(), mapper, mapper); grid.getPaintStyle().setBackground(new Color(255,252,240)); grid.getPaintStyle().setForeground(new Color(102,123,126)); grid.getPaintStyle().setTransparencyValue(150); /* * Set chart */ Chart2D radar = new Chart2D(new PolarProjector()); radar.setObjects(new ChartObject[] { grid, axis, series1,series2}); ToolTipManager toolTipManager = new ToolTipManager(); radar.addPlugin(toolTipManager); LabeledChart topChart = new LabeledChart(radar); topChart.setTitle("Mathematical functions"); topChart.setRightView(new Legend(radar)); m_chartPanel = new JChartPanel(topChart); } public static void main(String[] args) { RadarStrategy_sample frame = new RadarStrategy_sample(); frame.setSize(new Dimension(600, 400)); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setTitle("Mathematical functions"); frame.setVisible(true); } } |