List of usage examples for org.jfree.chart ChartPanel setSize
public void setSize(int width, int height)
From source file:views.Student_Home.java
private void populateTasks() { ArrayList taskList = studentActions.fetchTasks(); while (taskModel.getRowCount() != 0) { taskModel.removeRow(taskModel.getRowCount() - 1); }/* w w w .ja v a 2 s . c o m*/ Task task = new Task(); Date currDate = new Date(); int totalTime = 0; int timePassed = 0; for (int i = 0; i < taskList.size(); i++) { task = (Task) taskList.get(i); this.taskLinkedList.add(task.getTaskId()); if (currDate.before(task.getStartDate())) { String[] str = { task.getTaskId(), task.getTaskDescription(), task.getProjectId(), "Up coming" }; taskModel.insertRow(taskModel.getRowCount(), str); } else { String[] str = { task.getTaskId(), task.getTaskDescription(), task.getProjectId(), "In progress" }; taskModel.insertRow(taskModel.getRowCount(), str); timePassed = timePassed + (currDate.getDate() - task.getStartDate().getDate()); } totalTime = totalTime + (task.getEndDate().getDate() - task.getStartDate().getDate()); } DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Task completed", timePassed); dataset.setValue("Pending Tasks", totalTime - timePassed); JFreeChart taskStatusChart = ChartFactory.createPieChart("Tasks completion status", dataset, true, true, true); PiePlot piePlot = (PiePlot) taskStatusChart.getPlot(); ChartPanel chartPanel = new ChartPanel(taskStatusChart); chartPanel.setSize(323, 303); chartPanel.setVisible(true); //chartPanel.setLocation(500, 200); taskPieChart.removeAll(); taskPieChart.add(chartPanel); taskPieChart.updateUI(); taskPieChart.repaint(); }
From source file:GUI.Starts.java
private void initGraphs() { XYDataset datasets = createDataset(); JFreeChart chart = ChartFactory.createXYLineChart("", "Periods", "Price", datasets, PlotOrientation.VERTICAL, true, true, false); ChartPanel cp = new ChartPanel(chart); cp.setMouseWheelEnabled(true);//w w w . j a v a 2s. c o m cp.setSize(jPanel1.getWidth(), jPanel1.getHeight()); cp.setVisible(true); jPanel1.add(cp); jPanel1.validate(); }
From source file:OrdenacaoGUI.java
private void printGraph() { long tempo;//from w w w . ja v a 2 s .c om try { // conjunto de dados do grafico XYSeriesCollection dataset = new XYSeriesCollection(); // series de dados a serem exibidas no grafico int seriesSize = 5; XYSeries[] series = new XYSeries[seriesSize]; // adiciona as legendas de cada serie String[] legendas = { "Comb", "Shell", "Heap", "Radix", "Counting" }; for (int i = 0; i < seriesSize; ++i) { series[i] = new XYSeries(legendas[i]); } // executa 180 pontos no eixo de tamanho for (int i = 0; i < 180; ++i) { // o tamanho incrementado de 1000 em 1000 int size = (i + 1) * 1000; // gera um vetor de valores aleatorios com o tamanho determinado int[] valores = new int[size]; fillRandom(valores); int[] novo; // executa para cada serie for (int j = 0; j < seriesSize; ++j) { // cria uma copia dos valores gerados, para manter o vetor original intacto e igual para todos os algoritmos novo = Arrays.copyOf(valores, valores.length); // executa o algoritmo daquela serie e mede o tempo tempo = System.nanoTime(); runSort(novo, j); tempo = System.nanoTime() - tempo; // adiciona o ponto (tamanho, tempo) na respectiva serie series[j].add(size, tempo); } } // adiciona todas as series ao conjunto de dados do grafico for (int i = 0; i < seriesSize; ++i) { dataset.addSeries(series[i]); } // cria o grafico com parametros personalizados String titulo = "Comparativo das Ordenaes"; String eixoy = "Tempo (ns)"; String eixox = "Tamanho"; boolean legenda = true; boolean tooltips = true; boolean urls = true; JFreeChart graf = ChartFactory.createXYLineChart(titulo, eixox, eixoy, dataset, PlotOrientation.VERTICAL, legenda, tooltips, urls); ChartPanel myChartPanel = new ChartPanel(graf, true); myChartPanel.setSize(jPanelGrafico.getWidth(), jPanelGrafico.getHeight()); myChartPanel.setVisible(true); jPanelGrafico.removeAll(); jPanelGrafico.add(myChartPanel); jPanelGrafico.revalidate(); jPanelGrafico.repaint(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Visao.Relatorio.GraficoPerCapta.java
public void plotarGrafico(String chartTitle, ArrayList<Double> indices) { barChart = ChartFactory.createBarChart3D(chartTitle, "Estado", "?ndice de Reclamao", createDataset(indices), PlotOrientation.VERTICAL, true, true, false); barChart.setBackgroundPaint(Color.WHITE); CategoryPlot p = barChart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(barChart); panel.setVisible(true);// w w w. j a va2s. c o m panel.setSize(screenSize.width - 210, screenSize.height - 140); this.add(panel); }
From source file:org.drugis.addis.gui.builder.NetworkMetaAnalysisView.java
private JComponent createRankProbChart() { final CategoryDataset dataset = d_pm.getRankProbabilityDataset(); final JFreeChart chart = ChartFactory.createBarChart("Rank Probability", "Treatment", "Probability", dataset, PlotOrientation.VERTICAL, true, true, false); chart.addSubtitle(new org.jfree.chart.title.ShortTextTitle(d_pm.getRankProbabilityRankChartNote())); final FormLayout layout = new FormLayout("fill:0:grow", "p, 3dlu, p"); final PanelBuilder builder = new PanelBuilder(layout); final CellConstraints cc = new CellConstraints(); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setSize(chartPanel.getPreferredSize().width, chartPanel.getPreferredSize().height + 1); chartPanel.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); builder.add(chartPanel, cc.xy(1, 1)); final ButtonBarBuilder2 bbuilder = new ButtonBarBuilder2(); bbuilder.addButton(createSaveImageButton(chart)); builder.add(bbuilder.getPanel(), cc.xy(1, 3)); return builder.getPanel(); }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * calculates the correct height with multiple iterations Domain and Range axes need to share the * same unit (e.g. mm)//from w w w .ja va2 s. c o m * * @param myChart * @param copyToNewPanel * @param dataWidth width of data * @param axis for width calculation * @return */ public static double calcHeightToWidth(ChartPanel myChart, double chartWidth, double estimatedHeight, int iterations, boolean copyToNewPanel) { // if(myChart.getChartRenderingInfo()==null || // myChart.getChartRenderingInfo().getChartArea()==null || // myChart.getChartRenderingInfo().getChartArea().getWidth()==0) // result double height = estimatedHeight; double lastH = height; makeChartResizable(myChart); // paint on a ghost panel JPanel parent = (JPanel) myChart.getParent(); JPanel p = copyToNewPanel ? new JPanel() : parent; if (copyToNewPanel) p.add(myChart, BorderLayout.CENTER); try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy panel==true) myChart.setSize((int) chartWidth, (int) estimatedHeight); myChart.paintImmediately(myChart.getBounds()); XYPlot plot = (XYPlot) myChart.getChart().getPlot(); ChartRenderingInfo info = myChart.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); Rectangle2D chartArea = info.getChartArea(); // calc title space: will be added later to the right plot size double titleWidth = chartArea.getWidth() - dataArea.getWidth(); double titleHeight = chartArea.getHeight() - dataArea.getHeight(); // calc right plot size with axis dim. // real plot width is given by factor; double realPW = chartWidth - titleWidth; // ranges ValueAxis domainAxis = plot.getDomainAxis(); org.jfree.data.Range x = domainAxis.getRange(); ValueAxis rangeAxis = plot.getRangeAxis(); org.jfree.data.Range y = rangeAxis.getRange(); // real plot height can be calculated by double realPH = realPW / x.getLength() * y.getLength(); // the real height height = realPH + titleHeight; // for next iteration estimatedHeight = height; if ((int) lastH == (int) height) break; else lastH = height; } } catch (Exception ex) { ex.printStackTrace(); } if (copyToNewPanel) { // reset to frame p.removeAll(); parent.add(myChart); } return height; }
From source file:srvclientmonitor.frmMain.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed JPanel panel = new JPanel(); getContentPane().add(panel);//from w w w. j a v a 2 s . c o m DefaultCategoryDataset data = new DefaultCategoryDataset(); //DefaultPieDataset data = new DefaultPieDataset(); //Para el Grafico PIE data.addValue(20, "OSP", "HOY"); data.addValue(99, "ETL", "HOY"); data.addValue(25, "LOR", "HOY"); data.addValue(12, "MOV", "HOY"); // Creando el Grafico //JFreeChart chart = ChartFactory.createPieChart( //JFreeChart chart = ChartFactory.createBarChart("Ejemplo Rapido de Grafico en un ChartFrame", "Mes", "Valor", data); JFreeChart chart = ChartFactory.createBarChart("", "", "", data, PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(Color.BLACK); chart.setTitle(""); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRangePannable(true); plot.setRangeGridlinesVisible(false); plot.setBackgroundAlpha(1); plot.setBackgroundPaint(Color.BLACK); plot.setForegroundAlpha(1); plot.setDomainCrosshairPaint(Color.WHITE); plot.setNoDataMessagePaint(Color.WHITE); plot.setOutlinePaint(Color.WHITE); plot.setRangeCrosshairPaint(Color.WHITE); plot.setRangeMinorGridlinePaint(Color.WHITE); plot.setRangeZeroBaselinePaint(Color.WHITE); // Paint p = new GradientPaint(0, 0, Color.white, 1000, 0, Color.green); // plot.setBackgroundPaint(p); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelPaint(Color.WHITE); rangeAxis.setAxisLinePaint(Color.WHITE); rangeAxis.setTickLabelPaint(Color.WHITE); rangeAxis.setVerticalTickLabels(true); //ChartUtilities.applyCurrentTheme(chart); // Crear el Panel del Grafico con ChartPanel ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setSize(300, 150); chartPanel.setBackground(Color.BLACK); chartPanel.setOpaque(false); chartPanel.setDomainZoomable(true); this.jPanel1.setSize(300, 200); this.jPanel1.setBackground(Color.DARK_GRAY); this.jPanel1.add(chartPanel); }
From source file:net.linra.AttendanceSystemFrame.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: jPanel4.removeAll();/* w ww.j ava2s .c o m*/ DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(4, "", "Last Month"); dataset.setValue(7, "", "Last Week"); dataset.setValue(3, "", "Yesterday"); dataset.setValue(Integer.parseInt(this.absentNumber.getText()), "", "Today"); JFreeChart chart = ChartFactory.createBarChart("Histgram of absent student", "Data", "Absent number", dataset, PlotOrientation.VERTICAL, true, true, false); ChartPanel p = new ChartPanel(chart); p.setSize(jPanel4.getWidth(), jPanel4.getHeight()); p.setVisible(true); jPanel4.add(p); jPanel4.repaint(); //ChartFrame frame = new ChartFrame("Chart1", chart); //frame.setVisible(true); System.out.println(Integer.parseInt(this.absentNumber.getText()) + ""); }
From source file:net.linra.AttendanceSystemFrame.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed JLabel[] labels = { student1, student2, student3, student4, student5, student6, student7, student8, student9, student10, student11, student12, student13, student14, student15, student16, student17, student18, student19, student20, student21, student22, student23, student24, student25 }; if (jList1.getModel().getSize() <= 0) { this.jButton1.setEnabled(false); } else {//from ww w.ja v a 2 s.co m int i = studentCombobox.getSelectedIndex(); String name = studentCombobox.getSelectedItem().toString(); for (JLabel label : labels) { if (name.equals(label.getText())) { label.setIcon( new javax.swing.ImageIcon(getClass().getResource("/net/linra/picpackage/present.png"))); } } this.absentNumber.setText((jList1.getModel().getSize() - 1) + ""); DefaultListModel model = (DefaultListModel) jList1.getModel(); model.removeElementAt(i); DefaultComboBoxModel model2 = (DefaultComboBoxModel) studentCombobox.getModel(); model2.removeElementAt(i); jPanel4.removeAll(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(4, "", "Last Month"); dataset.setValue(7, "", "Last Week"); dataset.setValue(3, "", "Yesterday"); dataset.setValue(Integer.parseInt(this.absentNumber.getText()), "", "Today"); JFreeChart chart = ChartFactory.createBarChart("Histgram of absent student", "Data", "Absent number", dataset, PlotOrientation.VERTICAL, true, true, false); ChartPanel p = new ChartPanel(chart); p.setSize(jPanel4.getWidth(), jPanel4.getHeight()); p.setVisible(true); jPanel4.add(p); jPanel4.repaint(); } }
From source file:ctPrincipal.Principal.java
public void criaGrafico() throws IOException { CategoryDataset cds = _grafico.createDataset(); String titulo = "Mdia Linha de varredura "; String eixoy = "Valores"; String txt_legenda = "Pixels"; boolean legenda = true; boolean tooltips = true; boolean urls = true; JFreeChart graf = ChartFactory.createLineChart(titulo, txt_legenda, eixoy, cds, PlotOrientation.VERTICAL, true, true, true);//from ww w .ja va 2s.c om ChartPanel myChartPanel = new ChartPanel(graf, true); myChartPanel.setSize(jPanel1.getWidth(), jPanel1.getHeight()); myChartPanel.setVisible(true); File lineChart = new File("OutputImg/grafico.jpeg"); ChartUtilities.saveChartAsJPEG(lineChart, graf, 256, 256); jLImgC.setIcon(new ImageIcon(lineChart.getAbsolutePath())); }