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 | import java.awt.*;
import javax.swing.JFrame;
import lt.monarch.chart.chart3D.Chart3D;
import lt.monarch.chart.chart3D.engine.SimpleProjector3D;
import lt.monarch.chart.chart3D.series.*;
import lt.monarch.chart.engine.*;
import lt.monarch.chart.models.*;
import lt.monarch.chart.plugins.*;
import lt.monarch.chart.style.Styles;
import lt.monarch.chart.style.enums.*;
import lt.monarch.chart.style.tags.*;
import lt.monarch.chart.swing.JChartPanel;
import lt.monarch.chart.view.*;
public class Pie3DDemo extends JFrame
{
private transient JChartPanel m_chartPanel;
public Pie3DDemo ()
{
setLayout(new BorderLayout());
initChart();
add(m_chartPanel, BorderLayout.CENTER);
}
protected void initChart()
{
Chart3D chart = new Chart3D();
// setting chart data model
ChartDataModel pieModel = new ChartDataModel();
pieModel.add(new Object[] { "USA", new Double(25.1) });
pieModel.add(new Object[] { "Germany", new Double(10.7) });
pieModel.add(new Object[] { "India", new Double(9.7) });
pieModel.add(new Object[] { "China", new Double(5.3) });
pieModel.add(new Object[] { "UK", new Double(5.1) });
pieModel.add(new Object[] { "Other", new Double(44.1) });
// setting chart style
MetaDataModel meta1 = new MetaDataModel();
// creating style objects
Styles<SeriesPaintTags> style1 = new Styles<SeriesPaintTags>();
Styles<SeriesPaintTags> style2 = new Styles<SeriesPaintTags>();
Styles<SeriesPaintTags> style3 = new Styles<SeriesPaintTags>();
Styles<SeriesPaintTags> style4 = new Styles<SeriesPaintTags>();
Styles<SeriesPaintTags> style5 = new Styles<SeriesPaintTags>();
Styles<SeriesPaintTags> style6 = new Styles<SeriesPaintTags>();
// setting background color for each slice
style1.getPaintStyle().setBackground(new Color(49, 119, 31));
style2.getPaintStyle().setBackground(new Color(75, 146, 188));
style3.getPaintStyle().setBackground(new Color(143, 60, 168));
style4.getPaintStyle().setBackground(new Color(245, 64, 55, 20));
style5.getPaintStyle().setBackground(new Color(223, 95, 32));
style6.getPaintStyle().setBackground(new Color(251, 178, 47));
// setting foreground color for each slice
style1.getPaintStyle().setForeground(null);
style2.getPaintStyle().setForeground(null);
style3.getPaintStyle().setForeground(null);
style4.getPaintStyle().setForeground(null);
style5.getPaintStyle().setForeground(null);
style6.getPaintStyle().setForeground(null);
style1.getPaintStyle().setTransparencyValue(155);
style2.getPaintStyle().setTransparencyValue(155);
style3.getPaintStyle().setTransparencyValue(155);
style4.getPaintStyle().setTransparencyValue(155);
style5.getPaintStyle().setTransparencyValue(155);
style6.getPaintStyle().setTransparencyValue(155);
style1.getTextStyle().setFont(new Font("Arial", Font.BOLD, 14));
style2.getTextStyle().setFont(new Font("Arial", Font.BOLD, 14));
style3.getTextStyle().setFont(new Font("Arial", Font.BOLD, 14));
style4.getTextStyle().setFont(new Font("Arial", Font.BOLD, 14));
style5.getTextStyle().setFont(new Font("Arial", Font.BOLD, 14));
style6.getTextStyle().setFont(new Font("Arial", Font.BOLD, 14));
// adding styles to meta data
meta1.setData(MetaDataType.STYLE, 0, style1);
meta1.setData(MetaDataType.STYLE, 1, style2);
meta1.setData(MetaDataType.STYLE, 2, style3);
meta1.setData(MetaDataType.STYLE, 3, style4);
meta1.setData(MetaDataType.STYLE, 4, style5);
meta1.setData(MetaDataType.STYLE, 5, style6);
// setting height
meta1.setData(MetaDataType.PIE_HEIGHT, 0, new Double(0.3));
meta1.setData(MetaDataType.PIE_HEIGHT, 1, new Double(0.25));
meta1.setData(MetaDataType.PIE_HEIGHT, 2, new Double(0.2));
meta1.setData(MetaDataType.PIE_HEIGHT, 3, new Double(0.15));
meta1.setData(MetaDataType.PIE_HEIGHT, 4, new Double(0.1));
meta1.setData(MetaDataType.PIE_HEIGHT, 5, new Double(0.05));
// setting series
Pie3DSeries pie = new Pie3DSeries(pieModel, meta1);
pie.setStartAngle(20d);
// setting labels
pie.setLabelLayouter(Pie3DLabelsLayouters.LABELS_OUTSIDE);
pie.setLabelAlignment(Pie3DLabelAlignment.CIRCULAR);
pie.setLabelFormat(PieLabelFormat.CUSTOM_LABELS);
pie.setLabelFormatPattern("%3$s - %2$.1f%%");
// setting legend format
pie.setLegendFormat(PieLegendFormat.CUSTOM_LABELS);
pie.setLegendFormatPattern("%1$.2f, %2$.0f%%, %3$s");
pie.getTextStyle().setColor(Color.red);
pie.getPaintStyle().setTransparencyValue(20);
chart.setObjects(new ChartObject[] { pie });
chart.addPlugin(new ChartRotator(pie));
chart.addPlugin(new ChartZoomer());
chart.setPaintMode(PaintMode.GRADIENT_PAINT);
chart.getPaintStyle().getGradientStyle().setColors(Color.RED, Color.GREEN);
((SimpleProjector3D)chart.projector()).setElevationAngle(Math.toRadians(20));
LabelView<LabeledChartPaintTags> nameView = new LabelView<LabeledChartPaintTags>("");
nameView.getTextStyle().setColor(new Color(0, 0, 0));
nameView.setHorizontalAlignment(Alignment.RIGHT);
nameView.getTextStyle().setFont(new Font("Arial", Font.BOLD, 18));
LabelView<LabeledChartPaintTags> lastTitle = new LabelView<LabeledChartPaintTags>("Avg. Time on Site: 3.1 min/day " + " Sites Linking In : 27,002 " + "Online Since: 14-Dec-1995");
lastTitle.getTextStyle().setColor(new Color(60, 120, 181, 255));
lastTitle.setHorizontalAlignment(Alignment.RIGHT);
lastTitle.getTextStyle().setFont(new Font("Arial", Font.BOLD, 12));
LabeledChart m_chart = new LabeledChart(chart);
m_chart.setBottomView(lastTitle, 105);
m_chart.setTitle("Archive.org visitors by country");
// setting JChartPanel
m_chartPanel = new JChartPanel(m_chart);
m_chartPanel.setHotSpotMap(new SimpleHotSpotMap());
}
public static void main(String[] args)
{
Pie3DDemo frame = new Pie3DDemo();
frame.setSize(new Dimension(600, 400));
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setTitle("Archive.org visitors by country");
frame.setVisible(true);
}
} |