1 33 34 package com.icesoft.faces.component.outputchart; 35 36 import org.krysalis.jcharts.Chart; 37 import org.krysalis.jcharts.chartData.PieChartDataSet; 38 import org.krysalis.jcharts.nonAxisChart.PieChart2D; 39 import org.krysalis.jcharts.nonAxisChart.PieChart3D; 40 import org.krysalis.jcharts.properties.ChartProperties; 41 import org.krysalis.jcharts.properties.LegendProperties; 42 import org.krysalis.jcharts.properties.PieChart2DProperties; 43 import org.krysalis.jcharts.properties.PieChart3DProperties; 44 import org.krysalis.jcharts.properties.util.ChartStroke; 45 import org.krysalis.jcharts.types.PieLabelType; 46 47 import javax.faces.component.UIComponent; 48 import java.awt.*; 49 50 public class PieChart extends AbstractChart { 51 52 public PieChart(UIComponent outputChart) throws Throwable { 53 super(outputChart); 54 } 55 56 protected void buildChart() { 57 try { 58 if (type.equalsIgnoreCase("pie2d")) { 59 chart = getPie2dChart(); 60 } else if (type.equalsIgnoreCase("pie3d")) { 61 chart = getPie3dChart(); 62 } 63 } catch (Throwable e) { 64 e.printStackTrace(); 65 } 66 } 67 68 double data[] = null; 69 70 public double[] getData(Object obj) { 71 if (data != null && obj instanceof String ) { 72 return data; 73 } 74 return data = super.getAsDoubleArray(obj); 75 } 76 77 String [] labels = null; 78 79 public String [] getLabels(Object obj) { 80 if (obj == null && labels == null) { 81 return labels = getGeneratedLabels("label", data.length); 82 } else if ((obj == null || obj instanceof String ) && labels != null) { 83 return labels; 84 } else { 85 return labels = getAsStringArray(obj); 86 } 87 } 88 89 public Paint[] getPaints(Object obj) { 90 return getPaints(obj, data.length); 91 } 92 93 private Chart getPie2dChart() throws Throwable { 94 PieChart2DProperties pieChart2DProperties = new PieChart2DProperties(); 95 PieChartDataSet pieChartDataSet; 96 pieChartDataSet = new PieChartDataSet(outputChart.getChartTitle(), 97 getData(outputChart.getData()), 98 getLabels( 99 outputChart.getLabels()), 100 getPaints( 101 outputChart.getColors()), 102 pieChart2DProperties); 103 104 return new PieChart2D(pieChartDataSet, 105 getLegendProperties(), 106 new ChartProperties(), 107 new Integer (outputChart.getWidth()).intValue(), 108 new Integer (outputChart.getHeight()).intValue()); 109 110 } 111 112 private Chart getPie3dChart() throws Throwable { 113 PieChart3DProperties pieChart3DProperties = new PieChart3DProperties(); 114 pieChart3DProperties.setDepth(30); 115 pieChart3DProperties.setBorderChartStroke( 116 new ChartStroke(new BasicStroke(1f), Color.black)); 117 pieChart3DProperties.setPieLabelType(PieLabelType.LEGEND_LABELS); 118 PieChartDataSet pieChartDataSet = 119 new PieChartDataSet(outputChart.getChartTitle(), 120 getData(outputChart.getData()), 121 getLabels(outputChart.getLabels()), 122 getPaints(outputChart.getColors()), 123 pieChart3DProperties); 124 return new PieChart3D(pieChartDataSet, null, new ChartProperties(), 125 new Integer (outputChart.getWidth()).intValue(), 126 new Integer (outputChart.getHeight()).intValue()); 127 } 128 } 129 | Popular Tags |