1 2 35 36 package org.krysalis.jcharts.demo.userGuide; 37 38 39 import org.krysalis.jcharts.properties.PieChart2DProperties; 40 import org.krysalis.jcharts.properties.LegendProperties; 41 import org.krysalis.jcharts.properties.ChartProperties; 42 import org.krysalis.jcharts.properties.util.ChartStroke; 43 import org.krysalis.jcharts.chartData.ChartDataException; 44 import org.krysalis.jcharts.chartData.PieChartDataSet; 45 import org.krysalis.jcharts.nonAxisChart.PieChart2D; 46 import org.krysalis.jcharts.types.PieLabelType; 47 48 import java.awt.*; 49 50 51 56 public class PieChartsGuide extends UserGuideBase 57 { 58 59 64 public void run() throws Throwable 65 { 66 this.basicChart(); 67 this.zeroDegreeOffsetChart(); 68 this.borderStroke(); 69 this.borderPaint(); 70 71 this.pieValueLabels(); 72 this.pieLegendLabels(); 73 } 74 75 76 77 private void outputChart( PieChart2DProperties pieChart2DProperties, String name ) throws ChartDataException 78 { 79 double[] data= { 81d, 55d, 39d, 20.6d }; 80 String [] labels= { "BMW M5", "BMW M3", "Viper GTS-R", "Corvette Z06" }; 81 Paint[] paints= { Color.lightGray, Color.green, Color.blue, Color.red }; 82 83 PieChartDataSet pieChartDataSet= new PieChartDataSet( "Cars That Own", data, labels, paints, pieChart2DProperties ); 84 85 PieChart2D pieChart2D= new PieChart2D( pieChartDataSet, new LegendProperties(), new ChartProperties(), 400, 350 ); 86 super.exportImage( pieChart2D, name ); 87 } 88 89 90 91 private void basicChart() throws Throwable 92 { 93 PieChart2DProperties pieChart2DProperties= new PieChart2DProperties(); 94 this.outputChart( pieChart2DProperties, "pieChartBasic" ); 95 } 96 97 98 99 private void zeroDegreeOffsetChart() throws Throwable 100 { 101 PieChart2DProperties pieChart2DProperties= new PieChart2DProperties(); 102 pieChart2DProperties.setZeroDegreeOffset( 45f ); 103 this.outputChart( pieChart2DProperties, "pieChartZeroOffset" ); 104 } 105 106 107 108 private void borderStroke() throws Throwable 109 { 110 PieChart2DProperties pieChart2DProperties= new PieChart2DProperties(); 111 pieChart2DProperties.setBorderChartStroke( new ChartStroke( new BasicStroke( 4f ), Color.black ) ); 112 this.outputChart( pieChart2DProperties, "pieChartBorderStroke" ); 113 } 114 115 116 117 private void borderPaint() throws Throwable 118 { 119 124 } 125 126 127 private void pieValueLabels() throws ChartDataException 128 { 129 PieChart2DProperties pieChart2DProperties= new PieChart2DProperties(); 130 pieChart2DProperties.setPieLabelType( PieLabelType.VALUE_LABELS ); 131 this.outputChart( pieChart2DProperties, "pieChartValueLabels" ); 132 } 133 134 private void pieLegendLabels() throws ChartDataException 135 { 136 PieChart2DProperties pieChart2DProperties= new PieChart2DProperties(); 137 pieChart2DProperties.setPieLabelType( PieLabelType.LEGEND_LABELS ); 138 139 double[] data= { 81d, 55d, 39d, 20.6d }; 140 String [] labels= { "BMW M5", "BMW M3", "Viper GTS-R", "Audi S6" }; 141 Paint[] paints= { Color.lightGray, Color.green, Color.blue, Color.red }; 142 143 PieChartDataSet pieChartDataSet= new PieChartDataSet( "Cars That Own", data, labels, paints, pieChart2DProperties ); 144 PieChart2D pieChart2D= new PieChart2D( pieChartDataSet, null, new ChartProperties(), 400, 350 ); 145 super.exportImage( pieChart2D, "pieChartLegendLabels" ); 146 } 147 } 148 149 150 151 152 153 | Popular Tags |