[17184] | 1 | package org.greenstone3.ms;
|
---|
| 2 |
|
---|
| 3 | import java.awt.Color;
|
---|
| 4 | import java.awt.Font;
|
---|
| 5 | import java.util.ArrayList;
|
---|
| 6 | import javax.swing.JPanel;
|
---|
| 7 | import org.jfree.chart.ChartPanel;
|
---|
| 8 | import org.jfree.chart.JFreeChart;
|
---|
| 9 | import org.jfree.chart.axis.NumberAxis;
|
---|
| 10 | import org.jfree.chart.axis.NumberTickUnit;
|
---|
| 11 | import org.jfree.chart.axis.SymbolAxis;
|
---|
| 12 | import org.jfree.chart.plot.XYPlot;
|
---|
| 13 | import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
|
---|
| 14 | import org.jfree.data.xy.XYDataset;
|
---|
| 15 | import org.jfree.data.xy.XYSeries;
|
---|
| 16 | import org.jfree.data.xy.XYSeriesCollection;
|
---|
| 17 | import org.jfree.ui.ApplicationFrame;
|
---|
| 18 | import org.jfree.ui.RefineryUtilities;
|
---|
| 19 |
|
---|
| 20 | public class DrawSymbolAxis extends ApplicationFrame
|
---|
| 21 | {
|
---|
| 22 | //private String Title;
|
---|
| 23 | private static String[] metadataName;
|
---|
| 24 |
|
---|
| 25 | private static String[] documentIDs;
|
---|
| 26 |
|
---|
| 27 | private static ArrayList dataset;
|
---|
| 28 |
|
---|
| 29 | public DrawSymbolAxis(String string, String[] metadata, String[] ids, ArrayList set) {
|
---|
| 30 | super(string);
|
---|
| 31 | //Title = string;
|
---|
| 32 | metadataName = metadata;
|
---|
| 33 | documentIDs = ids;
|
---|
| 34 | dataset = set;
|
---|
| 35 |
|
---|
| 36 | JPanel jpanel = createDemoPanel();
|
---|
| 37 |
|
---|
| 38 | setContentPane(jpanel);
|
---|
| 39 |
|
---|
| 40 | pack();
|
---|
| 41 | RefineryUtilities.centerFrameOnScreen(this);
|
---|
| 42 | setVisible(true);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | private static JFreeChart createChart(XYDataset xydataset) {
|
---|
| 46 | SymbolAxis symbolaxis
|
---|
| 47 | = new SymbolAxis("Document ID", documentIDs);
|
---|
| 48 | SymbolAxis symbolaxis_0_
|
---|
| 49 | = new SymbolAxis("Indexes", metadataName);
|
---|
| 50 |
|
---|
| 51 | XYLineAndShapeRenderer xylineandshaperenderer
|
---|
| 52 | = new XYLineAndShapeRenderer(false, true);
|
---|
| 53 |
|
---|
| 54 | XYPlot xyplot = new XYPlot(xydataset,symbolaxis_0_,symbolaxis,
|
---|
| 55 | xylineandshaperenderer);
|
---|
| 56 | xyplot.setDomainGridlinePaint(Color.black);
|
---|
| 57 | xyplot.setRangeGridlinePaint(Color.black);
|
---|
| 58 |
|
---|
| 59 | NumberAxis domainAxis = (NumberAxis)xyplot.getDomainAxis();
|
---|
| 60 | domainAxis.setAutoTickUnitSelection(true);
|
---|
| 61 | double rangetick = 1;
|
---|
| 62 | domainAxis.setTickUnit(new NumberTickUnit(rangetick));
|
---|
| 63 |
|
---|
| 64 | xyplot.getRenderer().setSeriesPaint(0,Color.blue);
|
---|
| 65 | xyplot.getRenderer().setSeriesShape(0, xyplot.DEFAULT_LEGEND_ITEM_BOX);
|
---|
| 66 | JFreeChart jfreechart = new JFreeChart("",new Font("", Font.PLAIN, 12),xyplot,false);
|
---|
| 67 | return jfreechart;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | private static XYDataset createDataset() {
|
---|
| 71 |
|
---|
| 72 | XYSeries xyseries = new XYSeries("Series");
|
---|
| 73 |
|
---|
| 74 | for(int a= 0; a<dataset.size(); a++){
|
---|
| 75 |
|
---|
| 76 | int[] row = (int[])dataset.get(a);
|
---|
| 77 | //System.out.print
|
---|
| 78 | for(int b = 0; b<row.length; b++){
|
---|
| 79 | if(row[b]==1){xyseries.add(a,b);}
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | XYSeriesCollection xyseriescollection = new XYSeriesCollection();
|
---|
| 85 | xyseriescollection.addSeries(xyseries);
|
---|
| 86 | return xyseriescollection;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | public static JPanel createDemoPanel() {
|
---|
| 90 | return new ChartPanel(createChart(createDataset()));
|
---|
| 91 | }
|
---|
| 92 | public static void main(String[] strings) {
|
---|
| 93 | DrawSymbolAxis symbolaxisdemo1 = new DrawSymbolAxis("Symbolic Axis Demo", null, null, null);
|
---|
| 94 |
|
---|
| 95 | }
|
---|
| 96 | public void windowClosing(java.awt.event.WindowEvent event){
|
---|
| 97 | this.dispose();
|
---|
| 98 | }
|
---|
| 99 | }
|
---|