/** * Set the axis range. * * @param axis a numberAxis * @param range a range */ private void setAxisRange(NumberAxis axis, double[] range) { if (range == null || range.length != 2) { axis.setAutoRange(true); } else { double lower = range[0]; double upper = range[1]; ArgumentNotValid.checkTrue(lower < upper, "Incorrect range"); axis.setAutoRange(false); axis.setRange(new Range(lower, upper)); } }
private static JFreeChart createChart(XYDataset dataset, String exp) { JFreeChart chart = ChartFactory.createXYLineChart( "", "", "", dataset, PlotOrientation.VERTICAL, false, false, false); chart.setBorderVisible(false); chart.setAntiAlias(true); chart.setBackgroundPaint(Color.getHSBColor((float) 0, (float) 0, (float) 0.96)); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(true); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.WHITE); // 网格线颜色 plot.setNoDataMessage("No data!"); plot.setOutlinePaint(Color.WHITE); plot.setRangeGridlinePaint(Color.WHITE); plot.setBackgroundPaint(Color.getHSBColor((float) 0, (float) 0.01, (float) 0.91)); // xylineandshaperenderer.setShapesFilled(true); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRange(true); axis.setPositiveArrowVisible(true); axis.setAutoRangeIncludesZero(true); axis.setAutoRangeStickyZero(true); // List axisIndices = Arrays.asList(new Integer[] {new Integer(0), // new Integer(1)}); // plot.mapDatasetToDomainAxes(0, axisIndices); // plot.mapDatasetToRangeAxes(0, axisIndices); // ChartUtilities.applyCurrentTheme(chart); return chart; }
@Override protected void afterPlot(List<? super InstanceStatistics> list, JFreeChart chart, XYPlot plot) { NumberAxis sizeAxis = (NumberAxis) plot.getRangeAxis(0); Font labelFont = sizeAxis.getLabelFont(); Paint labelPaint = sizeAxis.getLabelPaint(); TimeSeries tm = new TimeSeries("memory"); for (int i = 0; i < list.size(); i++) { double memory = 0; MapStatistics mapStatistics = (MapStatistics) list.get(i); for (MapStatistics.LocalMapStatistics localMapStatistics : mapStatistics.getListOfLocalStats()) { memory = memory + localMapStatistics.ownedEntryMemoryCost + localMapStatistics.backupEntryMemoryCost + localMapStatistics.markedAsRemovedMemoryCost; } double mem = new Double(memory / (double) (1024 * 1024)); tm.addOrUpdate(new Second(((MapStatistics) list.get(i)).getCreatedDate()), mem); } NumberAxis memoryAxis = new NumberAxis("memory (MB)"); memoryAxis.setAutoRange(true); memoryAxis.setAutoRangeIncludesZero(false); plot.setDataset(1, new TimeSeriesCollection(tm)); plot.setRangeAxis(1, memoryAxis); plot.mapDatasetToRangeAxis(1, 1); plot.setRenderer(1, new StandardXYItemRenderer()); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); increaseRange(memoryAxis); memoryAxis.setLabelFont(labelFont); memoryAxis.setLabelPaint(labelPaint); }
/** * Set lower and upper limits for an ordinate * * @param i Axis index * @param lower Lower limit * @param upper Upper limit * @param tick Tick unit */ public void setOrdinateRange(int i, double lower, double upper, double tick) { NumberAxis e = AxesList.get(i); e.setAutoRange(false); e.setLowerBound(lower); e.setUpperBound(upper); e.setTickUnit(new NumberTickUnit(tick)); }
/** * Set lower and upper limits for an ordinate * * @param axis Axis to configure */ void setOrdinateRange(final NumberAxis axis) { axis.setAutoRange(false); GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(0, 10, 0, 10)); final TextField tfMax; final TextField tfMin; final TextField tfTick; final TextField tfFuente; grid.add(new Label("Axis"), 0, 0); grid.add(new Label(axis.getLabel()), 1, 0); grid.add(new Label("Lower"), 0, 1); grid.add(tfMin = new TextField(), 1, 1); grid.add(new Label("Upper"), 0, 2); grid.add(tfMax = new TextField(), 1, 2); grid.add(new Label("Space"), 0, 3); grid.add(tfTick = new TextField(), 1, 3); tfMin.setText(String.valueOf(axis.getLowerBound())); tfMax.setText(String.valueOf(axis.getUpperBound())); tfTick.setText(String.valueOf(axis.getTickUnit().getSize())); new PseudoModalDialog(skeleton, grid, true) { @Override public boolean validation() { axis.setLowerBound(Double.valueOf(tfMin.getText())); axis.setUpperBound(Double.valueOf(tfMax.getText())); axis.setTickUnit(new NumberTickUnit(Double.valueOf(tfTick.getText()))); return true; } }.show(); }
public BoxplotChart(String title, String xAxisTitle, String yAxisTitle) { super(); dataset = new DefaultBoxAndWhiskerCategoryDataset(); CategoryAxis xAxis = new CategoryAxis("Type"); NumberAxis yAxis = new NumberAxis("Value"); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); chart = new JFreeChart(title, plot); Font font = new Font("Helvetica", Font.BOLD, 12); xAxis.setLabelFont(font); xAxis.setLabel(xAxisTitle); yAxis.setLabelFont(font); yAxis.setLabel(yAxisTitle); // Making it pretty plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); chart.setBackgroundPaint(Color.white); chart.setTextAntiAlias(true); yAxis.setAutoRange(true); colorGenerator = new ColorGenerator(); datasetIndex = 0; chart.getLegend().setPosition(RectangleEdge.BOTTOM); chart.getLegend().setBorder(1, 1, 1, 1); }
/** * Sets the properties of the specified axis to match the properties defined on this panel. * * @param axis the axis. */ public void setAxisProperties(Axis axis) { super.setAxisProperties(axis); NumberAxis numberAxis = (NumberAxis) axis; numberAxis.setAutoRange(this.autoRange); if (!this.autoRange) { numberAxis.setRange(this.minimumValue, this.maximumValue); } // numberAxis.setGridLinesVisible(this.showGridLinesCheckBox.isSelected()); // numberAxis.setGridPaint(this.gridPaintSample.getPaint()); // numberAxis.setGridStroke(this.gridStrokeSample.getStroke()); }
@Override protected JFreeChart createGraph() { final JFreeChart chart = ChartFactory.createLineChart( null, // chart title null, // unused yLabel, // range axis label categoryDataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... final LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerBound(0); rangeAxis.setAutoRange(true); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(2.0f)); ColorPalette.apply(renderer); // crop extra space around the graph plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); return chart; }
protected String buildGraph(String seriesDirectory, Method<?, ?> method, List<Double> datas) { XYSeries series = new XYSeries("XYGraph", false, false); double snapshot = 0; for (Double data : datas) { double seconds = TimeUnit.NANOSECONDS.toSeconds(data.intValue()); series.add(snapshot++, seconds); } XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series); JFreeChart chart = ChartFactory.createXYLineChart( null, "Snapshots", "Time", seriesCollection, PlotOrientation.VERTICAL, false, false, false); chart.setTitle(new TextTitle(method.getName(), new Font("Arial", Font.BOLD, 11))); XYPlot xyPlot = chart.getXYPlot(); NumberAxis yAxis = (NumberAxis) xyPlot.getRangeAxis(); yAxis.setAutoRange(true); yAxis.setAutoRangeIncludesZero(true); NumberAxis xAxis = (NumberAxis) xyPlot.getDomainAxis(); xAxis.setAutoRange(true); xAxis.setAutoRangeIncludesZero(true); // xAxis.setTickUnit(new NumberTickUnit(1)); StringBuilder builder = new StringBuilder(method.getClassName()); builder.append(method.getName()); builder.append(method.getDescription()); String fileName = Long.toString(Toolkit.hash(builder.toString())); fileName += ".jpeg"; File chartSeriesDirectory = new File(IConstants.chartDirectory, seriesDirectory); File chartFile = new File(chartSeriesDirectory, fileName); try { if (!IConstants.chartDirectory.exists()) { //noinspection ResultOfMethodCallIgnored IConstants.chartDirectory.mkdirs(); } if (!chartSeriesDirectory.exists()) { //noinspection ResultOfMethodCallIgnored chartSeriesDirectory.mkdirs(); } if (!chartFile.exists()) { //noinspection ResultOfMethodCallIgnored chartFile.createNewFile(); } ChartUtilities.saveChartAsJPEG(chartFile, chart, 450, 150); builder = new StringBuilder(IConstants.CHARTS); builder.append(File.separatorChar); builder.append(seriesDirectory); builder.append(File.separatorChar); builder.append(fileName); return builder.toString(); } catch (Exception e) { logger.error("Exception generating the graph", e); } return null; }
public Drawable createChart(ADCDataset dataset, Dimension dimension) { JFreeChart chart = ChartFactory.createBarChart( "", // chart title "", // domain axis label "", // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation false, // legend false, // tooltips false // urls ); TextTitle textTitle = new TextTitle(dataset.get(Attribute.TITLE), TITLE_FONT); textTitle.setPadding(new RectangleInsets(10, 0, 0, 0)); chart.setTitle(textTitle); chart.addLegend(createLegend(dataset.getRowKey(0).toString(), dataset.getRowKey(1).toString())); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setOutlineVisible(false); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.gray); plot.setRangeGridlineStroke(new BasicStroke(2)); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoTickUnitSelection(true); rangeAxis.setTickUnit(new NumberTickUnit(0.2, percentFormatter())); rangeAxis.setAxisLineVisible(true); rangeAxis.setLabel(dataset.get(Attribute.Y_AXIS_LABEL)); rangeAxis.setAxisLineStroke(new BasicStroke(2)); rangeAxis.setAxisLinePaint(Color.black); rangeAxis.setTickMarksVisible(false); rangeAxis.setLabelPaint(AXIS_LABEL_COLOR); rangeAxis.setLabelFont(AXIS_LABEL_FONT); rangeAxis.setLabelInsets(new RectangleInsets(0, 0, 0, 0)); rangeAxis.setUpperMargin(0); rangeAxis.setAutoRange(false); rangeAxis.setRange(0, 1); CategoryAxis cAxis = plot.getDomainAxis(); cAxis.setTickMarksVisible(false); cAxis.setAxisLinePaint(Color.black); cAxis.setAxisLineStroke(new BasicStroke(2)); cAxis.setLabel(dataset.get(Attribute.X_AXIS_LABEL)); cAxis.setTickLabelsVisible(true); cAxis.setUpperMargin(0.05); cAxis.setLowerMargin(0.05); cAxis.setTickLabelFont(CAXIS_LABEL_FONT); cAxis.setTickLabelPaint(Color.black); CustomBarRenderer renderer = new CustomBarRenderer(); plot.setRenderer(renderer); renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(false); renderer.setShadowVisible(false); renderer.setBarPainter(new StandardBarPainter()); renderer.setMaximumBarWidth(0.08); renderer.setItemMargin(0.01); return new JFreeChartDrawable(chart, dimension); }
private JFreeChart createChart() { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart( null, // chart title null, // x axis label null, // y axis label null, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customization... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) { if ((dataTable.isDate(indexAxis)) || (dataTable.isDateTime(indexAxis))) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(indexAxis)); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); chart.getXYPlot().setDomainAxis(domainAxis); } } else { plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US)); ((NumberAxis) plot.getDomainAxis()).setAutoRangeStickyZero(false); ((NumberAxis) plot.getDomainAxis()).setAutoRangeIncludesZero(false); } ValueAxis xAxis = plot.getDomainAxis(); if (indexAxis > -1) xAxis.setLabel(getDataTable().getColumnName(indexAxis)); else xAxis.setLabel(SERIESINDEX_LABEL); xAxis.setAutoRange(true); xAxis.setLabelFont(LABEL_FONT_BOLD); xAxis.setTickLabelFont(LABEL_FONT); xAxis.setVerticalTickLabels(isLabelRotating()); if (indexAxis > 0) { if (getRangeForDimension(indexAxis) != null) { xAxis.setRange(getRangeForDimension(indexAxis)); } } else { if (getRangeForName(SERIESINDEX_LABEL) != null) { xAxis.setRange(getRangeForName(SERIESINDEX_LABEL)); } } // renderer and range axis synchronized (dataTable) { int numberOfSelectedColumns = 0; for (int c = 0; c < dataTable.getNumberOfColumns(); c++) { if (getPlotColumn(c)) { if (dataTable.isNumerical(c)) { numberOfSelectedColumns++; } } } int columnCount = 0; for (int c = 0; c < dataTable.getNumberOfColumns(); c++) { if (getPlotColumn(c)) { if (dataTable.isNumerical(c)) { // YIntervalSeries series = new YIntervalSeries(this.dataTable.getColumnName(c)); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries(dataTable.getColumnName(c)); Iterator<DataTableRow> i = dataTable.iterator(); int index = 1; while (i.hasNext()) { DataTableRow row = i.next(); double value = row.getValue(c); if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) { double indexValue = row.getValue(indexAxis); series.add(indexValue, value); } else { series.add(index++, value); } } dataset.addSeries(series); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Color color = getColorProvider().getPointColor(1.0d); if (numberOfSelectedColumns > 1) { color = getColorProvider() .getPointColor(columnCount / (double) (numberOfSelectedColumns - 1)); } renderer.setSeriesPaint(0, color); renderer.setSeriesStroke( 0, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); renderer.setSeriesShapesVisible(0, false); NumberAxis yAxis = new NumberAxis(dataTable.getColumnName(c)); if (getRangeForDimension(c) != null) { yAxis.setRange(getRangeForDimension(c)); } else { yAxis.setAutoRange(true); yAxis.setAutoRangeStickyZero(false); yAxis.setAutoRangeIncludesZero(false); } yAxis.setLabelFont(LABEL_FONT_BOLD); yAxis.setTickLabelFont(LABEL_FONT); if (numberOfSelectedColumns > 1) { yAxis.setAxisLinePaint(color); yAxis.setTickMarkPaint(color); yAxis.setLabelPaint(color); yAxis.setTickLabelPaint(color); } plot.setRangeAxis(columnCount, yAxis); plot.setRangeAxisLocation(columnCount, AxisLocation.TOP_OR_LEFT); plot.setDataset(columnCount, dataset); plot.setRenderer(columnCount, renderer); plot.mapDatasetToRangeAxis(columnCount, columnCount); columnCount++; } } } } chart.setBackgroundPaint(Color.white); return chart; }