public MainFrame(int width, int height, String DBAddr, String DBUser, String DBPass) { // TODO Auto-generated constructor stub this.DBAddr = DBAddr; this.DBUser = DBUser; this.DBPass = DBPass; connectDB(DBAddr, DBUser, DBPass); graphVerticalSize = 0.25f; trafficDataset = new DefaultCategoryDataset(); trafficChart = ChartFactory.createStackedAreaChart( "node name : IP", "", "kb/s", trafficDataset, PlotOrientation.VERTICAL, true, true, false); initGraph(); initComponent(); this.setSize(width, height); this.setVisible(true); inset = this.getInsets(); pWidth = this.getWidth() - (inset.left + inset.right); pHeight = this.getHeight() - (inset.top + inset.bottom); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); insertTestData(); repaint(); }
/** JFreeChartオブジェクトを作成する */ private JFreeChart createChartObject(Document doc) { Element root = doc.getDocumentElement(); Element chartInfo = (Element) root.getElementsByTagName("ChartInfo").item(0); String chartTitle = chartInfo.getElementsByTagName("Title").item(0).getFirstChild().getNodeValue(); this.chartType = chartInfo.getElementsByTagName("Type").item(0).getFirstChild().getNodeValue(); String categoryLabel = ((Element) chartInfo.getElementsByTagName("Category").item(0)) .getElementsByTagName("Label") .item(0) .getFirstChild() .getNodeValue(); Element firstSeries = (Element) ((Element) chartInfo.getElementsByTagName("SeriesList").item(0)) .getElementsByTagName("Series") .item(0); String firstSeriesLabel = firstSeries.getElementsByTagName("Label").item(0).getFirstChild().getNodeValue(); // データセットのリストを取得 this.dataSetList = this.getDatasetList(doc); // 棒チャート(Series数に関わらない) if (this.chartType.equals("VerticalBar") || this.chartType.equals("HorizontalBar") || this.chartType.equals("VerticalMultiBar") || this.chartType.equals("HorizontalMultiBar")) { chart = ChartFactory.createBarChart( chartTitle, categoryLabel, firstSeriesLabel, (CategoryDataset) this.dataSetList.get(0), getLayoutFromDoc(doc), false, false, false); } // 3D棒チャート(Series数に関わらない) else if (this.chartType.equals("Vertical3D_Bar") || this.chartType.equals("Horizontal3D_Bar") || this.chartType.equals("VerticalMulti3D_Bar") || this.chartType.equals("HorizontalMulti3D_Bar")) { chart = ChartFactory.createBarChart3D( chartTitle, categoryLabel, firstSeriesLabel, (CategoryDataset) this.dataSetList.get(0), getLayoutFromDoc(doc), false, false, false); } // 積み上げ棒チャート else if ((this.chartType.equals("VerticalStackedBar")) || (this.chartType.equals("HorizontalStackedBar"))) { chart = ChartFactory.createStackedBarChart( chartTitle, categoryLabel, firstSeriesLabel, (CategoryDataset) this.dataSetList.get(0), getLayoutFromDoc(doc), false, false, false); } // 3D積み上げ棒チャート else if ((this.chartType.equals("VerticalStacked3D_Bar")) || (this.chartType.equals("HorizontalStacked3D_Bar"))) { chart = ChartFactory.createStackedBarChart3D( chartTitle, categoryLabel, firstSeriesLabel, (CategoryDataset) this.dataSetList.get(0), getLayoutFromDoc(doc), false, false, false); } // 折れ線チャート(Series数に関わらない) else if ((this.chartType.equals("Line")) || (this.chartType.equals("MultiLine"))) { chart = ChartFactory.createLineChart( chartTitle, categoryLabel, firstSeriesLabel, (CategoryDataset) this.dataSetList.get(0), PlotOrientation.VERTICAL, false, false, false); } // 面チャート(Series数に関わらない) else if ((this.chartType.equals("Area")) || (this.chartType.equals("MultiArea"))) { chart = ChartFactory.createAreaChart( chartTitle, categoryLabel, firstSeriesLabel, (CategoryDataset) this.dataSetList.get(0), PlotOrientation.VERTICAL, false, false, false); } // 積み上げ面チャート else if (this.chartType.equals("StackedArea")) { chart = ChartFactory.createStackedAreaChart( chartTitle, categoryLabel, firstSeriesLabel, (CategoryDataset) this.dataSetList.get(0), PlotOrientation.VERTICAL, false, false, false); } // 円チャート(Series数に関わらない) else if (this.chartType.equals("Pie")) { chart = ChartFactory.createPieChart( chartTitle, (PieDataset) this.dataSetList.get(0), false, false, false); } // 3D円チャート(Series数に関わらない) else if (this.chartType.equals("Pie_3D")) { chart = ChartFactory.createPieChart3D( chartTitle, (PieDataset) this.dataSetList.get(0), false, false, false); } // 複数円チャート(Series数が2以上) else if (this.chartType.equals("MultiPie")) { // 複数円チャート chart = ChartFactory.createMultiplePieChart( chartTitle, (CategoryDataset) this.dataSetList.get(0), TableOrder.BY_ROW, false, false, false); } return chart; }