1 20 package org.openi.test; 21 22 import com.tonbeller.jpivot.olap.model.OlapException; 23 import com.tonbeller.jpivot.xmla.XMLA_Model; 24 import org.apache.log4j.Logger; 25 import org.jfree.chart.ChartRenderingInfo; 26 import org.jfree.chart.ChartUtilities; 27 import org.jfree.chart.JFreeChart; 28 import org.jfree.chart.axis.CategoryAxis; 29 import org.jfree.chart.axis.NumberAxis; 30 import org.jfree.chart.axis.ValueAxis; 31 import org.jfree.chart.entity.StandardEntityCollection; 32 import org.jfree.chart.labels.StandardCategoryToolTipGenerator; 33 import org.jfree.chart.plot.CategoryPlot; 34 import org.jfree.chart.plot.PlotOrientation; 35 import org.jfree.chart.renderer.category.BarRenderer; 36 import org.jfree.data.category.DefaultCategoryDataset; 37 import org.openi.chart.AxisLabelGenerator; 38 import org.openi.xmla.DatasetAdapter; 39 import org.openi.xmla.XmlaConnector; 40 import org.xml.sax.SAXException ; 41 import java.awt.Font ; 42 import java.io.File ; 43 import java.io.IOException ; 44 import java.util.Locale ; 45 46 47 public class XmlaTester { 48 private static Logger logger = Logger.getLogger(XmlaTester.class); 49 50 54 public XmlaTester() { 55 Util.setupLog4j(); 57 } 58 59 public void query() throws IOException , OlapException, SAXException { 60 long start = System.currentTimeMillis(); 61 62 67 68 String url = ""; 70 String catalog = ""; 71 String apple = ""; 72 XmlaConnector connector = new XmlaConnector(); 73 XMLA_Model model = connector.query(url, catalog, apple); 74 logger.debug("query time: " + (System.currentTimeMillis() - start) 75 + "ms"); 76 77 79 DatasetAdapter adapter = new DatasetAdapter(Locale.getDefault()); 81 logger.debug("building a category dataset"); 82 83 DefaultCategoryDataset dataset = adapter.buildCategoryDataset(model); 84 85 String chartTitle = "chartTitle"; 87 Font titleFont = new Font ("name", 1, 12); 88 logger.debug("building axis label"); 91 92 AxisLabelGenerator axisLabel = new AxisLabelGenerator(); 93 String horizAxisLabel = axisLabel.getHorizAxisLabel(model); 94 String vertAxisLabel = axisLabel.getVertAxisLabel(model); 95 boolean showLegend = true; 96 boolean showTooltips = true; 97 boolean drillThroughEnabled = false; 98 99 107 CategoryAxis categoryAxis = new CategoryAxis(horizAxisLabel); 108 ValueAxis valueAxis = new NumberAxis(vertAxisLabel); 109 BarRenderer renderer = new BarRenderer(); 110 111 if (showTooltips) { 112 renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); 113 } 114 115 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 116 renderer); 117 plot.setOrientation(PlotOrientation.HORIZONTAL); 118 119 JFreeChart chart = new JFreeChart(chartTitle, titleFont, plot, 120 showLegend); 121 122 ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); 124 String renderFile = "/home/plucas/results/" 125 + XmlaTester.class.getName(); 126 ChartUtilities.saveChartAsPNG(new File (renderFile + ".png"), chart, 127 640, 480, info); 128 ChartUtilities.saveChartAsJPEG(new File (renderFile + ".jpg"), chart, 129 640, 480); 130 131 137 } 138 139 public static void main(String [] args) { 140 try { 141 XmlaTester tester = new XmlaTester(); 142 tester.query(); 143 } catch (Exception e) { 144 e.printStackTrace(); 145 } 146 } 147 } | Popular Tags |