List of usage examples for org.jfree.chart.renderer.xy XYBlockRenderer setBlockWidth
public void setBlockWidth(double width)
From source file:org.jfree.chart.demo.XYBlockChartDemo2.java
private static JFreeChart createChart(XYZDataset xyzdataset) { DateAxis dateaxis = new DateAxis("Date"); dateaxis.setLowerMargin(0.0D);//from w ww. j a v a 2s .c o m dateaxis.setUpperMargin(0.0D); dateaxis.setInverted(true); NumberAxis numberaxis = new NumberAxis("Hour"); numberaxis.setUpperMargin(0.0D); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYBlockRenderer xyblockrenderer = new XYBlockRenderer(); xyblockrenderer.setBlockWidth(86400000D); xyblockrenderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT); LookupPaintScale lookuppaintscale = new LookupPaintScale(0.5D, 4.5D, Color.white); lookuppaintscale.add(0.5D, Color.red); lookuppaintscale.add(1.5D, Color.green); lookuppaintscale.add(2.5D, Color.blue); lookuppaintscale.add(3.5D, Color.yellow); xyblockrenderer.setPaintScale(lookuppaintscale); XYPlot xyplot = new XYPlot(xyzdataset, dateaxis, numberaxis, xyblockrenderer); xyplot.setOrientation(PlotOrientation.HORIZONTAL); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo2", xyplot); jfreechart.removeLegend(); jfreechart.setBackgroundPaint(Color.white); SymbolAxis symbolaxis = new SymbolAxis(null, new String[] { "", "Unavailable", "Free", "Group 1", "Group 2" }); symbolaxis.setRange(0.5D, 4.5D); symbolaxis.setPlot(new PiePlot()); symbolaxis.setGridBandsVisible(false); PaintScaleLegend paintscalelegend = new PaintScaleLegend(lookuppaintscale, symbolaxis); paintscalelegend.setMargin(new RectangleInsets(3D, 10D, 3D, 10D)); paintscalelegend.setPosition(RectangleEdge.BOTTOM); paintscalelegend.setAxisOffset(5D); jfreechart.addSubtitle(paintscalelegend); return jfreechart; }
From source file:com.javafxpert.neuralnetviz.scenario.PlotUtil.java
private static JFreeChart createChart(XYZDataset dataset, double[] mins, double[] maxs, int nPoints, XYDataset xyData) {//from w ww. j a v a 2s .co m NumberAxis xAxis = new NumberAxis("X"); xAxis.setRange(mins[0], maxs[0]); NumberAxis yAxis = new NumberAxis("Y"); yAxis.setRange(mins[1], maxs[1]); XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setBlockWidth((maxs[0] - mins[0]) / (nPoints - 1)); renderer.setBlockHeight((maxs[1] - mins[1]) / (nPoints - 1)); PaintScale scale = new GrayPaintScale(0, 1.0); renderer.setPaintScale(scale); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); JFreeChart chart = new JFreeChart("", plot); chart.getXYPlot().getRenderer().setSeriesVisibleInLegend(0, false); NumberAxis scaleAxis = new NumberAxis("Probability (class 0)"); scaleAxis.setAxisLinePaint(Color.white); scaleAxis.setTickMarkPaint(Color.white); scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7)); PaintScaleLegend legend = new PaintScaleLegend(new GrayPaintScale(), scaleAxis); legend.setStripOutlineVisible(false); legend.setSubdivisionCount(20); legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT); legend.setAxisOffset(5.0); legend.setMargin(new RectangleInsets(5, 5, 5, 5)); legend.setFrame(new BlockBorder(Color.red)); legend.setPadding(new RectangleInsets(10, 10, 10, 10)); legend.setStripWidth(10); legend.setPosition(RectangleEdge.LEFT); chart.addSubtitle(legend); ChartUtilities.applyCurrentTheme(chart); plot.setDataset(1, xyData); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setBaseLinesVisible(false); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return chart; }
From source file:org.gumtree.vis.awt.PlotFactory.java
private static XYBlockRenderer createRender(IXYZDataset dataset, PaintScale scale) { // renderer = new Render2D(); XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setPaintScale(scale);// w w w .j ava 2 s . c o m renderer.setBlockHeight(dataset.getYBlockSize()); renderer.setBlockWidth(dataset.getXBlockSize()); return renderer; }
From source file:org.spf4j.perf.impl.chart.Charts.java
public static JFreeChart createHeatJFreeChart(final String[] dsNames, final double[][] values, final long startTimeMillis, final long stepMillis, final String uom, final String chartName) { final QuantizedXYZDatasetImpl dataSet = new QuantizedXYZDatasetImpl(dsNames, values, startTimeMillis, stepMillis);/*from w w w .j av a 2 s. c om*/ NumberAxis xAxis = new NumberAxis("Time"); xAxis.setStandardTickUnits(dataSet.createXTickUnits()); xAxis.setLowerMargin(0); xAxis.setUpperMargin(0); xAxis.setVerticalTickLabels(true); NumberAxis yAxis = new NumberAxis(uom); yAxis.setStandardTickUnits(dataSet.createYTickUnits()); yAxis.setLowerMargin(0); yAxis.setUpperMargin(0); XYBlockRenderer renderer = new XYBlockRenderer(); PaintScale scale; if (dataSet.getMinValue() >= dataSet.getMaxValue()) { if (dataSet.getMinValue() == Double.POSITIVE_INFINITY) { scale = new InverseGrayScale(0, 1); } else { scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue() + 1); } } else { scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue()); } renderer.setPaintScale(scale); renderer.setBlockWidth(1); renderer.setBlockHeight(1); XYPlot plot = new XYPlot(dataSet, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeMinorGridlinesVisible(false); JFreeChart chart = new JFreeChart(chartName, plot); PaintScaleLegend legend = new PaintScaleLegend(scale, new NumberAxis("Count")); legend.setMargin(0, 5, 0, 5); chart.addSubtitle(legend); chart.removeLegend(); chart.setBackgroundPaint(Color.white); return chart; }
From source file:inflor.core.plots.DensityPlot.java
private XYBlockRenderer updateRenderer(Histogram2D histogram) { BitSet nonEmptyMask = histogram.getNonEmptyBins(); double[] z = FCSUtilities.filterColumn(nonEmptyMask, histogram.getZValues()); LookupPaintScale paintScale = PlotUtils.createPaintScale(Doubles.max(z), colorScheme); // Renderer configuration XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setBlockWidth(histogram.getXBinWidth()); renderer.setBlockHeight(histogram.getYBinWidth()); renderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT); renderer.setSeriesVisible(0, true);/* w w w .j a v a 2 s . co m*/ renderer.setPaintScale(paintScale); return renderer; }
From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.XyBlockRendererCustomizer.java
@Override public void customize(JFreeChart chart, ReportParameters reportParameters) { chart.getXYPlot().getDomainAxis().setUpperMargin(0); chart.getXYPlot().getRangeAxis().setUpperMargin(0); XYBlockRenderer renderer = new XYBlockRenderer(); if (xyBlockPlot.getBlockWidth() != null) { renderer.setBlockWidth(xyBlockPlot.getBlockWidth()); }/* w ww. j a va2 s . c o m*/ if (xyBlockPlot.getBlockHeight() != null) { renderer.setBlockHeight(xyBlockPlot.getBlockHeight()); } if (xyBlockPlot.getBlockAnchor() != null) { renderer.setBlockAnchor(ConstantTransform.rectangleAnchor(xyBlockPlot.getBlockAnchor())); } LookupPaintScale paintScale = new LookupPaintScale(xyBlockPlot.getDefaultLowerBound(), xyBlockPlot.getDefaultUpperBound(), xyBlockPlot.getDefaultPaint()); for (DRIPaintScale scale : xyBlockPlot.getPaintScales()) { paintScale.add(scale.getValue(), scale.getPaint()); } renderer.setPaintScale(paintScale); chart.getXYPlot().setRenderer(renderer); LegendItemCollection legendItems = new LegendItemCollection(); for (DRIPaintScale scale : xyBlockPlot.getPaintScales()) { legendItems.add(new LegendItem(scale.getLabel(), scale.getPaint())); } chart.getXYPlot().setFixedLegendItems(legendItems); }
From source file:inflor.core.plots.CategoryResponseChart.java
public JFreeChart createChart(FCSFrame dataFrame) { CategoryXYZDataSet categoryData = new CategoryXYZDataSet(); double zMin = Double.MAX_VALUE; double zMax = 1; if (dataFrame.getKeywords().containsKey(FCSUtilities.KEY_MERGE_MAP)) { String[] mergeMap = dataFrame.getKeywordValue(FCSUtilities.KEY_MERGE_MAP) .split(NodeUtilities.DELIMITER_REGEX); FCSDimension dim = dataFrame.getDimension(axisName); double[] transformedData = transform.transform(dim.getData()); int perFileSize = dim.getData().length / mergeMap.length; for (int i = 0; i < mergeMap.length; i++) { double[] unMergedData = new double[perFileSize]; for (int j = 0; j < unMergedData.length; j++) { unMergedData[j] = transformedData[i * unMergedData.length + j]; }/*from w ww . ja v a 2 s . co m*/ double tMin = transform.getMinTranformedValue(); double tMax = transform.getMaxTransformedValue(); Histogram1D hist = new Histogram1D(unMergedData, tMin, tMax, ChartingDefaults.BIN_COUNT); double[] x = hist.getNonZeroX(); double[] y = new double[x.length]; for (int j = 0; j < y.length; j++) { y[j] = i; } double[] z = hist.getNonZeroY(); double currentZMin = Doubles.min(z); double currentZMax = Doubles.max(z); if (currentZMin < zMin) { zMin = currentZMin; } else if (currentZMax > zMax) { zMax = currentZMax; } categoryData.addCategoricalSeries(mergeMap[i], x, z); } } else { FCSDimension dim = dataFrame.getDimension(axisName); double[] transformedData = transform.transform(dim.getData()); Histogram1D hist = new Histogram1D(transformedData, transform.getMinTranformedValue(), transform.getMaxTransformedValue(), ChartingDefaults.BIN_COUNT); double[] x = hist.getNonZeroX(); double[] y = new double[x.length]; for (int j = 0; j < y.length; j++) { y[j] = 0; } double[] z = hist.getNonZeroY(); double currentZMin = Doubles.min(z); double currentZMax = Doubles.max(z); if (currentZMin < zMin) { zMin = currentZMin; } else if (currentZMax > zMax) { zMax = currentZMax; } categoryData.addCategoricalSeries(dataFrame.getDisplayName(), x, z); } ValueAxis domainAxis = PlotUtils.createAxis(axisName, transform); NumberAxis rangeAxis = new CategoricalNumberAxis("", categoryData.getLabelMap()); // Renderer configuration XYBlockRenderer renderer = new XYBlockRenderer(); double xWidth = (transform.getMaxTransformedValue() - transform.getMinTranformedValue()) / ChartingDefaults.BIN_COUNT; renderer.setBlockWidth(xWidth); renderer.setBlockHeight(0.5); renderer.setBlockAnchor(RectangleAnchor.LEFT); PaintScale paintScale = PlotUtils.createPaintScale(zMax, ChartingDefaults.DEFAULT_COLOR_SCHEME); renderer.setPaintScale(paintScale); // Add to panel. XYPlot responsePlot = new XYPlot(categoryData, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart(responsePlot); chart.removeLegend(); return chart; }
From source file:org.spantus.exp.segment.draw.DrawDtw.java
protected JFreeChart createXYZChart() { NumberAxis xAxis = new NumberAxis("Sample"); NumberAxis yAxis = new NumberAxis("target"); List<List<Double>> data = info.getDistanceMatrix(); XYZDataset xyzset = new XYZArrayDataset(data); XYPlot plot = new XYPlot(xyzset, xAxis, yAxis, null); XYBlockRenderer r = new XYBlockRenderer(); PaintScale ps = new GrayPaintScale(min, max); // LookupPaintScale ps = new LookupPaintScale(0.0, 4.0, Color.WHITE); // ps.add(1, Color.red); // ps.add(2, Color.green); // ps.add(3, Color.gray); r.setPaintScale(ps);//from w w w. j av a 2 s .c om r.setBlockHeight(1.0f); r.setBlockWidth(1.0f); plot.setRenderer(r); JFreeChart chart = new JFreeChart("Chart Title", JFreeChart.DEFAULT_TITLE_FONT, plot, false); NumberAxis scaleAxis = new NumberAxis("Scale"); scaleAxis.setUpperBound(100); scaleAxis.setAxisLinePaint(Color.white); scaleAxis.setTickMarkPaint(Color.white); scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 12)); // PaintScaleLegend legend = new PaintScaleLegend(ps, scaleAxis); // legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // legend.setPadding(new RectangleInsets(5, 5, 5, 5)); // legend.setStripWidth(50); // legend.setPosition(RectangleEdge.RIGHT); // legend.setBackgroundPaint(Color.WHITE); // chart.addSubtitle(legend); chart.setBackgroundPaint(Color.white); return chart; }
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);// ww w . j a va2s.c o m 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:org.jax.haplotype.analysis.visualization.GenomicGraphFactory.java
/** * Create a SNP block graph for the given parameters. This graph * will show where the intervals do and don't exist. Interval lists * are organized with the X axis label matching the list's key * @param snpIntervals// ww w. jav a 2 s . c o m * the blocks * @param startInBasePairs * the x location to start the graph at * @param extentInBasePairs * the extent to use for the graph * @param maximumImageBlockCount * the max # of separate image blocks to use * @param renderAxes * if true render the axes... otherwise dont * @param legendText * the text to use for the legend * @param yAxisText * the text to use for the y axis * @param trueColor * the color to use for true * @param falseColor * the color to use for false * @return * the graph */ public JFreeChart createSnpIntervalGraph( final Map<String, ? extends List<? extends BasePairInterval>> snpIntervals, final long startInBasePairs, final long extentInBasePairs, final int maximumImageBlockCount, final boolean renderAxes, final String legendText, final String yAxisText, final Color trueColor, final Color falseColor) { XYDataset dataset = snpIntervalsToDataset(snpIntervals, startInBasePairs, extentInBasePairs, maximumImageBlockCount); NumberAxis xAxis = new NumberAxis("SNP Position (Base Pairs)"); xAxis.setAutoRangeIncludesZero(false); xAxis.setRange(new Range(startInBasePairs, startInBasePairs + extentInBasePairs)); String[] sortedStrainNames = extractSortedStrainNames(snpIntervals); for (int strainIndex = 0; strainIndex < sortedStrainNames.length; strainIndex++) { LOG.info("Strain Name: " + sortedStrainNames[strainIndex]); } SymbolAxis yAxis = new SymbolAxis(yAxisText == null ? "" : yAxisText, sortedStrainNames); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); LegendItemCollection items = new LegendItemCollection(); if (legendText != null) { items.add(new LegendItem(legendText, null, null, null, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0), trueColor, new BasicStroke(), Color.BLACK)); } plot.setFixedLegendItems(items); XYBlockRenderer r = new XYBlockRenderer(); SmoothPaintScale ps = new SmoothPaintScale(0.0, 1.0, falseColor, trueColor); r.setPaintScale(ps); r.setBlockHeight(1.0); r.setBlockWidth(1.0); plot.setRenderer(r); final JFreeChart chart; if (renderAxes) { chart = new JFreeChart("Identical By State Blocks", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else { xAxis.setVisible(false); yAxis.setVisible(false); plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); chart = new JFreeChart(plot); } chart.setBackgroundPaint(Color.WHITE); return chart; }