List of usage examples for org.jfree.chart ChartPanel setBackground
@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.") public void setBackground(Color bg)
From source file:lu.lippmann.cdb.weka.SilhouetteUtil.java
/** * /* w ww .j a v a2 s. c om*/ * @param sils * @return */ public static JPanel buildSilhouettePanel(final Instances ds, final WekaClusteringResult result) { final Map<Integer, List<Double>> sils = computeSilhouette(ds, result); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); final JFreeChart chart = ChartFactory.createBarChart("Silhouette", "Category", "Value", dataset, PlotOrientation.HORIZONTAL, true, true, false); int nbClass = sils.keySet().size(); int id = 0; double minValue = 0; int counter[][] = new int[nbClass][4]; for (int i = 0; i < nbClass; i++) { final double[] tree = ArrayUtils.toPrimitive(sils.get(i).toArray(new Double[0])); for (double val : tree) { if (val > 0.75) { dataset.addValue(val, "Cluster " + i + " ++", "" + id); counter[i][0]++; } else if (val > 0.50) { dataset.addValue(val, "Cluster " + i + " +", "" + id); counter[i][1]++; } else if (val > 0.25) { dataset.addValue(val, "Cluster " + i + " =", "" + id); counter[i][2]++; } else { dataset.addValue(val, "Cluster " + i + " -", "" + id); counter[i][3]++; } if (val < minValue) { minValue = val; } id++; } } final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); categoryplot.setBackgroundPaint(Color.WHITE); categoryplot.getDomainAxis().setVisible(false); categoryplot.setDomainGridlinesVisible(false); categoryplot.setRangeGridlinesVisible(false); categoryplot.getRangeAxis().setRange(minValue, 1.0); //Add line markers ValueMarker target = new ValueMarker(0.75); target.setPaint(Color.BLACK); target.setLabel(" ++"); target.setLabelAnchor(RectangleAnchor.TOP_LEFT); target.setLabelTextAnchor(TextAnchor.TOP_LEFT); categoryplot.addRangeMarker(target); target = new ValueMarker(0.5); target.setPaint(Color.BLACK); target.setLabel(" +"); target.setLabelAnchor(RectangleAnchor.TOP_LEFT); target.setLabelTextAnchor(TextAnchor.TOP_LEFT); categoryplot.addRangeMarker(target); target = new ValueMarker(0.25); target.setPaint(Color.BLACK); target.setLabel(" ="); target.setLabelAnchor(RectangleAnchor.TOP_LEFT); target.setLabelTextAnchor(TextAnchor.TOP_LEFT); categoryplot.addRangeMarker(target); target = new ValueMarker(0); target.setPaint(Color.BLACK); target.setLabel(" -"); target.setLabelAnchor(RectangleAnchor.TOP_LEFT); target.setLabelTextAnchor(TextAnchor.TOP_LEFT); categoryplot.addRangeMarker(target); //Remove visual effects on bar final BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setBarPainter(new StandardBarPainter()); //set bar colors int p = 0; final int max = ColorHelper.COLORBREWER_SEQUENTIAL_PALETTES.size(); for (int i = 0; i < nbClass; i++) { final Color[] color = new ArrayList<Color[]>(ColorHelper.COLORBREWER_SEQUENTIAL_PALETTES.values()) .get((max - i) % max); final int nbColors = color.length; for (int k = 0; k < counter[i].length; k++) { if (counter[i][k] > 0) barrenderer.setSeriesPaint(p++, color[(nbColors - k - 3) % nbColors]); } } //remove blank line between bars barrenderer.setItemMargin(-dataset.getRowCount()); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setMouseWheelEnabled(true); chartPanel.setPreferredSize(new Dimension(1200, 900)); chartPanel.setBorder(new TitledBorder("Silhouette plot")); chartPanel.setBackground(Color.WHITE); chart.setTitle(""); return chartPanel; }
From source file:lu.lippmann.cdb.lab.mds.MDSViewBuilder.java
/** * // w w w. j av a 2 s . c o m * @param clusters */ public static void buildKMeansChart(final List<Instances> clusters) { final XYSeriesCollection dataset = new XYSeriesCollection(); final JFreeChart chart = ChartFactory.createScatterPlot("", // title "X", "Y", // axis labels dataset, // dataset PlotOrientation.VERTICAL, true, // legend? yes true, // tooltips? yes false // URLs? no ); final XYPlot xyPlot = (XYPlot) chart.getPlot(); ((NumberAxis) xyPlot.getDomainAxis()).setTickUnit(new NumberTickUnit(2.0)); ((NumberAxis) xyPlot.getRangeAxis()).setTickUnit(new NumberTickUnit(2.0)); Attribute clsAttribute = null; int nbClass = 1; Instances cluster0 = clusters.get(0); if (cluster0.classIndex() != -1) { clsAttribute = cluster0.classAttribute(); nbClass = clsAttribute.numValues(); } if (nbClass <= 1) { dataset.addSeries(new XYSeries("Serie #1", false)); } else { for (int i = 0; i < nbClass; i++) { dataset.addSeries(new XYSeries(clsAttribute.value(i), false)); } } final XYToolTipGenerator gen = new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset dataset, int series, int item) { return "TODO"; } }; for (int i = 0; i < nbClass; i++) { dataset.getSeries(i).clear(); xyPlot.getRenderer().setSeriesToolTipGenerator(i, gen); } final int nbClusters = clusters.size(); for (int i = 0; i < nbClusters; i++) { Instances instances = clusters.get(i); final int nbInstances = instances.numInstances(); for (int j = 0; j < nbInstances; j++) { final Instance oInst = instances.instance(j); dataset.getSeries(i).add(oInst.value(0), oInst.value(1)); } } final TitledBorder titleBorder = new TitledBorder("Kmeans of projection"); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setMouseWheelEnabled(true); chartPanel.setPreferredSize(new Dimension(1200, 900)); chartPanel.setBorder(titleBorder); chartPanel.setBackground(Color.WHITE); JXFrame frame = new JXFrame(); frame.getContentPane().add(chartPanel); frame.setVisible(true); frame.pack(); }
From source file:lu.lippmann.cdb.lab.mds.MDSViewBuilder.java
/** * // w ww .jav a 2s.co m */ public static JXPanel buildMDSViewFromDataSet(final Instances instances, final MDSResult mdsResult, final int maxInstances, final Listener<Instances> listener, final String... attrNameToUseAsPointTitle) throws Exception { final XYSeriesCollection dataset = new XYSeriesCollection(); final JFreeChart chart = ChartFactory.createScatterPlot("", // title "X", "Y", // axis labels dataset, // dataset PlotOrientation.VERTICAL, attrNameToUseAsPointTitle.length == 0, // legend? true, // tooltips? yes false // URLs? no ); final XYPlot xyPlot = (XYPlot) chart.getPlot(); xyPlot.setBackgroundPaint(Color.WHITE); xyPlot.getDomainAxis().setTickLabelsVisible(false); xyPlot.getRangeAxis().setTickLabelsVisible(false); //FIXME : should be different for Shih if (!mdsResult.isNormalized()) { String stress = FormatterUtil.DECIMAL_FORMAT .format(ClassicMDS.getKruskalStressFromMDSResult(mdsResult)); chart.setTitle(mdsResult.getCInstances().isCollapsed() ? "Collapsed MDS(Instances=" + maxInstances + ",Stress=" + stress + ")" : "MDS(Stress=" + stress + ")"); } else { chart.setTitle(mdsResult.getCInstances().isCollapsed() ? "Collapsed MDS(Instances=" + maxInstances + ")" : "MDS"); } final SimpleMatrix coordinates = mdsResult.getCoordinates(); buildFilteredSeries(mdsResult, xyPlot, attrNameToUseAsPointTitle); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setMouseWheelEnabled(true); chartPanel.setPreferredSize(new Dimension(1200, 900)); chartPanel.setBorder(new TitledBorder("MDS Projection")); chartPanel.setBackground(Color.WHITE); final JButton selectionButton = new JButton("Select data"); selectionButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final org.jfree.data.Range XDomainRange = xyPlot.getDomainAxis().getRange(); final org.jfree.data.Range YDomainRange = xyPlot.getRangeAxis().getRange(); final Instances cInstances = mdsResult.getCollapsedInstances(); final Instances selectedInstances = new Instances(cInstances, 0); List<Instances> clusters = null; if (mdsResult.getCInstances().isCollapsed()) { clusters = mdsResult.getCInstances().getCentroidMap().getClusters(); } for (int i = 0; i < cInstances.numInstances(); i++) { final Instance centroid = instances.instance(i); if (XDomainRange.contains(coordinates.get(i, 0)) && YDomainRange.contains(coordinates.get(i, 1))) { if (mdsResult.getCInstances().isCollapsed()) { if (clusters != null) { final Instances elementsOfCluster = clusters.get(i); final int nbElements = elementsOfCluster.numInstances(); for (int k = 0; k < nbElements; k++) { selectedInstances.add(elementsOfCluster.get(k)); } } } else { selectedInstances.add(centroid); } } } if (listener != null) { listener.onAction(selectedInstances); } } }); final JXPanel allPanel = new JXPanel(); allPanel.setLayout(new BorderLayout()); allPanel.add(chartPanel, BorderLayout.CENTER); final JXPanel southPanel = new JXPanel(); southPanel.add(selectionButton); allPanel.add(southPanel, BorderLayout.SOUTH); return allPanel; }
From source file:SystemAnomalies.bouncedLogInRate.java
public ChartPanel getChartPanel() { XYSeries series = new XYSeries("Annual Composite Production Vs Farmers Experience"); series.add(0, 0);//from w w w .ja v a 2 s. co m series.add(1, 100); series.add(2, 100); series.add(3, 100); series.add(4, 120); series.add(5, 120); series.add(6, 1040); series.add(7, 1040); series.add(8, 1040); series.add(9, 2000); series.add(10, 2000); series.add(11, 100); series.add(12, 100); series.add(13, 100); series.add(14, 120); series.add(15, 120); series.add(16, 1040); series.add(17, 1040); series.add(18, 1040); series.add(19, 2000); series.add(20, 2000); series.add(21, 1845); series.add(22, 1040); series.add(23, 2000); // Add the series to your data set XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); // Generate the graph JFreeChart chart = ChartFactory.createXYLineChart("Sign-in Bounce off Rate", // Title "Time of Day", // x-axis Label "Number of Attempts", // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setBackground(Color.WHITE); chartPanel.setBounds(2, 5, 750, 500); chartPanel.setBorder(new LineBorder(Color.decode("#f5f5f5"), 2)); return chartPanel; }
From source file:de.rbs90.fwdisp.settingsgui.gui.tabs.statistics.TypeStatisticsPanel.java
public TypeStatisticsPanel() { setName("EinsatzTyp"); setLayout(new BorderLayout()); DefaultPieDataset dataset = new DefaultPieDataset(); HashMap<String, Integer> alarmCount = new HashMap<>(); try {// w ww . j av a 2 s.com ResultSet resultSet = Starter.getDatabase().getStatement() .executeQuery("SELECT TYPE, COUNT(*) AS COUNT FROM ALARMHISTORY GROUP BY TYPE"); while (resultSet.next()) { String type = resultSet.getString("TYPE"); if (type.isEmpty()) type = "unbekannt"; int count = resultSet.getInt("COUNT"); type += " (" + count + ")"; alarmCount.put(type, count); } } catch (SQLException e) { e.printStackTrace(); } for (String key : alarmCount.keySet()) { dataset.setValue(key, alarmCount.get(key)); } JFreeChart chart = ChartFactory.createPieChart3D("Einsatztypen", dataset, false, false, false); chart.setBackgroundPaint(getBackground()); ChartPanel panel = new ChartPanel(chart); panel.setPopupMenu(null); panel.setBackground(getBackground()); add(panel, BorderLayout.CENTER); }
From source file:room.utilization.PieChart.java
private JPanel createPanel() { JFreeChart chart = null;/*from w ww . j av a 2 s . c o m*/ ChartPanel panel = null; chart = createChart(createDataset()); panel = new ChartPanel(chart); panel.setBackground(Color.WHITE); return panel; }
From source file:room.utilization.BarGraph.java
private JPanel createPanel() { JFreeChart graph = null;//from w w w .j av a 2 s. c o m ChartPanel panel = null; graph = createGraph(createDataset()); panel = new ChartPanel(graph); panel.setBackground(Color.WHITE); return panel; }
From source file:UI.MainViewPanel.java
public ChartPanel getPanel5(Metric5 m5) { int totalRiskCount = m5.totalCriticalCount + m5.totalHighCount + m5.totalLowCount + m5.totalMediumCount; String[][] risks = new String[totalRiskCount][3]; BarChart barChart = new BarChart(m5.totalCriticalCount, m5.totalHighCount, m5.totalMediumCount, m5.totalLowCount, 0, "", risks); ChartPanel thisChart = barChart.drawBarChart(); thisChart.setBackground(Color.white); JFreeChart chart = thisChart.getChart(); chart.setBackgroundPaint(new Color(0, 0, 0, 0)); Plot plot = chart.getPlot();//from www . j a v a 2 s . c om plot.setBackgroundPaint(chartBackgroundColor); return thisChart; }
From source file:UI.MainViewPanel.java
public ChartPanel getPanel1(Metric1 m1) { int totalRiskCount = m1.totalCriticalCount + m1.totalHighCount + m1.totalLowCount + m1.totalMediumCount; String[][] risks = new String[totalRiskCount][3]; PieChart pieChart = new PieChart(m1.totalCriticalCount, m1.totalHighCount, m1.totalMediumCount, m1.totalLowCount, "", risks, true); ChartPanel thisChart = pieChart.drawPieChart(); thisChart.setBackground(Color.white); JFreeChart chart = thisChart.getChart(); chart.setBackgroundPaint(new Color(0, 0, 0, 0)); Plot plot = chart.getPlot();//from w w w .ja v a 2s .com plot.setBackgroundPaint(chartBackgroundColor); return thisChart; }
From source file:UI.MainViewPanel.java
public ChartPanel getPanel4(Metric4 m4) { int totalRiskCount = m4.totalCriticalCount + m4.totalHighCount + m4.totalLowCount + m4.totalMediumCount; String[][] risks = new String[totalRiskCount][3]; PieChart pieChart = new PieChart(m4.totalCriticalCount, m4.totalHighCount, m4.totalMediumCount, m4.totalLowCount, "", risks, true); ChartPanel thisChart = pieChart.drawPieChart(); thisChart.setBackground(Color.white); JFreeChart chart = thisChart.getChart(); chart.setBackgroundPaint(new Color(0, 0, 0, 0)); Plot plot = chart.getPlot();// ww w . ja va2s . c o m plot.setBackgroundPaint(chartBackgroundColor); return thisChart; }