List of usage examples for org.jfree.chart.renderer LookupPaintScale add
public void add(double value, Paint paint)
From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithHeatMap.java
protected static void addValuesToPaintScale(LookupPaintScale paintScale, double lowerBound, double upperBound, Color lowColor, Color highColor) { int distinctValues = DISTINCT_PALETTE_VALUES; if (upperBound <= lowerBound) upperBound = lowerBound + .0001; double increment = (upperBound - lowerBound) / distinctValues; int redDiff = highColor.getRed() - lowColor.getRed(); int greenDiff = highColor.getGreen() - lowColor.getGreen(); int blueDiff = highColor.getBlue() - lowColor.getBlue(); double redIncrement = (redDiff / distinctValues); double greenIncrement = (greenDiff / distinctValues); double blueIncrement = (blueDiff / distinctValues); _log.debug("Palette: "); for (int i = 0; i < distinctValues; i++) { int r = (int) (lowColor.getRed() + (i * redIncrement)); int g = (int) (lowColor.getGreen() + (i * greenIncrement)); int b = (int) (lowColor.getBlue() + (i * blueIncrement)); Color incrementColor = new Color(r, g, b); double incrementStart = lowerBound + (i * increment); paintScale.add(incrementStart, incrementColor); _log.debug("\t" + incrementStart + "-" + (incrementStart + increment) + ": " + incrementColor); }//from ww w . j a v a2 s .c o m }
From source file:SciTK.PlotXYZBlock.java
private void init(String x_label, String y_label, String window_title) { chart = ChartFactory.createScatterPlot("", x_label, y_label, data, PlotOrientation.VERTICAL, false, true, false);// w w w.j a v a 2s .c o m // turn off borders of the plot: XYPlot p = chart.getXYPlot(); p.getDomainAxis().setLowerMargin(0.0); p.getDomainAxis().setUpperMargin(0.0); p.getRangeAxis().setLowerMargin(0.0); p.getRangeAxis().setUpperMargin(0.0); // -------------------------------------------- // set up a lookup table // -------------------------------------------- // this is how we render the block plots: XYBlockRenderer renderer = new XYBlockRenderer(); // need to find max and min z of the data set: double min = 0; double max = 0; for (int i = 0; i < data.getSeriesCount(); i++) // iterate over data sets { for (int j = 0; j < data.getItemCount(i); j++) // iterate over points in dataset { if (data.getZValue(i, j) < min) min = data.getZValue(i, j); else if (data.getZValue(i, j) > max) max = data.getZValue(i, j); } } // create paint scale using min and max values, default color black: LookupPaintScale paintScale = new LookupPaintScale(min, max, Color.black); // set up the LUT: double step_size = (max - min) / 255.; // step size for LUT for (int i = 0; i < 256; i++) { paintScale.add(min + i * step_size, new Color(i, i, i, 255)); } renderer.setPaintScale(paintScale); // set this renderer to the plot: p.setRenderer(renderer); // -------------------------------------------- // set up a color bar // -------------------------------------------- // create an array of display labels: num_labels = 10; // default to 10 labels on color bar double display_step_size = (max - min) / ((double) num_labels); String[] scale_bar_labels = new String[num_labels + 1]; // to format numbers in scientific notation: DecimalFormat formater = new DecimalFormat("0.#E0"); // create list of labesl: for (int i = 0; i <= num_labels; i++) { scale_bar_labels[i] = formater.format(min + i * display_step_size); } // create axis: SymbolAxis scaleAxis = new SymbolAxis(null, scale_bar_labels); scaleAxis.setRange(min, max); scaleAxis.setPlot(new PiePlot()); scaleAxis.setGridBandsVisible(false); // set up the paint scale: psl = new PaintScaleLegend(paintScale, scaleAxis); psl.setBackgroundPaint(new Color(255, 255, 255, 0)); // clear background // set up frame with buffer region to allow text display psl.setFrame(new LineBorder((Paint) Color.BLACK, new BasicStroke((float) 1.0), new RectangleInsets(15, 10, 15, 10))); psl.setAxisOffset(5.0); // display on right side: psl.setPosition(RectangleEdge.RIGHT); // margin around color scale: psl.setMargin(new RectangleInsets(20, 15, 20, 15)); // add to the chart so it will be displayed by default: chart.addSubtitle(psl); // -------------------------------------------- // WINDOW-RELATED UI // -------------------------------------------- // set up the generic plot UI: super.window_title = window_title; super.initUI(); // add another menu item JMenuBar mb = super.getJMenuBar(); // get the menu bar // find menu named "Plot" JMenu menu_plot = null; for (int i = 0; i < mb.getMenuCount(); i++) { if (mb.getMenu(i).getText() == "Plot") menu_plot = mb.getMenu(i); } // Add a new checkbox for the color scale bar JCheckBoxMenuItem menu_plot_scalebar = new JCheckBoxMenuItem("Color Scale"); menu_plot_scalebar.setToolTipText("Show color scale bar?"); menu_plot_scalebar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { AbstractButton aButton = (AbstractButton) event.getSource(); boolean selected = aButton.getModel().isSelected(); setScaleBar(selected); } }); // set appropirate checkbox state: menu_plot_scalebar.setState(true); if (menu_plot != null) // sanity check menu_plot.add(menu_plot_scalebar); }
From source file:vteaexploration.plottools.panels.XYChartPanel.java
private ChartPanel createChart(int x, int y, int l, String xText, String yText, String lText, Color imageGateColor) {/* w w w. j a va2s . c o m*/ XYShapeRenderer renderer = new XYShapeRenderer(); XYShapeRenderer rendererGate = new XYShapeRenderer(); PaintScaleLegend psl = new PaintScaleLegend(new LookupPaintScale(0, 100, new Color(0, 0, 0)), new NumberAxis("")); if (l > 0) { double max = getMaximumOfData((ArrayList) plotValues.get(1), l); double min = this.getMinimumOfData((ArrayList) plotValues.get(1), l); double range = max - min; if (max == 0) { max = 1; } //System.out.println("PROFILING-DETAILS: Points to plot: " + ((ArrayList) plotValues.get(1)).size()); LookupPaintScale ps = new LookupPaintScale(min, max + 100, new Color(0, 0, 0)); renderer.setPaintScale(ps); ps.add(min, TENPERCENT); ps.add(min + (1 * (range / 10)), XYChartPanel.TENPERCENT); ps.add(min + (2 * (range / 10)), XYChartPanel.TWENTYPERCENT); ps.add(min + (3 * (range / 10)), XYChartPanel.THIRTYPERCENT); ps.add(min + (4 * (range / 10)), XYChartPanel.FORTYPERCENT); ps.add(min + (5 * (range / 10)), XYChartPanel.FIFTYPERCENT); ps.add(min + (6 * (range / 10)), XYChartPanel.SIXTYPERCENT); ps.add(min + (7 * (range / 10)), XYChartPanel.SEVENTYPERCENT); ps.add(min + (8 * (range / 10)), XYChartPanel.EIGHTYPERCENT); ps.add(min + (9 * (range / 10)), XYChartPanel.NINETYPERCENT); ps.add(max, XYChartPanel.ALLPERCENT); NumberAxis lAxis = new NumberAxis(lText); lAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); psl = new PaintScaleLegend(ps, lAxis); psl.setBackgroundPaint(VTC._VTC.BACKGROUND); psl.setPosition(RectangleEdge.RIGHT); psl.setMargin(4, 4, 40, 4); psl.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); } else { renderer.setBaseFillPaint(TENPERCENT); } Ellipse2D shape = new Ellipse2D.Double(0, 0, size, size); Ellipse2D shapeGate = new Ellipse2D.Double(-2, -2, size + 4, size + 4); renderer.setBaseShape(shape); rendererGate.setBaseShape(shapeGate); NumberAxis xAxis = new NumberAxis(""); NumberAxis yAxis = new NumberAxis(""); xAxis.setAutoRangeIncludesZero(false); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(createXYZDataset((ArrayList) plotValues.get(1), x, y, l), xAxis, yAxis, renderer); plot.getDomainAxis(); plot.getRangeAxis(); plot.setDomainPannable(false); plot.setRangePannable(false); plot.setRenderer(0, renderer); plot.setRenderer(1, rendererGate); plot.setDataset(0, createXYZDataset((ArrayList) plotValues.get(1), x, y, l)); if (imageGate) { roiCreated(impoverlay); XYZDataset set = createXYZDataset(ImageGateOverlay, x, y, l); plot.setDataset(1, set); plot.setRenderer(1, new XYShapeRenderer() { @Override protected java.awt.Paint getPaint(XYDataset dataset, int series, int item) { return imageGateOutline; } @Override public Shape getItemShape(int row, int col) { return new Ellipse2D.Double(-2, -2, size + 4, size + 4); } }); } //System.out.println("PROFILING: Generating plot with " + plot.getDatasetCount() + " datasets."); //System.out.println("PROFILING: Generating plot with " + ImageGateOverlay.size() + " objects gated."); try { if (getRangeofData((ArrayList) plotValues.get(1), x) > 16384) { LogAxis logAxisX = new LogAxis(); logAxisX.setAutoRange(true); plot.setDomainAxis(logAxisX); } if (getRangeofData((ArrayList) plotValues.get(1), y) > 16384) { LogAxis logAxisY = new LogAxis(); logAxisY.setAutoRange(true); plot.setRangeAxis(logAxisY); } } catch (NullPointerException e) { } ; JFreeChart chart = new JFreeChart("Plot of " + xText + " vs. " + yText, plot); chart.removeLegend(); //LUT if (l > 0) chart.addSubtitle(psl); //notifiyUpdatePlotWindowListeners(); return new ChartPanel(chart, true, true, false, false, true); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.BlockChart.java
/** * Creates a chart for the specified dataset. * // ww w .jav a2 s. co m * @param dataset the dataset. * * @return A chart instance. */ public JFreeChart createChart(DatasetMap datasets) { XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1"); //Creates the xAxis with its label and style NumberAxis xAxis = new NumberAxis(xLabel); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); xAxis.setLabel(xLabel); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { xAxis.setLabelFont(addLabelsStyle.getFont()); xAxis.setLabelPaint(addLabelsStyle.getColor()); } //Creates the yAxis with its label and style NumberAxis yAxis = new NumberAxis(yLabel); yAxis.setAutoRangeIncludesZero(false); yAxis.setInverted(false); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); yAxis.setTickLabelsVisible(true); yAxis.setLabel(yLabel); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { yAxis.setLabelFont(addLabelsStyle.getFont()); yAxis.setLabelPaint(addLabelsStyle.getColor()); } yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); Color outboundCol = new Color(Integer.decode(outboundColor).intValue()); //Sets the graph paint scale and the legend paintscale LookupPaintScale paintScale = new LookupPaintScale(zvalues[0], (new Double(zrangeMax)).doubleValue(), outboundCol); LookupPaintScale legendPaintScale = new LookupPaintScale(0.5, 0.5 + zvalues.length, outboundCol); for (int ke = 0; ke <= (zvalues.length - 1); ke++) { Double key = (new Double(zvalues[ke])); Color temp = (Color) colorRangeMap.get(key); paintScale.add(zvalues[ke], temp); legendPaintScale.add(0.5 + ke, temp); } //Configures the renderer XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setPaintScale(paintScale); double blockHeight = (new Double(blockH)).doubleValue(); double blockWidth = (new Double(blockW)).doubleValue(); renderer.setBlockWidth(blockWidth); renderer.setBlockHeight(blockHeight); //configures the plot with title, subtitle, axis ecc. XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); plot.setDomainCrosshairPaint(Color.black); plot.setForegroundAlpha(0.66f); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); JFreeChart chart = new JFreeChart(plot); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } chart.removeLegend(); chart.setBackgroundPaint(Color.white); //Sets legend labels SymbolAxis scaleAxis = new SymbolAxis(null, legendLabels); scaleAxis.setRange(0.5, 0.5 + zvalues.length); scaleAxis.setPlot(new PiePlot()); scaleAxis.setGridBandsVisible(false); scaleAxis.setLabel(zLabel); //scaleAxis.setLabelAngle(3.14/2); scaleAxis.setLabelFont(addLabelsStyle.getFont()); scaleAxis.setLabelPaint(addLabelsStyle.getColor()); //draws legend as chart subtitle PaintScaleLegend psl = new PaintScaleLegend(legendPaintScale, scaleAxis); psl.setAxisOffset(2.0); psl.setPosition(RectangleEdge.RIGHT); psl.setMargin(new RectangleInsets(5, 1, 5, 1)); chart.addSubtitle(psl); if (yLabels != null) { //Sets y legend labels LookupPaintScale legendPaintScale2 = new LookupPaintScale(0, (yLabels.length - 1), Color.white); for (int ke = 0; ke < yLabels.length; ke++) { Color temp = Color.white; legendPaintScale2.add(1 + ke, temp); } SymbolAxis scaleAxis2 = new SymbolAxis(null, yLabels); scaleAxis2.setRange(0, (yLabels.length - 1)); scaleAxis2.setPlot(new PiePlot()); scaleAxis2.setGridBandsVisible(false); //draws legend as chart subtitle PaintScaleLegend psl2 = new PaintScaleLegend(legendPaintScale2, scaleAxis2); psl2.setAxisOffset(5.0); psl2.setPosition(RectangleEdge.LEFT); psl2.setMargin(new RectangleInsets(8, 1, 40, 1)); psl2.setStripWidth(0); psl2.setStripOutlineVisible(false); chart.addSubtitle(psl2); } return chart; }
From source file:org.jls.toolbox.math.chart.XYBlockChart.java
/** * Permet de modifier l'chelle de couleur utilise par le graphique. Cela * va crer un gradient de couleur entre les deux couleurs spcifies, la * premire couleur correspondant aux valeurs les plus fortes de l'chelle * des donnes reprsenter. Les bornes infrieure et suprieure permettent * de prciser l'tendue des donnes reprsentes par cette chelle de * couleur./*from w ww. j a va 2s .co m*/ * * @param colorMin * Couleur d'arrive du gradient reprsentant les plus faibles * valeurs de l'chelle. * @param colorMax * Couleur de dpart du gradient reprsentant les plus fortes * valeurs de l'chelle. * @param lowerBound * Borne infrieure de l'chelle des donnes reprsentes. * @param upperBound * Bornes suprieure de l'chelle des donnes reprsentes. */ public void setColorGradient(Color colorMin, Color colorMax, double lowerBound, double upperBound) { LookupPaintScale scale = new LookupPaintScale(lowerBound, upperBound, Color.lightGray); double r1, r2, dr, g1, g2, dg, b1, b2, db; int nbVal = (int) (upperBound - lowerBound + 0.5); // Acquisition des composantes r1 = colorMax.getRed(); g1 = colorMax.getGreen(); b1 = colorMax.getBlue(); r2 = colorMin.getRed(); g2 = colorMin.getGreen(); b2 = colorMin.getBlue(); // Calcul du delta entre les composantes dr = (r2 - r1) / nbVal; dg = (g2 - g1) / nbVal; db = (b2 - b1) / nbVal; // Cration du gradient for (int i = 0; i < nbVal; i++) { scale.add(lowerBound + i, new Color((int) r2, (int) g2, (int) b2)); r2 = r2 - dr; g2 = g2 - dg; b2 = b2 - db; } // Mise jour du graphique this.renderer.setPaintScale(scale); this.scaleLegend.setScale(scale); // Du fait que la lgende n'est pas lie aux modifications de la courbe, // il faut rcrer la lgende la main. this.chart.removeSubtitle(this.scaleLegend); createPaintScaleLegend(scale); }
From source file:mio_de_pso.MainForm.java
private LookupPaintScale createLookupPaintScale(double[] values) { double minVal = values[0]; double maxVal = values[0]; for (int i = 0; i < values.length; ++i) { if (values[i] < minVal) minVal = values[i];// w w w.j a v a 2s. c om if (values[i] > maxVal) maxVal = values[i]; } LookupPaintScale ps = new LookupPaintScale(minVal, maxVal + 0.0000001, Color.WHITE); Color startColor = Color.BLACK; Color secondColor = Color.BLUE; Color thirdColor = Color.GREEN; Color fourthColor = Color.YELLOW; Color endColor = Color.RED; int iterations = 80; int iterationPerColor = iterations / 4; double res = Math.round(((maxVal - minVal) / iterations) * 100.0) / 100.0; minVal -= res; for (int i = 0; i < iterationPerColor; ++i) { ps.add(minVal += res, new Color( startColor.getRed() + (((secondColor.getRed() - startColor.getRed()) * i) / iterationPerColor), startColor.getGreen() + (((secondColor.getGreen()) - startColor.getGreen()) * i) / iterationPerColor, startColor.getBlue() + (((secondColor.getBlue() - startColor.getBlue()) * i) / iterationPerColor))); } for (int i = 0; i < iterationPerColor; ++i) { ps.add(minVal += res, new Color( secondColor.getRed() + (((thirdColor.getRed() - secondColor.getRed()) * i) / iterationPerColor), secondColor.getGreen() + (((thirdColor.getGreen()) - secondColor.getGreen()) * i) / iterationPerColor, secondColor.getBlue() + (((thirdColor.getBlue() - secondColor.getBlue()) * i) / iterationPerColor))); } for (int i = 0; i < iterationPerColor; ++i) { ps.add(minVal += res, new Color( thirdColor.getRed() + (((fourthColor.getRed() - thirdColor.getRed()) * i) / iterationPerColor), thirdColor.getGreen() + (((fourthColor.getGreen()) - thirdColor.getGreen()) * i) / iterationPerColor, thirdColor.getBlue() + (((fourthColor.getBlue() - thirdColor.getBlue()) * i) / iterationPerColor))); } for (int i = 0; i < iterationPerColor; ++i) { ps.add(minVal += res, new Color( fourthColor.getRed() + (((endColor.getRed() - fourthColor.getRed()) * i) / iterationPerColor), fourthColor.getGreen() + (((endColor.getGreen()) - fourthColor.getGreen()) * i) / iterationPerColor, fourthColor.getBlue() + (((endColor.getBlue() - fourthColor.getBlue()) * i) / iterationPerColor))); } return ps; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.blockcharts.TimeBlockChart.java
@Override public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); super.createChart(datasets); DefaultXYZDataset dataset = (DefaultXYZDataset) datasets.getDatasets().get("1"); DateAxis xAxis = new DateAxis(yLabel); xAxis.setLowerMargin(0.0);// www. ja v a 2 s . c om xAxis.setUpperMargin(0.0); xAxis.setInverted(false); xAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy")); if (dateAutoRange) { xAxis.setAutoRange(true); } else { DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); DateTickUnit unit = new DateTickUnit(DateTickUnit.DAY, 1, formatter); xAxis.setTickUnit(unit); } if (dateMin != null && dateMax != null) { xAxis.setRange(dateMin, addDay(dateMax)); } else { xAxis.setRange(minDateFound, addDay(maxDateFound)); } // Calendar c=new GregorianCalendar(); // c.set(9 + 2000, Calendar.JANUARY, 1); // java.util.Date minima=c.getTime(); // Calendar c1=new GregorianCalendar(); // c1.set(9 + 2000, Calendar.FEBRUARY, 1); // java.util.Date massima=c1.getTime(); NumberAxis yAxis = new NumberAxis(xLabel); yAxis.setUpperMargin(0.0); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); yAxis.setRange(hourMin, hourMax); XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setBlockWidth(BLOCK_HEIGHT); // one block for each minute! renderer.setBlockHeight(0.017); //renderer.setBlockWidth(1); renderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT); // MyXYItemLabelGenerator my=new MyXYItemLabelGenerator(); // renderer.setItemLabelsVisible(null); // renderer.setSeriesItemLabelGenerator(0, my); // renderer.setSeriesItemLabelsVisible(0, true); // XYTextAnnotation annotation1 = new XYTextAnnotation( // "P_",1.2309372E12, 14.3); // XYTextAnnotation annotation2 = new XYTextAnnotation( // "P_",1.2308508E12, 16.3); for (Iterator iterator = annotations.keySet().iterator(); iterator.hasNext();) { String annotationCode = (String) iterator.next(); AnnotationBlock annotationBlock = annotations.get(annotationCode); XYTextAnnotation xyAnnotation = new XYTextAnnotation(annotationBlock.getAnnotation(), annotationBlock.getXPosition() + ANNOTATION_HEIGHT, annotationBlock.getYPosition()); if (styleAnnotation != null) { xyAnnotation.setFont(new Font(styleAnnotation.getFontName(), Font.BOLD, styleAnnotation.getSize())); xyAnnotation.setPaint(styleAnnotation.getColor()); } else { xyAnnotation.setFont(new Font("Nome", Font.BOLD, 8)); xyAnnotation.setPaint(Color.BLACK); } xyAnnotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); renderer.addAnnotation(xyAnnotation); } logger.debug("Annotation set"); LookupPaintScale paintScale = new LookupPaintScale(0.5, ranges.size() + 0.5, color); String[] labels = new String[ranges.size() + 1]; labels[0] = ""; // ******************** SCALE **************************** for (Iterator iterator = ranges.iterator(); iterator.hasNext();) { RangeBlocks range = (RangeBlocks) iterator.next(); Integer index = patternRangeIndex.get(range.getPattern()); Color color = range.getColor(); if (color != null) { //Paint colorTransparent=new Color(color.getRed(), color.getGreen(), color.getBlue(), 50); Paint colorTransparent = null; if (addTransparency == true) { colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue(), 50); } else { colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue()); } paintScale.add(index + 0.5, colorTransparent); } //String insertLabel=" "+range.getLabel(); String insertLabel = range.getLabel(); labels[index + 1] = insertLabel; } renderer.setPaintScale(paintScale); SymbolAxis scaleAxis = new SymbolAxis(null, labels); scaleAxis.setRange(0.5, ranges.size() + 0.5); scaleAxis.setPlot(new PiePlot()); scaleAxis.setGridBandsVisible(false); org.jfree.chart.title.PaintScaleLegend psl = new PaintScaleLegend(paintScale, scaleAxis); psl.setMargin(new RectangleInsets(3, 10, 3, 10)); psl.setPosition(RectangleEdge.BOTTOM); psl.setAxisOffset(5.0); // ******************** END SCALE **************************** logger.debug("Scale Painted"); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.HORIZONTAL); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); logger.debug("Plot set"); JFreeChart chart = new JFreeChart(name, plot); if (styleTitle != null) { TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); } chart.removeLegend(); chart.setBackgroundPaint(Color.white); chart.addSubtitle(psl); logger.debug("OUT"); return chart; }
From source file:whitebox.stats.Kriging.java
/** * Draw Semivariogram surface map and also draw the search are if * Anisotropic//from www. j av a2s. co m * * @param Radius * @param AnIsotropic */ public void DrawSemivariogramSurface(double Radius, boolean AnIsotropic) { double[][] data = new double[3][BinSurface.length * BinSurface[0].length]; int n = 0; double max = Double.MIN_VALUE; for (int i = 0; i < BinSurface.length; i++) { for (int j = 0; j < BinSurface[i].length; j++) { data[0][n] = BinSurface[i][j].GridHorDistance; data[1][n] = BinSurface[i][j].GridVerDistance; if ((Math.pow(data[0][n], 2) + Math.pow(data[1][n], 2)) <= Radius * Radius && !Double.isNaN(BinSurface[i][j].Value)) { data[2][n] = BinSurface[i][j].Value; if (max < data[2][n]) { max = data[2][n]; } } else { data[2][n] = -1; } n++; } } DefaultXYZDataset dataset = new DefaultXYZDataset(); dataset.addSeries("Value", data); NumberAxis xAxis = new NumberAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); NumberAxis yAxis = new NumberAxis(); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setBlockWidth(LagSize); renderer.setBlockHeight(LagSize); renderer.setBlockAnchor(RectangleAnchor.CENTER); LookupPaintScale paintScale = new LookupPaintScale(0, max, Color.white); double colorRange = max / 6; //double colorRange = 23013; paintScale.add(0.0, Color.blue); paintScale.add(1 * colorRange, Color.green); paintScale.add(2 * colorRange, Color.cyan); paintScale.add(3 * colorRange, Color.yellow); paintScale.add(4 * colorRange, Color.ORANGE); paintScale.add(5 * colorRange, Color.red); renderer.setPaintScale(paintScale); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinePaint(Color.white); if (AnIsotropic) { CombinedRangeXYPlot combinedrangexyplot = new CombinedRangeXYPlot(); XYSeries seriesT1 = new XYSeries("1"); XYSeriesCollection AngleCollct = new XYSeriesCollection(); double bw = BandWidth; double r = bw / Math.sin(Tolerance); if (r > Radius) { bw = Radius * Math.sin(Tolerance); r = Radius; } seriesT1.add(r * Math.cos(Angle + Tolerance), r * Math.sin(Angle + Tolerance)); if ((double) Math.round(Math.sin(Angle) * 10000) / 10000 != 0) { if ((double) Math.round(Math.cos(Angle) * 10000) / 10000 != 0) { double a = (1 + Math.pow(Math.tan(Angle), 2)); double b = 2 * bw / Math.sin(Angle) * Math.pow(Math.tan(Angle), 2); double c = Math.pow(Math.tan(Angle), 2) * Math.pow(bw / Math.sin(Angle), 2) - Math.pow(Radius, 2); double x1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a); double y1 = Math.tan(Angle) * (x1 + bw / Math.sin(Angle)); double x2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a); double y2 = Math.tan(Angle) * (x2 + bw / Math.sin(Angle)); double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2)) + (Math.pow((Radius * Math.sin(Angle) - y1), 2))); double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2)) + (Math.pow((Radius * Math.sin(Angle) - y2), 2))); if (d1 < d2) { seriesT1.add(x1, y1); } else { seriesT1.add(x2, y2); } } else { double x1 = -bw * Math.sin(Angle); double y1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2)); double y2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2)); double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2)) + (Math.pow((Radius * Math.sin(Angle) - y1), 2))); double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2)) + (Math.pow((Radius * Math.sin(Angle) - y2), 2))); if (d1 < d2) { seriesT1.add(x1, y1); } else { seriesT1.add(x1, y2); } } } else { double y1 = bw * Math.cos(Angle); double x1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2)); double x2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2)); double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2)) + (Math.pow((Radius * Math.sin(Angle) - y1), 2))); double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2)) + (Math.pow((Radius * Math.sin(Angle) - y1), 2))); if (d1 < d2) { seriesT1.add(x1, y1); } else { seriesT1.add(x2, y1); } } AngleCollct.addSeries(seriesT1); XYSeries seriesT2 = new XYSeries("2"); seriesT2.add(r * Math.cos(Angle + Tolerance), r * Math.sin(Angle + Tolerance)); seriesT2.add(0.0, 0.0); AngleCollct.addSeries(seriesT2); XYSeries seriesT3 = new XYSeries("3"); seriesT3.add(Radius * Math.cos(Angle), Radius * Math.sin(Angle)); seriesT3.add(0, 0); AngleCollct.addSeries(seriesT3); XYSeries seriesT4 = new XYSeries("4"); seriesT4.add(r * Math.cos(Angle - Tolerance), r * Math.sin(Angle - Tolerance)); seriesT4.add(0, 0); AngleCollct.addSeries(seriesT4); XYSeries seriesT5 = new XYSeries("5"); seriesT5.add(r * Math.cos(Angle - Tolerance), r * Math.sin(Angle - Tolerance)); if ((double) Math.round(Math.sin(Angle) * 10000) / 10000 != 0) { if ((double) Math.round(Math.cos(Angle) * 10000) / 10000 != 0) { double a = (1 + Math.pow(Math.tan(Angle), 2)); double b = -2 * bw / Math.sin(Angle) * Math.pow(Math.tan(Angle), 2); double c = Math.pow(Math.tan(Angle), 2) * Math.pow(bw / Math.sin(Angle), 2) - Math.pow(Radius, 2); double x1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a); double y1 = Math.tan(Angle) * (x1 - bw / Math.sin(Angle)); double x2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a); double y2 = Math.tan(Angle) * (x2 - bw / Math.sin(Angle)); double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2)) + (Math.pow((Radius * Math.sin(Angle) - y1), 2))); double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2)) + (Math.pow((Radius * Math.sin(Angle) - y2), 2))); if (d1 < d2) { seriesT5.add(x1, y1); } else { seriesT5.add(x2, y2); } } else { double x1 = bw * Math.sin(Angle); double y1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2)); double y2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2)); double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2)) + (Math.pow((Radius * Math.sin(Angle) - y1), 2))); double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2)) + (Math.pow((Radius * Math.sin(Angle) - y2), 2))); if (d1 < d2) { seriesT5.add(x1, y1); } else { seriesT5.add(x1, y2); } } } else { double y1 = -bw * Math.cos(Angle); double x1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2)); double x2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2)); double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2)) + (Math.pow((Radius * Math.sin(Angle) - y1), 2))); double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2)) + (Math.pow((Radius * Math.sin(Angle) - y1), 2))); if (d1 < d2) { seriesT5.add(x1, y1); } else { seriesT5.add(x2, y1); } } AngleCollct.addSeries(seriesT5); plot.setDataset(1, AngleCollct); XYLineAndShapeRenderer lineshapRend = new XYLineAndShapeRenderer(true, false); for (int i = 0; i < AngleCollct.getSeriesCount(); i++) { //plot.getRenderer().setSeriesPaint(i , Color.BLUE); lineshapRend.setSeriesPaint(i, Color.BLACK); } plot.setRenderer(1, lineshapRend); combinedrangexyplot.add(plot); } plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); JFreeChart chart = new JFreeChart("Semivariogram Surface", plot); chart.removeLegend(); chart.setBackgroundPaint(Color.white); // create and display a frame... ChartFrame frame = new ChartFrame("", chart); frame.pack(); //frame.setSize(100, 50); frame.setVisible(true); }
From source file:com.peterbochs.instrument.InstrumentPanel.java
public void update2DChart() { // jfcMemory.getCategoryPlot().setDataset(createMemoryDataset()); jfcMemory.getXYPlot().setDataset(createDataset()); MyXYBlockRenderer renderer = (MyXYBlockRenderer) jfcMemory.getXYPlot().getRenderer(); int largest = findLargest( Data.getChartData(CommonLib.convertFilesize((String) jFromComboBox.getSelectedItem()), CommonLib.convertFilesize((String) jToComboBox.getSelectedItem()), CommonLib.convertFilesize((String) jBlockSizeComboBox.getSelectedItem()))); if (largest == 0) { largest = 1;//from w w w . j a va 2 s . co m } LookupPaintScale paintScale = new LookupPaintScale(0, largest, background); if (largest > 1) { // int mean = // medianWithoutZero(Data.getChartData(CommonLib.convertFilesize((String) // jFromComboBox.getSelectedItem()), // CommonLib.convertFilesize((String) jToComboBox // .getSelectedItem()))); int m[] = Data.getChartData(CommonLib.convertFilesize((String) jFromComboBox.getSelectedItem()), CommonLib.convertFilesize((String) jToComboBox.getSelectedItem()), CommonLib.convertFilesize((String) jBlockSizeComboBox.getSelectedItem())); TreeSet<Integer> data = new TreeSet<Integer>(); for (int x = 0; x < m.length; x++) { if (m[x] > 0) { data.add(m[x]); } } // paintScale.add(0, Color.white); ArrayList<Color> allColors = allColors(); Object iData[] = data.toArray(); paintScale.add(1, allColors.get(0)); for (int x = 1; x < iData.length - 1; x++) { paintScale.add((int) (Integer) iData[x], allColors.get(allColors.size() / iData.length * x)); } paintScale.add((int) (Integer) iData[iData.length - 1], allColors.get(allColors.size() - 1)); } renderer.setPaintScale(paintScale); renderer.setBaseToolTipGenerator(new MyXYToolTipGenerator()); jfcMemory.getXYPlot().setForegroundAlpha(1f); jZoomOutAutoRangeButtonActionPerformed(null); }