List of usage examples for org.jfree.chart ChartFactory createLineChart
public static JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:userinterface.Citizen.CitizenWorkAreaJPanel.java
private void graphButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphButtonActionPerformed JFreeChart lineChart = ChartFactory.createLineChart("Vital Sign Chart", "TimeStamp", "Vital Signs", createDataset(), PlotOrientation.VERTICAL, true, true, false); ChartFrame cf = new ChartFrame("Vital Sign Chart", lineChart); CategoryPlot plot = lineChart.getCategoryPlot(); // Stroke[] seriesStrokeArray = new Stroke[3]; // seriesStrokeArray[0] = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, // 1.0f, new float[]{10.0f, 6.0f}, 0.0f); // seriesStrokeArray[1] = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, // 1.0f, new float[]{6.0f, 6.0f}, 0.0f); // seriesStrokeArray[2] = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, // 1.0f, new float[]{2.0f, 6.0f}, 0.0f); // plot.setShadowGenerator(null); lineChart.setBackgroundPaint(Color.yellow); plot.setBackgroundPaint(Color.yellow); cf.setSize(450, 450);//from w ww . j a va 2 s .c o m cf.setVisible(true); }
From source file:charts.Chart.java
public static void PlotParallelCoordinates(String title, String x_axis_label, String y_axis_label, float[][] Md, int classes, int[] features, Vector featurestitles, Vector datatitles) { JFrame chartwindow = new JFrame(title); JFreeChart jfreechart = ChartFactory.createLineChart(title, x_axis_label, y_axis_label, null, PlotOrientation.VERTICAL, true, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setRangeGridlinePaint(Color.black); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); int lines = Md.length; int columns = Md[0].length; LineAndShapeRenderer[] lineandshaperenderer = new LineAndShapeRenderer[classes]; for (int i = 0; i < lineandshaperenderer.length; i++) { lineandshaperenderer[i] = new LineAndShapeRenderer(); lineandshaperenderer[i].setShapesVisible(true); lineandshaperenderer[i].setDrawOutlines(true); lineandshaperenderer[i].setUseFillPaint(true); lineandshaperenderer[i].setFillPaint(Color.white); lineandshaperenderer[i].setBaseStroke(new BasicStroke(2.0f)); }//from w w w.j a va 2 s . c o m int count = 0; for (int i = 0; i < lines; i++) { int classe = ((int) Md[i][columns - 1]); DefaultKeyedValues2DDataset dataset = new DefaultKeyedValues2DDataset(); int j = 0; double value = 0; while (j < features.length) { /*value recebe o valor da linha i e da coluna especificada pelo usuario, por meio do parametro de chegada features[]*/ value = Md[i][features[j]]; String strclasse = String.valueOf(classe); //especifico Marie-Anne /* if (classe == 0) { strclasse = "thi1"; lineandshaperenderer[classe].setSeriesPaint(0, Color.RED); Shape s0 = new Rectangle2D.Float(-3f, -3f, 6f, 6f); lineandshaperenderer[classe].setSeriesShape(0, s0); } else if (classe == 1) { strclasse = "controle"; lineandshaperenderer[classe].setSeriesPaint(0, Color.PINK); Shape s1 = new Ellipse2D.Float(-3f, -3f, 6f, 6f); lineandshaperenderer[classe].setSeriesShape(0, s1); } else if (classe == 2) { strclasse = "fotossntese"; lineandshaperenderer[classe].setSeriesPaint(0, Color.GREEN); int[] x = {-3, 0, 3}; int[] y = {-3, 3, -3}; int n = 3; Shape s2 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesShape(0, s2); } else if (classe == 3) { strclasse = "respirao"; int[] x = {-3, 0, 3}; int[] y = {3, -3, 3}; int n = 3; Shape s3 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesShape(0, s3); lineandshaperenderer[classe].setSeriesPaint(0, Color.BLUE); } else if (classe == 4) { strclasse = "sntese de tiamina"; lineandshaperenderer[classe].setSeriesPaint(0, Color.BLACK); Shape s4 = new Rectangle2D.Float(-1f, -3f, 1f, 6f); lineandshaperenderer[classe].setSeriesShape(0, s4); } else if (classe == 5) { strclasse = "gliclise"; int[] x = {-3, 0, 3, 0}; int[] y = {0, -3, 0, 3}; int n = 4; Shape s5 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesPaint(0, Color.ORANGE); lineandshaperenderer[classe].setSeriesShape(0, s5); } else if (classe == 6) { strclasse = "AT4G34200"; int[] x = {-3, 0, 3, 0}; int[] y = {0, -3, 0, 3}; int n = 4; Shape s5 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesPaint(0, Color.MAGENTA); lineandshaperenderer[classe].setSeriesShape(0, s5); } else if (classe == 7) { strclasse = "AT2G36530"; int[] x = {-3, 0, 3, 0}; int[] y = {0, -3, 0, 3}; int n = 4; Shape s5 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesPaint(0, Color.CYAN); lineandshaperenderer[classe].setSeriesShape(0, s5); } */ if (featurestitles != null) { if (datatitles != null) { dataset.addValue(value, strclasse, (String) featurestitles.get(features[j] + 1)); //datasets[i].addValue(Mo[lineindex[i]][c], label, (String) featurestitles.get(c + 1)); } else { dataset.addValue(value, strclasse, (String) featurestitles.get(features[j])); //datasets[i].addValue(Mo[lineindex[i]][c], label, (String) featurestitles.get(c)); } } else { dataset.addValue(value, strclasse, String.valueOf(features[j])); //datasets[i].addValue(Mo[lineindex[i]][c], label, String.valueOf(c)); } //dataset.addValue(value, String.valueOf(classe), String.valueOf(features[j])); j++; } categoryplot.setDataset(count, dataset); categoryplot.setRenderer(count, lineandshaperenderer[classe]); count++; } LegendItemCollection legends = categoryplot.getLegendItems(); LegendItemCollection newlegends = new LegendItemCollection(); for (int i = 0; i < classes; i++) { int l = 0; //especifico Marie-Anne String label1 = null; if (i == 0) { label1 = "thi1"; } else if (i == 1) { label1 = "controle"; } else if (i == 2) { label1 = "fotossntese"; } else if (i == 3) { label1 = "respirao"; } else if (i == 4) { label1 = "sntese de tiamina"; } else if (i == 5) { label1 = "gliclise"; } else if (i == 6) { label1 = "AT4G34200"; } else if (i == 7) { label1 = "AT2G36530"; } //String label1 = String.valueOf(i); String label2 = null; boolean found = false; do { label2 = legends.get(l).getLabel(); if (label1.equalsIgnoreCase(label2)) { found = true; } else { l++; } } while (!found && (l < lines)); if (found) { //newlegends.add(legends.get(l)); LegendItem li = new LegendItem(legends.get(l).getLabel(), legends.get(l).getDescription(), legends.get(l).getToolTipText(), legends.get(l).getURLText(), legends.get(l).isShapeVisible(), legends.get(l).getShape(), legends.get(l).isShapeFilled(), legends.get(l).getFillPaint(), legends.get(l).isShapeOutlineVisible(), legends.get(l).getOutlinePaint(), legends.get(l).getOutlineStroke(), legends.get(l).isLineVisible(), legends.get(l).getLine(), legends.get(l).getLineStroke(), legends.get(l).getLinePaint()); newlegends.add(li); } } categoryplot.setFixedLegendItems(newlegends); JPanel jpanel = new ChartPanel(jfreechart); jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight)); chartwindow.setContentPane(jpanel); chartwindow.pack(); RefineryUtilities.centerFrameOnScreen(chartwindow); chartwindow.setVisible(true); }
From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java
protected JFreeChart createLineChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart freeChart = ChartFactory.createLineChart(evaluateTextExpression(getChart().getTitleExpression()), evaluateTextExpression(((JRLinePlot) getPlot()).getCategoryAxisLabelExpression()), evaluateTextExpression(((JRLinePlot) getPlot()).getValueAxisLabelExpression()), (CategoryDataset) getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(), true, false);//from www .ja v a2s . co m configureChart(freeChart, getPlot()); CategoryPlot categoryPlot = (CategoryPlot) freeChart.getPlot(); JRLinePlot linePlot = (JRLinePlot) getPlot(); LineAndShapeRenderer lineRenderer = (LineAndShapeRenderer) categoryPlot.getRenderer(); boolean isShowShapes = linePlot.getShowShapes() == null ? true : linePlot.getShowShapes(); boolean isShowLines = linePlot.getShowLines() == null ? true : linePlot.getShowLines(); lineRenderer.setBaseShapesVisible(isShowShapes);//FIXMECHART check this lineRenderer.setBaseLinesVisible(isShowLines); //FIXME labels? // Handle the axis formating for the category axis configureAxis(categoryPlot.getDomainAxis(), linePlot.getCategoryAxisLabelFont(), linePlot.getCategoryAxisLabelColor(), linePlot.getCategoryAxisTickLabelFont(), linePlot.getCategoryAxisTickLabelColor(), linePlot.getCategoryAxisTickLabelMask(), linePlot.getCategoryAxisVerticalTickLabels(), linePlot.getOwnCategoryAxisLineColor(), getDomainAxisSettings(), (Comparable<?>) evaluateExpression(linePlot.getDomainAxisMinValueExpression()), (Comparable<?>) evaluateExpression(linePlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(categoryPlot.getRangeAxis(), linePlot.getValueAxisLabelFont(), linePlot.getValueAxisLabelColor(), linePlot.getValueAxisTickLabelFont(), linePlot.getValueAxisTickLabelColor(), linePlot.getValueAxisTickLabelMask(), linePlot.getValueAxisVerticalTickLabels(), linePlot.getOwnValueAxisLineColor(), getRangeAxisSettings(), (Comparable<?>) evaluateExpression(linePlot.getRangeAxisMinValueExpression()), (Comparable<?>) evaluateExpression(linePlot.getRangeAxisMaxValueExpression())); return freeChart; }
From source file:UserInfo_Frame.java
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed try {/* w ww . j a v a 2s . c o m*/ String query = "select date,pressure from UserInfo"; JDBCCategoryDataset dataset = new JDBCCategoryDataset(javaconnect.ConnectDB(), query); JFreeChart chart = ChartFactory.createLineChart("Query Chart", "Date", "Pressure", dataset, PlotOrientation.VERTICAL, false, true, true); BarRenderer renderer = null; CategoryPlot plot = null; renderer = new BarRenderer(); ChartFrame frame = new ChartFrame("Query Chart", chart); frame.setVisible(true); frame.setSize(400, 650); } catch (Exception e) { } }
From source file:ui.Analyze.java
private Component labane(LocalDate l) throws SQLException { org.jfree.data.category.DefaultCategoryDataset data = new org.jfree.data.category.DefaultCategoryDataset(); for (LocalDate l2 = l; l2.isBefore(l.plusWeeks(1)); l2 = l2.plusDays(1)) { Number u = getUntung(l2), r = getRugi(l2); data.addValue(u.longValue() - r.longValue(), "Laba", l2); }//from w w w. ja v a2 s .co m return new org.jfree.chart.ChartPanel(ChartFactory.createLineChart("Laba Bersih", "Periode", "Nilai", data, PlotOrientation.VERTICAL, true, true, false)); }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
protected JFreeChart createLineChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createLineChart( evaluateTextExpression(getChart().getTitleExpression()), evaluateTextExpression(((JRLinePlot) getPlot()).getCategoryAxisLabelExpression()), evaluateTextExpression(((JRLinePlot) getPlot()).getValueAxisLabelExpression()), (CategoryDataset) getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(), true, false);//from w w w . j a va 2 s.com configureChart(jfreeChart); CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot(); JRLinePlot linePlot = (JRLinePlot) getPlot(); LineAndShapeRenderer lineRenderer = (LineAndShapeRenderer) categoryPlot.getRenderer(); boolean isShowShapes = linePlot.getShowShapes() == null ? true : linePlot.getShowShapes(); boolean isShowLines = linePlot.getShowLines() == null ? true : linePlot.getShowLines(); lineRenderer.setBaseShapesVisible(isShowShapes);//FIXMECHART check this lineRenderer.setBaseLinesVisible(isShowLines); //FIXME labels? // Handle the axis formating for the category axis configureAxis(categoryPlot.getDomainAxis(), linePlot.getCategoryAxisLabelFont(), linePlot.getCategoryAxisLabelColor(), linePlot.getCategoryAxisTickLabelFont(), linePlot.getCategoryAxisTickLabelColor(), linePlot.getCategoryAxisTickLabelMask(), linePlot.getCategoryAxisVerticalTickLabels(), linePlot.getCategoryAxisLineColor(), false, (Comparable<?>) evaluateExpression(linePlot.getDomainAxisMinValueExpression()), (Comparable<?>) evaluateExpression(linePlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(categoryPlot.getRangeAxis(), linePlot.getValueAxisLabelFont(), linePlot.getValueAxisLabelColor(), linePlot.getValueAxisTickLabelFont(), linePlot.getValueAxisTickLabelColor(), linePlot.getValueAxisTickLabelMask(), linePlot.getValueAxisVerticalTickLabels(), linePlot.getValueAxisLineColor(), true, (Comparable<?>) evaluateExpression(linePlot.getRangeAxisMinValueExpression()), (Comparable<?>) evaluateExpression(linePlot.getRangeAxisMaxValueExpression())); return jfreeChart; }
From source file:jhplot.HChart.java
/** * Update the chart//from w ww . j a va 2s.co m * * @param N1 * location in X * @param N2 * location in Y */ public void update(int N1, int N2) { if (cdatPie[N1][N2] != null || cdatPie3D[N1][N2] != null || cdatBar[N1][N2] != null || cdatBar3D[N1][N2] != null || cdatLine[N1][N2] != null || cdatArea[N1][N2] != null || cdatPolar[N1][N2] != null) { if (cdatPie[N1][N2] != null) { chart[N1][N2] = ChartFactory.createPieChart(title[N1][N2], (PieDataset) cdatPie[N1][N2], true, true, true); } else if (cdatPie3D[N1][N2] != null) { chart[N1][N2] = ChartFactory.createPieChart3D(title[N1][N2], (PieDataset) cdatPie3D[N1][N2], true, true, true); PiePlot3D pieplot3d = (PiePlot3D) chart[N1][N2].getPlot(); // pieplot3d.setStartAngle(290D); // pieplot3d.setDirection(Rotation.CLOCKWISE); // pieplot3d.setForegroundAlpha(0.5F); pieplot3d.setBackgroundPaint(DEFAULT_BG_COLOR); } else if (cdatBar[N1][N2] != null) { chart[N1][N2] = ChartFactory.createBarChart(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatBar[N1][N2], PlotOrientation.VERTICAL, true, true, true); CategoryPlot lineplot = (CategoryPlot) chart[N1][N2].getPlot(); CategoryAxis yy = lineplot.getDomainAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); ValueAxis xx = lineplot.getRangeAxis(); xx.setTickLabelPaint(tickColor); xx.setTickLabelFont(tickFont); xx.setLabelPaint(labelColor); xx.setLabelFont(labelFont); xx.setAxisLineStroke(new BasicStroke(axisPenwidth)); xx.setAxisLinePaint(Color.black); } else if (cdatBar3D[N1][N2] != null) { chart[N1][N2] = ChartFactory.createBarChart3D(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatBar3D[N1][N2], PlotOrientation.VERTICAL, true, true, true); } else if (cdatLine[N1][N2] != null) { chart[N1][N2] = ChartFactory.createLineChart(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatLine[N1][N2], PlotOrientation.VERTICAL, true, true, true); CategoryPlot lineplot = (CategoryPlot) chart[N1][N2].getPlot(); lineplot.setOutlineStroke(new BasicStroke(axisPenwidth)); CategoryAxis yy = lineplot.getDomainAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); ValueAxis xx = lineplot.getRangeAxis(); xx.setTickLabelPaint(tickColor); xx.setTickLabelFont(tickFont); xx.setLabelPaint(labelColor); xx.setLabelFont(labelFont); xx.setAxisLineStroke(new BasicStroke(axisPenwidth)); xx.setAxisLinePaint(Color.black); LineAndShapeRenderer renderer = (LineAndShapeRenderer) lineplot.getRenderer(); renderer.setBaseStroke(new BasicStroke(linestroke)); for (int m = 0; m < cdatLine[N1][N2].getColumnCount() + 1; m++) renderer.setSeriesStroke(m, new BasicStroke(linestroke)); } else if (cdatPolar[N1][N2] != null) { chart[N1][N2] = ChartFactory.createPolarChart(title[N1][N2], (XYSeriesCollection) cdatPolar[N1][N2], true, true, true); PolarPlot lineplot = (PolarPlot) chart[N1][N2].getPlot(); ValueAxis yy = lineplot.getAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); } else if (cdatArea[N1][N2] != null) { chart[N1][N2] = ChartFactory.createAreaChart(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatArea[N1][N2], PlotOrientation.VERTICAL, true, true, true); CategoryPlot lineplot = (CategoryPlot) chart[N1][N2].getPlot(); CategoryAxis yy = lineplot.getDomainAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); ValueAxis xx = lineplot.getRangeAxis(); xx.setTickLabelPaint(tickColor); xx.setTickLabelFont(tickFont); xx.setLabelPaint(labelColor); xx.setLabelFont(labelFont); xx.setAxisLineStroke(new BasicStroke(axisPenwidth)); xx.setAxisLinePaint(Color.black); } chart[N1][N2].setAntiAlias(antiAlias); chart[N1][N2].setBorderPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBackgroundPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBorderVisible(false); cp[N1][N2].setChart(chart[N1][N2]); return; } for (int i = 0; i < indexdat[N1][N2]; i++) { if (type[N1][N2].get(i) == "array") xyplot[N1][N2].setRenderer(i, (StandardXYItemRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "f") xyplot[N1][N2].setRenderer(i, (XYLineAndShapeRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "h") xyplot[N1][N2].setRenderer(i, (XYBarRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "p") xyplot[N1][N2].setRenderer(i, (XYLineAndShapeRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "pe") xyplot[N1][N2].setRenderer(i, (XYErrorRenderer) (rdat[N1][N2].get(i))); // System.out.println(i); } chart[N1][N2] = new JFreeChart(title[N1][N2], JFreeChart.DEFAULT_TITLE_FONT, xyplot[N1][N2], true); chart[N1][N2].setAntiAlias(antiAlias); chart[N1][N2].setBorderPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBackgroundPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBorderVisible(false); cp[N1][N2].setChart(chart[N1][N2]); }
From source file:gskproject.Analyze.java
private void btnPersonGraphActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPersonGraphActionPerformed //System.out.println(); if (tblPersonVise.getSelectedRow() != -1) { String username = tablePersonWise.get(tblPersonVise.getSelectedRow()).get(0).toString(); int userID = dbOps.getUserID(username); java.sql.Date from;// w ww . j a v a2 s . c om java.sql.Date to; if (dtPFrom.getDate() == null && dtPTo.getDate() == null) { from = null; to = null; } else if (dtPFrom.getDate() == null) { from = null; to = new java.sql.Date(dtPTo.getDate().getTime()); } else if (dtPTo.getDate() == null) { from = new java.sql.Date(dtPFrom.getDate().getTime()); to = null; } else { from = new java.sql.Date(dtPFrom.getDate().getTime()); to = new java.sql.Date(dtPTo.getDate().getTime()); } Vector<Vector> eachPersonDates = new Vector<Vector>(); eachPersonDates = dbOps.getEachPersonObservation(from, to, userID); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart chart = null; Calendar start = Calendar.getInstance(); Calendar end = Calendar.getInstance(); for (Vector<Object> row : eachPersonDates) { start.setTime((Date) row.get(1)); end.setTime((Date) row.get(2)); dataset.addValue(end.get(Calendar.DAY_OF_YEAR) - start.get(Calendar.DAY_OF_YEAR), "First Aid", row.get(0).toString()); } chart = ChartFactory.createLineChart("All Departments VS All Accident Types", "Observation ID", "Days", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame(username + " Chart", chart); frame.setSize(700, 500); frame.setVisible(true); } else { JOptionPane.showMessageDialog(this, "Please select a person using table!"); } }
From source file:ui.Analyze.java
private void generateLaba(LocalDate ld1, LocalDate ld2) throws SQLException { org.jfree.data.category.DefaultCategoryDataset data = new org.jfree.data.category.DefaultCategoryDataset(); javax.swing.table.DefaultTableModel m = (javax.swing.table.DefaultTableModel) ketTbl.getModel(); ketTbl.removeAll();/*www. j av a 2s . c om*/ LocalDate awal, akhir, loop; boolean min; if (ld2.isBefore(ld1)) { awal = ld2; akhir = ld1; min = false; } else { akhir = ld2; awal = ld1; min = true; } for (loop = awal; min ? !loop.isAfter(akhir) : !loop.isBefore(akhir);) { Number u = getUntung(loop), r = getRugi(loop); data.addValue(u.longValue() - r.longValue(), "Laba", loop); m.addRow(new Object[] { loop, u.longValue() - r.longValue() }); if (min) loop = loop.plusDays(1); else loop = loop.minusDays(1); } org.jfree.chart.ChartPanel cp = new org.jfree.chart.ChartPanel(ChartFactory.createLineChart("Laba", "Tanggal", "Laba", data, PlotOrientation.VERTICAL, true, true, false)); cp.setSize(pnlLaba.getSize()); if (0 < pnlLaba.getComponentCount()) pnlLaba.removeAll(); pnlLaba.add(cp); }
From source file:charts.Chart.java
public static void PlotMeanParallelCoordinates(String title, String x_axis_label, String y_axis_label, float[][] Md, int classes, int[] features, Vector featurestitles, Vector datatitles) { JFrame chartwindow = new JFrame(title); JFreeChart jfreechart = ChartFactory.createLineChart(title, x_axis_label, y_axis_label, null, PlotOrientation.VERTICAL, true, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setRangeGridlinePaint(Color.black); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); int lines = Md.length; int columns = Md[0].length; LineAndShapeRenderer[] lineandshaperenderer = new LineAndShapeRenderer[classes]; //lineandshaperenderer[0] = new LineAndShapeRenderer();//(LineAndShapeRenderer) categoryplot.getRenderer(); //lineandshaperenderer[0].setShapesVisible(true); //lineandshaperenderer[0].setDrawOutlines(true); //lineandshaperenderer[0].setUseFillPaint(true); //lineandshaperenderer[0].setFillPaint(Color.white); for (int i = 0; i < lineandshaperenderer.length; i++) { lineandshaperenderer[i] = new LineAndShapeRenderer(); lineandshaperenderer[i].setShapesVisible(true); lineandshaperenderer[i].setDrawOutlines(true); lineandshaperenderer[i].setUseFillPaint(true); lineandshaperenderer[i].setFillPaint(Color.white); lineandshaperenderer[i].setBaseStroke(new BasicStroke(2.0f)); }//from w w w . j a v a2 s. co m double[][][] valuesperclasse = new double[columns][classes][2]; /* a primeira coluna acumula a soma dos valores, e a segunda coluna conta o numero de vezes que recebeu um valor, para gerar a media aritmetica dos valores de cada atributo para cada uma das classes.*/ for (int i = 0; i < lines; i++) { int classe = ((int) Md[i][columns - 1]); int j = 0; while (j < features.length) { valuesperclasse[features[j]][classe][0] += Md[i][features[j]]; valuesperclasse[features[j]][classe][1]++; j++; } } for (int i = 0; i < classes; i++) { DefaultKeyedValues2DDataset dataset = new DefaultKeyedValues2DDataset(); double meanvaluej = 0; for (int j = 0; j < features.length; j++) { meanvaluej = valuesperclasse[features[j]][i][0] / valuesperclasse[features[j]][i][1]; String strclasse = String.valueOf(i); //especifico Marie-Anne /* if (i == 0) { strclasse = "thi1"; lineandshaperenderer[i].setSeriesPaint(0, Color.RED); Shape s0 = new Rectangle2D.Float(-3f, -3f, 6f, 6f); lineandshaperenderer[i].setSeriesShape(0, s0); } else if (i == 1) { strclasse = "controle"; lineandshaperenderer[i].setSeriesPaint(0, Color.PINK); Shape s1 = new Ellipse2D.Float(-3f, -3f, 6f, 6f); lineandshaperenderer[i].setSeriesShape(0, s1); } else if (i == 2) { strclasse = "fotossntese"; lineandshaperenderer[i].setSeriesPaint(0, Color.GREEN); int[] x = {-3, 0, 3}; int[] y = {-3, 3, -3}; int n = 3; Shape s2 = new Polygon(x, y, n); lineandshaperenderer[i].setSeriesShape(0, s2); } else if (i == 3) { strclasse = "respirao"; int[] x = {-3, 0, 3}; int[] y = {3, -3, 3}; int n = 3; Shape s3 = new Polygon(x, y, n); lineandshaperenderer[i].setSeriesShape(0, s3); lineandshaperenderer[i].setSeriesPaint(0, Color.BLUE); } else if (i == 4) { strclasse = "sntese de tiamina"; lineandshaperenderer[i].setSeriesPaint(0, Color.BLACK); Shape s4 = new Rectangle2D.Float(-1f, -3f, 1f, 6f); lineandshaperenderer[i].setSeriesShape(0, s4); } else if (i == 5) { strclasse = "gliclise"; int[] x = {-3, 0, 3, 0}; int[] y = {0, -3, 0, 3}; int n = 4; Shape s5 = new Polygon(x, y, n); lineandshaperenderer[i].setSeriesPaint(0, Color.ORANGE); lineandshaperenderer[i].setSeriesShape(0, s5); } else if (i == 6) { strclasse = "AT4G34200"; int[] x = {-3, 0, 3, 0}; int[] y = {0, -3, 0, 3}; int n = 4; Shape s5 = new Polygon(x, y, n); lineandshaperenderer[i].setSeriesPaint(0, Color.MAGENTA); lineandshaperenderer[i].setSeriesShape(0, s5); } else if (i == 7) { strclasse = "AT2G36530"; int[] x = {-3, 0, 3, 0}; int[] y = {0, -3, 0, 3}; int n = 4; Shape s5 = new Polygon(x, y, n); lineandshaperenderer[i].setSeriesPaint(0, Color.CYAN); lineandshaperenderer[i].setSeriesShape(0, s5); } */ if (featurestitles != null) { if (datatitles != null) { dataset.addValue(meanvaluej, strclasse, (String) featurestitles.get(features[j] + 1)); //datasets[i].addValue(Mo[lineindex[i]][c], label, (String) featurestitles.get(c + 1)); } else { dataset.addValue(meanvaluej, strclasse, (String) featurestitles.get(features[j])); //datasets[i].addValue(Mo[lineindex[i]][c], label, (String) featurestitles.get(c)); } } else { dataset.addValue(meanvaluej, strclasse, String.valueOf(features[j])); //dataset.addValue(meanvaluej, String.valueOf(i), String.valueOf(features[j])); } //dataset.addValue(meanvaluej, String.valueOf(i), String.valueOf(features[j])); } categoryplot.setDataset(i, dataset); categoryplot.setRenderer(i, lineandshaperenderer[i]); } JPanel jpanel = new ChartPanel(jfreechart); jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight)); chartwindow.setContentPane(jpanel); chartwindow.pack(); RefineryUtilities.centerFrameOnScreen(chartwindow); chartwindow.setVisible(true); }