List of usage examples for org.jfree.chart ChartColor ChartColor
public ChartColor(int r, int g, int b)
From source file:de.perdian.apps.dashboard.support.chart.ChartCreator.java
/** * Creates a new instance based upon the values made available in the given * request/*from w w w. j av a 2 s .c o m*/ */ public ChartCreator(AbstractChartRequest request) { if (request.getImageColor() != null && request.getImageColor().length() > 0) { try { Matcher regexMatcher = Pattern.compile("rgb\\((.*?), (.*?), (.*?)\\)") .matcher(request.getImageColor()); if (regexMatcher.matches()) { this.setColor(new ChartColor(Integer.parseInt(regexMatcher.group(1).trim()), Integer.parseInt(regexMatcher.group(2).trim()), Integer.parseInt(regexMatcher.group(3).trim()))); } } catch (Exception e) { // Ignore any exception here - we simply use the color that was // assigned as default value } } this.setWidth(request.getImageWidth()); this.setHeight(request.getImageHeight()); this.setStrokeDefinitions(new ArrayList<ChartStrokeDefinition>()); }
From source file:AnalysisModule.DataAnalysis.java
public void simulateBitmapAnalyse(List<Scenario> lstScenario) throws Exception { Double valor;// w w w. j a v a 2 s. c o m bitmapAnalyse(lstScenario); for (Scenario scenario : lstScenario) { for (Topology topology : scenario.lstTopology) { File table = new File(topology.getSaidasDir() + "Resumo.csv"); FileWriter fw = new FileWriter(table); PrintWriter pw = new PrintWriter(fw); pw.write(";Instancia 1;Instancia 2;Instancia 3;Instancia 4\n"); pw.write("Tipo;BITMAP;BITMAP;BITMAP;COUNTER\n"); pw.write("Size(KB);"); for (Instance instance : topology.getLstInstance()) { pw.write(String.format("%6.2f", (instance.getBitMapSize() / 8.0) / 1024.0) + ";"); } pw.write("\n"); pw.write("Treshold;0,1;0,3;0,5;-\n"); pw.write("RMSE;"); for (Instance instance : topology.getLstInstance()) { double error = 0; int counter = 0; for (int i = 0; i < topology.getNumberOfSwitches(); i++) { for (int j = i + 1; j < topology.getNumberOfSwitches(); j++) { error += Math.pow(topology.getTrafficMatrix()[i][j] - instance.trafficMatrix[i][j], 2); counter++; } } error = Math.sqrt(error / counter); System.out.println("RMSE: " + error); pw.write(String.format("%10.8f", error) + ";"); } pw.write("\n"); pw.write("RMSRE;"); for (Instance instance : topology.getLstInstance()) { double error = 0; int counter = 0; double T = 0; for (int i = 0; i < topology.getNumberOfSwitches(); i++) { for (int j = i + 1; j < topology.getNumberOfSwitches(); j++) { if (instance.trafficMatrix[i][j] > T) { error += Math.pow((topology.getTrafficMatrix()[i][j] - instance.trafficMatrix[i][j]) / instance.trafficMatrix[i][j], 2); counter++; } } } error = Math.sqrt(error / counter); System.out.println("RMSRE: " + error); pw.write(String.format("%10.8f", error) + ";"); } pw.write("\n"); pw.write("Observers;"); for (Instance instance : topology.getLstInstance()) { int nbSw = 0; for (Switch sw : instance.networkSwitch.values()) { if (sw.isObserver) { nbSw++; } } pw.write(nbSw + ";"); } pw.write("\n"); pw.write("RelNbSw;"); for (Instance instance : topology.getLstInstance()) { int nbSw = 0; for (Switch sw : instance.networkSwitch.values()) { if (sw.isObserver) { nbSw++; } } pw.write(String.format("%4.2f", 100.0 * (float) nbSw / (float) topology.getNumberOfSwitches()) + ";"); } pw.write("\n"); pw.close(); fw.close(); for (Instance instance : topology.getLstInstance()) { HashMap<Double, List<HashMap<Integer, Integer>>> orderMap = new HashMap<>(); File bmpFile = new File( topology.getSaidasDir() + "SimulacaoInstancia" + instance.getId() + ".csv"); if (!bmpFile.exists()) { bmpFile.createNewFile(); } FileWriter fout = new FileWriter(bmpFile); PrintWriter oos = new PrintWriter(fout); for (int i = 0; i < topology.getNumberOfSwitches(); i++) { oos.print(";Router " + (i + 1)); } for (int i = 0; i < topology.getNumberOfSwitches(); i++) { oos.println(); oos.print("Router " + (i + 1)); for (int j = 0; j < topology.getNumberOfSwitches(); j++) { int sourceId = i; int destinationId = j; if (sourceId > topology.getNumberOfSwitches() || destinationId > topology.getNumberOfSwitches()) { System.out.println("Erro no nmero de switches"); throw new Exception("Erro no nmero de switches"); } else { doPrintElement(oos, i, j, instance.trafficMatrix[i][j]); // if (i < j) { // if (orderMap.containsKey(instance.trafficMatrix[i][j])) { // // HashMap<Integer, Integer> mapNodes = new HashMap<>(); // mapNodes.put(i + 1, j + 1); // orderMap.get(instance.trafficMatrix[i][j]).add(mapNodes); // } else { // LinkedList listaHashMap = new LinkedList(); // HashMap<Integer, Integer> mapNodes = new HashMap<>(); // mapNodes.put(i + 1, j + 1); // listaHashMap.add(mapNodes); // orderMap.put(instance.trafficMatrix[i][j], listaHashMap); // } // } } } } oos.close(); fout.close(); // Map<Double, List<HashMap<Integer, Integer>>> map = new TreeMap<>(orderMap); // System.out.println("Instancia" + instance.getId() + " After Sorting:"); // Set set2 = map.entrySet(); // Iterator iterator2 = set2.iterator(); // while (iterator2.hasNext()) { // Map.Entry me2 = (Map.Entry) iterator2.next(); // System.out.print(me2.getKey() + ": "); // System.out.println(me2.getValue()); // } // Plot Graf XYSeries matrix = new XYSeries("Matrix", false, true); for (int i = 0; i < topology.getNumberOfSwitches(); i++) { for (int j = i + 1; j < topology.getNumberOfSwitches(); j++) { matrix.add((double) topology.getTrafficMatrix()[i][j], instance.trafficMatrix[i][j]); } } double maxPlot = Double.max(matrix.getMaxX(), matrix.getMaxY()) * 1.1; XYSeries middle = new XYSeries("Real"); middle.add(0, 0); middle.add(maxPlot, maxPlot); XYSeries max = new XYSeries("Max"); max.add(0, 0); max.add(maxPlot, maxPlot * 1.2); XYSeries min = new XYSeries("Min"); min.add(0, 0); min.add(maxPlot, maxPlot * 0.8); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(middle); dataset.addSeries(matrix); dataset.addSeries(max); dataset.addSeries(min); JFreeChart chart = ChartFactory.createXYLineChart("Matriz de Trfego", "Real", "Estimado", dataset); chart.setBackgroundPaint(new ChartColor(255, 255, 255)); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer(); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); int width = 640 * 2; /* Width of the image */ int height = 480 * 2; /* Height of the image */ File XYChart = new File( topology.getSaidasDir() + "SimulacaoInstancia" + instance.getId() + ".jpeg"); ChartUtilities.saveChartAsJPEG(XYChart, chart, width, height); } } } }