List of usage examples for org.jfree.chart.axis NumberAxis setPositiveArrowVisible
public void setPositiveArrowVisible(boolean visible)
From source file:jgnash.ui.budget.BudgetSparkline.java
public static Icon getSparklineImage(final List<BigDecimal> amounts) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); final boolean[] negate = new boolean[amounts.size()]; for (int i = 0; i < amounts.size(); i++) { dataset.addValue(amounts.get(i), CATEGORY, i); negate[i] = amounts.get(i).signum() == -1; }/*from ww w .j a va 2 s . c o m*/ CategoryAxis xAxis = new CategoryAxis(); xAxis.setTickLabelsVisible(false); xAxis.setTickMarksVisible(false); xAxis.setAxisLineVisible(false); xAxis.setVisible(false); NumberAxis yAxis = new NumberAxis(); yAxis.setTickLabelsVisible(false); yAxis.setTickMarksVisible(false); yAxis.setAxisLineVisible(false); yAxis.setNegativeArrowVisible(false); yAxis.setPositiveArrowVisible(false); yAxis.setAutoRangeIncludesZero(true); yAxis.setAutoRange(true); yAxis.setVisible(false); BarRenderer renderer = new BarRenderer() { @Override public Paint getItemPaint(final int row, final int column) { return negate[column] ? Color.RED : Color.BLACK; } }; renderer.setShadowVisible(false); renderer.setBarPainter(new StandardBarPainter()); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setInsets(INSETS); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setBackgroundPaint(CLEAR); JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBorderVisible(false); chart.setBackgroundPaint(CLEAR); Icon icon = EMPTY_ICON; try { byte[] image = ENCODER .encode(chart.createBufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.BITMASK, null)); icon = new ImageIcon(image); } catch (IOException ex) { Logger.getLogger(BudgetSparkline.class.getName()).log(Level.SEVERE, null, ex); } return icon; }
From source file:PlotsBuilding.PlotPanel.java
private JFreeChart createChart(XYDataset xyDataset, ArrayList<Integer> seriesCount, double y1, double y2) { NumberAxis domainAxis = new NumberAxis("x"); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setPositiveArrowVisible(true); NumberAxis rangeAxis = new NumberAxis("y"); rangeAxis.setRange(y1, y2);//from w ww . j av a2 s . com rangeAxis.setPositiveArrowVisible(true); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); int start = 0; int color = 50; for (Object series : seriesCount) { for (int i = start; i < start + (int) series; i++) { Color s = new Color(color); renderer.setSeriesPaint(i, s); renderer.setSeriesVisibleInLegend(i, false); renderer.setSeriesVisibleInLegend(start, true); } start = start + (int) series; color *= 100; } renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); XYPlot plot = new XYPlot(xyDataset, domainAxis, rangeAxis, renderer); PlotOrientation orientation = PlotOrientation.VERTICAL; plot.setOrientation(orientation); plot.setBackgroundPaint(Color.white); chart = new JFreeChart(plot); chart.setBackgroundPaint(Color.white); chart.getLegend().setPosition(RectangleEdge.RIGHT); chart.getLegend().setVerticalAlignment(VerticalAlignment.TOP); return chart; }
From source file:net.sf.maltcms.common.charts.ui.XYChartComponentOpenAction.java
@Override public void actionPerformed(ActionEvent e) { Task t = RequestProcessor.getDefault().create(new Runnable() { @Override/*from w w w.jav a2 s. c o m*/ public void run() { final Numeric1DDataset<Point2D> dataset = createDataset(); final XYChartBuilder builder = new XYChartBuilder(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setDefaultEntityRadius(50); NumberAxis domain = new NumberAxis("x-axis"); domain.setLowerBound(-100); domain.setUpperBound(1000); domain.setLowerMargin(0.1); domain.setUpperMargin(0.1); domain.setPositiveArrowVisible(true); domain.setNegativeArrowVisible(true); builder.xy(dataset).renderer(renderer).domainAxis(domain).useBuffer(false).minimumDrawSize(400, 300) .preferredDrawSize(800, 600).plot().chart("Sample plot").createLegend(true); invokeLater(new Runnable() { @Override public void run() { TopComponent tc = WindowManager.getDefault().findTopComponent("navigatorTC"); if (tc != null) { tc.open(); } } }); invokeLater(new Runnable() { @Override public void run() { XYChartTopComponent<Point2D> xytc = new XYChartTopComponent<>(Point2D.class, dataset, builder); xytc.open(); xytc.requestActive(); } }); } }); RequestProcessor.getDefault().post(t); }
From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java
/** * Generates a SparkLine Time Area Chart. * @param key/* w w w.j a v a 2s .c o m*/ * @param stats * @param startTime * @param endTime * @return chart */ private JFreeChart generateSparklineAreaChart(String key, String color, Statistic[] stats, long startTime, long endTime, int dataPoints) { Color backgroundColor = getBackgroundColor(); XYDataset dataset = populateData(key, stats, startTime, endTime, dataPoints); JFreeChart chart = ChartFactory.createXYAreaChart(null, // chart title null, // xaxis label null, // yaxis label dataset, // data PlotOrientation.VERTICAL, false, // include legend false, // tooltips? false // URLs? ); chart.setBackgroundPaint(backgroundColor); chart.setBorderVisible(false); chart.setBorderPaint(null); XYPlot plot = (XYPlot) chart.getPlot(); plot.setForegroundAlpha(1.0f); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setBackgroundPaint(backgroundColor); plot.setRangeGridlinesVisible(false); GraphDefinition graphDef = GraphDefinition.getDefinition(color); Color plotColor = graphDef.getInlineColor(0); plot.getRenderer().setSeriesPaint(0, plotColor); plot.getRenderer().setBaseItemLabelsVisible(false); plot.getRenderer().setBaseOutlinePaint(backgroundColor); plot.setOutlineStroke(null); plot.setDomainGridlinePaint(null); NumberAxis xAxis = (NumberAxis) chart.getXYPlot().getDomainAxis(); xAxis.setLabel(null); xAxis.setTickLabelsVisible(true); xAxis.setTickMarksVisible(true); xAxis.setAxisLineVisible(false); xAxis.setNegativeArrowVisible(false); xAxis.setPositiveArrowVisible(false); xAxis.setVisible(false); NumberAxis yAxis = (NumberAxis) chart.getXYPlot().getRangeAxis(); yAxis.setTickLabelsVisible(false); yAxis.setTickMarksVisible(false); yAxis.setAxisLineVisible(false); yAxis.setNegativeArrowVisible(false); yAxis.setPositiveArrowVisible(false); yAxis.setVisible(false); return chart; }