List of usage examples for org.jfree.chart.plot XYPlot setDomainGridlinesVisible
public void setDomainGridlinesVisible(boolean visible)
From source file:de.citec.csra.allocation.vis.MovingChart.java
/** * Creates a sample chart.//from www .java2s. com * * @param dataset the dataset. * * @return A sample chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart result = ChartFactory.createTimeSeriesChart(null, "Time", "Resource", dataset, false, true, false); final XYPlot plot = result.getXYPlot(); plot.addDomainMarker(this.marker); plot.setBackgroundPaint(new Color(0xf8f8ed)); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.lightGray); ValueAxis xaxis = plot.getDomainAxis(); xaxis.setAutoRange(true); xaxis.setTickLabelsVisible(false); //Domain axis would show data of 60 seconds for a time xaxis.setFixedAutoRange(this.past + this.future); // 60 seconds xaxis.setVerticalTickLabels(true); ValueAxis yaxis = plot.getRangeAxis(); yaxis.setAutoRangeMinimumSize(1.8); yaxis.setAutoRange(true); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setTickUnit(new NumberTickUnit(1)); range.setNumberFormatOverride(new NumberFormat() { @Override public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { return format((long) number, toAppendTo, pos); } private String getID(long number) { return values.entrySet().stream().filter(e -> e.equals(number)).findFirst().get().getKey(); } @Override public StringBuffer format(long number, StringBuffer ap, FieldPosition pos) { String id = "N/A"; if (number == 0) { id = "(Time)"; } if (values.containsValue(number)) { for (Map.Entry<String, Long> entry : values.entrySet()) { if (entry.getValue() == number) { id = entry.getKey(); break; } } } id = id.replaceFirst("/$", ""); ap.append(id); if (id.length() > 32) { ap.replace(15, ap.length() - 15, ".."); } return ap; } @Override public Number parse(String source, ParsePosition parsePosition) { return null; } }); // this.chart.getXYPlot().getRenderer(1).set // XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) this.chart.getXYPlot().getRendererForDataset(dataset); return result; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.SimpleBlockChart.java
/** * Creates a chart for the specified dataset. * //from w ww .j a v a 2 s .c o m * @param dataset the dataset. * * @return A chart instance. */ public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1"); JFreeChart chart = null; NumberAxis xAxis = new NumberAxis(xLabel); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (xLowerBound != null && xUpperBound != null) { xAxis.setLowerBound(xLowerBound); xAxis.setUpperBound(xUpperBound); } else { xAxis.setAutoRange(true); } xAxis.setAxisLinePaint(Color.white); xAxis.setTickMarkPaint(Color.white); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { xAxis.setLabelFont(addLabelsStyle.getFont()); xAxis.setLabelPaint(addLabelsStyle.getColor()); } NumberAxis yAxis = new NumberAxis(yLabel); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (yLowerBound != null && yUpperBound != null) { yAxis.setLowerBound(yLowerBound); yAxis.setUpperBound(yUpperBound); } else yAxis.setAutoRange(true); yAxis.setAxisLinePaint(Color.white); yAxis.setTickMarkPaint(Color.white); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { yAxis.setLabelFont(addLabelsStyle.getFont()); yAxis.setLabelPaint(addLabelsStyle.getColor()); } XYBlockRenderer renderer = new XYBlockRenderer(); PaintScale paintScale = null; if (grayPaintScale) { paintScale = new GrayPaintScale(minScaleValue, maxScaleValue); } else { if (scaleLowerBound != null && scaleUpperBound != null) { paintScale = new LookupPaintScale(scaleLowerBound, scaleUpperBound, Color.gray); } else { paintScale = new LookupPaintScale(minScaleValue, maxScaleValue, Color.gray); } for (int i = 0; i < zRangeArray.length; i++) { ZRange zRange = zRangeArray[i]; ((LookupPaintScale) paintScale).add(zRange.getValue().doubleValue(), zRange.getColor()); } } renderer.setPaintScale(paintScale); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); plot.setForegroundAlpha(0.66f); 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(); NumberAxis scaleAxis = new NumberAxis(zLabel); scaleAxis.setAxisLinePaint(Color.white); scaleAxis.setTickMarkPaint(Color.white); scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7)); if (scaleLowerBound != null && scaleUpperBound != null) { scaleAxis.setLowerBound(scaleLowerBound); scaleAxis.setUpperBound(scaleUpperBound); } else scaleAxis.setAutoRange(true); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { scaleAxis.setLabelFont(addLabelsStyle.getFont()); scaleAxis.setLabelPaint(addLabelsStyle.getColor()); } if (blockHeight != null && blockWidth != null) { renderer.setBlockWidth(blockWidth.doubleValue()); renderer.setBlockHeight(blockHeight.doubleValue()); } PaintScaleLegend legend = new PaintScaleLegend(paintScale, scaleAxis); legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT); legend.setAxisOffset(5.0); legend.setMargin(new RectangleInsets(5, 5, 5, 5)); legend.setFrame(new BlockBorder(Color.black)); legend.setPadding(new RectangleInsets(10, 10, 10, 10)); legend.setStripWidth(10); legend.setPosition(RectangleEdge.RIGHT); legend.setBackgroundPaint(color); chart.addSubtitle(legend); // chart.setBackgroundPaint(new Color(180, 180, 250)); chart.setBackgroundPaint(color); logger.debug("OUT"); return chart; }
From source file:wef.articulab.view.ui.CombinedBNXYPlot.java
private XYPlot createPlot(ChartContainer chartContainer) { createDataset(chartContainer);/*from ww w. ja v a 2 s . co m*/ chartContainer.target = new IntervalMarker(14, 16); chartContainer.target.setLabel("Activation Threshold"); chartContainer.target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11)); chartContainer.target.setLabelAnchor(RectangleAnchor.LEFT); chartContainer.target.setLabelTextAnchor(TextAnchor.CENTER_LEFT); chartContainer.target.setPaint(new Color(222, 222, 255, 128)); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); BasicStroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); for (int i = 0; i < chartContainer.series.length - 1; i++) { renderer.setSeriesStroke(i, stroke); } renderer.setSeriesStroke(chartContainer.series.length - 1, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 10.0f }, 0.0f)); NumberAxis rangeAxis = new NumberAxis("Activation"); NumberAxis domainAxis = new NumberAxis("Time"); XYPlot plot = new XYPlot(chartContainer.dataset, domainAxis, rangeAxis, renderer); plot.addRangeMarker(chartContainer.target, Layer.BACKGROUND); plot.setRenderer(renderer); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setBackgroundPaint(Color.LIGHT_GRAY); chartContainer.plot = plot; return plot; }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.MatrixChart.java
private void buildMainChart(String title, String subTitle, String xAxisLabel, String yAxisLabel, String fileName) {//from w w w. ja v a 2 s .c om final MatrixSeriesCollection dataset = new MatrixSeriesCollection(this.createMatrixDataSet()); final JFreeChart chart = ChartFactory.createBubbleChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); chart.addSubtitle(new TextTitle(subTitle)); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.WHITE)); chart.removeLegend(); // Perform customizations starts here ... final XYPlot plot1 = chart.getXYPlot(); plot1.setDomainGridlinesVisible(false); plot1.setRangeGridlinesVisible(false); plot1.setForegroundAlpha(0.5f); plot1.setDomainAxis(new CustomAxis(plot1.getDomainAxis().getLabel())); plot1.setRangeAxis(new CustomAxis(plot1.getRangeAxis().getLabel())); // Custumize the domain axis ( y ) final NumberAxis domainAxis = (NumberAxis) plot1.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); domainAxis.setRange(-1, this.array.length); // Custumize the range axis ( y ) final NumberAxis rangeAxis = (NumberAxis) plot1.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setRange(-1, this.array.length); // Create custom renderer StandardXYItemRenderer ren = new CustomRenderer(false); ren.setSeriesItemLabelPaint(0, Color.BLACK); plot1.setRenderer(ren); this.mainChart = chart; }
From source file:adams.flow.sink.JFreeChartPlot.java
/** * Creates a new display panel for the token. * * @param token the token to display in a new panel, can be null * @return the generated panel/* w w w .j ava 2 s .c om*/ */ @Override public DisplayPanel createDisplayPanel(Token token) { AbstractDisplayPanel result; result = new AbstractComponentDisplayPanel(getClass().getSimpleName()) { private static final long serialVersionUID = -3785685146120118884L; protected JFreeChart m_JFreeChart; protected ChartPanel m_PlotPanel; @Override protected void initGUI() { super.initGUI(); setLayout(new BorderLayout()); } @Override public void display(Token token) { SpreadSheet sheet = (SpreadSheet) token.getPayload(); Dataset dataset = m_Dataset.generate(sheet); m_JFreeChart = m_Chart.generate(dataset); if (m_JFreeChart.getPlot() instanceof XYPlot) { XYPlot plot = (XYPlot) m_JFreeChart.getPlot(); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.GRAY); plot.getRenderer().setSeriesPaint(0, m_PlotColor); if (plot.getSeriesCount() > 1) plot.getRenderer().setSeriesPaint(1, m_DiagonalColor); Shape shape = m_Shape.generate(); if (shape != null) plot.getRenderer().setSeriesShape(0, shape); } m_PlotPanel = new ChartPanel(m_JFreeChart); removeAll(); add(m_PlotPanel, BorderLayout.CENTER); } @Override public void clearPanel() { removeAll(); m_JFreeChart = null; } @Override public void cleanUp() { removeAll(); m_JFreeChart = null; } @Override public JComponent supplyComponent() { return m_PlotPanel; } }; if (token != null) result.display(token); return result; }
From source file:net.nosleep.superanalyzer.analysis.views.YearView.java
private void createChart() { NumberAxis xAxis = new NumberAxis(Misc.getString("RELEASE_YEAR")); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(Misc.getString("SONG_COUNT")); yAxis.setAutoRangeIncludesZero(true); xAxis.setNumberFormatOverride(new DecimalFormat("0")); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); XYPlot plot = new XYPlot(_dataset, xAxis, yAxis, renderer); // create and return the chart panel... _chart = new JFreeChart(Misc.getString("RELEASE_YEAR"), JFreeChart.DEFAULT_TITLE_FONT, plot, true); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4)); LegendTitle legend = _chart.getLegend(); legend.setFrame(BlockBorder.NONE);/*w w w . j a v a2s . c o m*/ _chart.addSubtitle(HomePanel.createSubtitle(Misc.getString("RELEASE_YEAR_TOOLTIP"))); XYToolTipGenerator generator = new StandardXYToolTipGenerator("{2}", new DecimalFormat("0.00"), new DecimalFormat("0.00")); renderer.setToolTipGenerator(generator); ChartUtilities.applyCurrentTheme(_chart); // format the lines after applying the theme renderer.setBaseShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(Color.white); renderer.setSeriesStroke(0, new BasicStroke(3.0f)); renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f)); renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0)); renderer.setSeriesStroke(1, new BasicStroke(3.0f)); renderer.setSeriesOutlineStroke(1, new BasicStroke(2.0f)); renderer.setSeriesShape(1, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0)); _chart.setPadding(new RectangleInsets(10, 10, 10, 10)); Misc.formatChart(plot); }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.MatrixChart.java
private void buildLegendChart(int nbValues) { this.legendValues = new int[nbValues + 1]; this.legendValues[0] = 0; int offset = 255 / nbValues; int step = offset; if (this.scaleMode == Chart.Scale.LOGARITHMIC) { double logStep = (Math.log(this.maxValue) / Math.log(2)) / nbValues; for (int i = 1; i < (nbValues + 1); i++) { this.legendValues[i] = (int) Math.pow(2, logStep * i); }//from ww w .j a va 2 s. c o m } else { // Linear scale mode for (int i = 1; i < (nbValues + 1); i++) { this.legendValues[i] = (step * this.maxValue) / 255; step += offset; } } final MatrixSeriesCollection dataset = new MatrixSeriesCollection(this.createLegendDataSet()); final JFreeChart chart = ChartFactory.createBubbleChart("", "", "", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.WHITE)); chart.removeLegend(); // Perform customizations starts here ... final XYPlot plot1 = chart.getXYPlot(); plot1.setDomainGridlinesVisible(false); plot1.setRangeGridlinesVisible(false); plot1.setForegroundAlpha(0.5f); plot1.setDomainAxis(new CustomAxis(plot1.getDomainAxis().getLabel())); plot1.setRangeAxis(new CustomAxis(plot1.getRangeAxis().getLabel())); // Custumize the domain axis ( x ) final NumberAxis domainAxis = (NumberAxis) plot1.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); domainAxis.setRange(-1, 1); domainAxis.setVisible(false); // Custumize the range axis ( y ) final NumberAxis rangeAxis = (NumberAxis) plot1.getRangeAxis(); rangeAxis.setTickUnit(new CustomTickUnit(rangeAxis.getTickUnit().getSize())); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setRange(-1, this.legendValues.length); rangeAxis.setTickLabelsVisible(true); rangeAxis.setTickMarkInsideLength(4); // Create custom renderer StandardXYItemRenderer ren = new CustomRenderer(true); ren.setSeriesItemLabelPaint(0, Color.BLUE); plot1.setRenderer(ren); plot1.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT); this.legendChart = chart; }
From source file:charts.Chart.java
public static JFreeChart MultipleSplineLineChart(XYDataset[] datasets, String title, String x_axis_label, String y_axis_label, boolean showlegend, float maxvalue, float minvalue, boolean showchart) { ValueAxis domainAxis = new NumberAxis(x_axis_label); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); ValueAxis rangeAxis = new NumberAxis(y_axis_label); rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); if (minvalue == 0 && maxvalue == 0) { rangeAxis.setAutoRange(true);/*from w w w . j a v a2s. c o m*/ } else { rangeAxis.setRange(minvalue, maxvalue); } //define o grafo combinado, determinando o label do eixo x. CombinedDomainXYPlot parent = new CombinedDomainXYPlot(domainAxis); for (int i = 0; i < datasets.length; i++) { XYSplineRenderer renderer = new XYSplineRenderer(); renderer.setBaseStroke(new BasicStroke(2.0f)); renderer.setBaseSeriesVisibleInLegend(showlegend); renderer.setShapesVisible(true); XYPlot subplot = new XYPlot(datasets[i], domainAxis, rangeAxis, renderer); subplot.setBackgroundPaint(Color.white); subplot.setRangeGridlinePaint(Color.black); subplot.setDomainGridlinesVisible(true); parent.add(subplot, 1); } JFreeChart jfreechart = new JFreeChart(title, parent); JPanel jpanel = new ChartPanel(jfreechart); jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight)); if (showchart) { JFrame chartwindow = new JFrame(title); chartwindow.setContentPane(jpanel); chartwindow.pack(); RefineryUtilities.centerFrameOnScreen(chartwindow); chartwindow.setVisible(true); } return jfreechart; }
From source file:net.nosleep.superanalyzer.analysis.views.PlayCountView.java
private void createChart() { _chart = ChartFactory.createXYBarChart(Misc.getString("PLAY_COUNT"), Misc.getString("PLAY_COUNT"), false, Misc.getString("NUMBER_OF_SONGS"), _dataset, PlotOrientation.VERTICAL, false, true, false); _chart.addSubtitle(HomePanel.createSubtitle(Misc.getString("PLAY_COUNT_SUBTITLE"))); // then customise it a little... XYPlot plot = (XYPlot) _chart.getPlot(); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); plot.setForegroundAlpha(0.75f);/*from w w w . ja v a2 s .c o m*/ ChartUtilities.applyCurrentTheme(_chart); renderer.setBarPainter(new StandardXYBarPainter()); renderer.setShadowVisible(false); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); domainAxis.setLowerMargin(0); domainAxis.setUpperMargin(0); // domainAxis.setLowerBound(0); // domainAxis.setAutoRangeIncludesZero(true); // domainAxis.setAutoRangeStickyZero(true); Misc.formatChart(plot); renderer.setSeriesPaint(0, Theme.getColorSet()[1]); }
From source file:GraphUI.java
/** * Creates new form GraphUI/*from w w w .ja v a 2 s .co m*/ */ public GraphUI() { try { //graphPane is the jPanel in the jFrame //cp is the ChartPanel that needs to be held inside jPanel1 initComponents(); data = Pinwheel.getData(); this.batch = data[0]; //jPanel1 = createChartPanel(); cp = createChartPanel(); //cp = new ChartPanel(chart); cp.setMouseWheelEnabled(true); jPanel1.add(cp); XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesStroke(0, new BasicStroke(3.0f)); renderer.setSeriesStroke(1, new BasicStroke(3.0f)); plot.setBackgroundPaint(Color.DARK_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.BLACK); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.BLACK); plot.setRenderer(renderer); this.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent windowEvent) { backBtn.doClick(); } }); } catch (SQLException ex) { Logger.getLogger(GraphUI.class.getName()).log(Level.SEVERE, null, ex); } }