List of usage examples for java.awt Color green
Color green
To view the source code for java.awt Color green.
Click Source Link
From source file:j2se.jfreechart.barchart.BarChartDemo4.java
/** * Creates a sample chart./*from w w w. j a v a 2 s . com*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(new Color(0xBBBBDD)); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setMaximumBarWidth(0.10); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:LoggerGUI.DataLogger.java
public DataLogger(String title) { super(title); initialize();//from w ww. jav a 2 s . c o m final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time")); this.datasets = new TimeSeriesCollection[INPUT_COUNT]; this.lastValue[0] = 100.0; this.lastValue[1] = 100.0; this.lastValue[2] = 100.0; this.lastValue[3] = 100.0; final TimeSeries s0 = new TimeSeries("A0", Millisecond.class); final TimeSeries s1 = new TimeSeries("A1", Millisecond.class); final TimeSeries s2 = new TimeSeries("A2", Millisecond.class); final TimeSeries s3 = new TimeSeries("A3", Millisecond.class); this.datasets[0] = new TimeSeriesCollection(s0); this.datasets[1] = new TimeSeriesCollection(s1); this.datasets[2] = new TimeSeriesCollection(s2); this.datasets[3] = new TimeSeriesCollection(s3); final NumberAxis rangeAxis = new NumberAxis("ADC Signal"); rangeAxis.setAutoRangeIncludesZero(false); XYPlot subplot; XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true,false); XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(true,false); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true,false); XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(true,false); subplot= new XYPlot( new TimeSeriesCollection(), null, rangeAxis, new XYLineAndShapeRenderer(true,false) ); plot.add(subplot); renderer.setBaseShapesVisible(false); renderer.setSeriesPaint(0, Color.red); subplot.setDataset(0,datasets[0]); subplot.setRenderer(0,renderer); renderer1.setBaseShapesVisible(false); renderer1.setSeriesPaint(0, Color.blue); subplot.setDataset(1,datasets[1]); subplot.setRenderer(1,renderer1); renderer2.setBaseShapesVisible(false); renderer2.setSeriesPaint(0, Color.black); subplot.setDataset(2,datasets[2]); subplot.setRenderer(2,renderer2); subplot.getRendererForDataset(subplot.getDataset(0)).setSeriesPaint(0, Color.red); subplot.getRendererForDataset(subplot.getDataset(1)).setSeriesPaint(1, Color.blue); subplot.getRendererForDataset(subplot.getDataset(2)).setSeriesPaint(2, Color.black); renderer3.setBaseShapesVisible(false); renderer3.setSeriesPaint(0, Color.green); subplot.setDataset(3,datasets[3]); subplot.setRenderer(3,renderer3); final JFreeChart chart = new JFreeChart("Data Logger", plot); chart.setBorderPaint(Color.black); chart.setBorderVisible(true); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(20000.0); // 60 seconds final JPanel content = new JPanel(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); final JPanel buttonPanel = new JPanel(new FlowLayout()); content.add(buttonPanel, BorderLayout.NORTH); chartPanel.setPreferredSize(new java.awt.Dimension(600, 600)); chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setContentPane(content); }
From source file:org.hxzon.demo.jfreechart.PieDatasetDemo2.java
private static JFreeChart createPieChart(PieDataset dataset, PieDataset previousDataset) { final boolean greenForIncrease = true; final boolean subTitle = true; final boolean showDifference = true; int percentDiffForMaxScale = 20; PiePlot plot = new PiePlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { plot.setToolTipGenerator(new StandardPieToolTipGenerator()); }//from w ww .ja v a 2 s . c o m if (urls) { plot.setURLGenerator(new StandardPieURLGenerator()); } @SuppressWarnings({ "rawtypes", "unchecked" }) List<Comparable> keys = dataset.getKeys(); DefaultPieDataset series = null; if (showDifference) { series = new DefaultPieDataset(); } double colorPerPercent = 255.0 / percentDiffForMaxScale; for (@SuppressWarnings("rawtypes") Comparable key : keys) { Number newValue = dataset.getValue(key); Number oldValue = previousDataset.getValue(key); if (oldValue == null) { if (greenForIncrease) { plot.setSectionPaint(key, Color.green); } else { plot.setSectionPaint(key, Color.red); } if (showDifference) { series.setValue(key + " (+100%)", newValue); } } else { double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0; double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 : Math.abs(percentChange) * colorPerPercent); if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue() || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) { plot.setSectionPaint(key, new Color(0, (int) shade, 0)); } else { plot.setSectionPaint(key, new Color((int) shade, 0, 0)); } if (showDifference) { series.setValue( key + " (" + (percentChange >= 0 ? "+" : "") + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")", newValue); } } } if (showDifference) { plot.setDataset(series); } JFreeChart chart = new JFreeChart("Pie Chart Demo 2", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); if (subTitle) { TextTitle subtitle = null; subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-" + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+" + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10)); chart.addSubtitle(subtitle); } plot.setNoDataMessage("No data available"); return chart; }
From source file:asl.util.PlotMaker.java
public void plotZNE_3x3(ArrayList<double[]> channelData, double[] xsecs, int nstart, int nend, String eventString, String plotString) { // Expecting 9 channels packed like: Panel Trace1 Trace2 Trace3 // channels[0] = 00-LHZ 1 00-LHZ 10-LHZ 20-LHZ // channels[1] = 00-LHND 2 00-LHND 10-LHND 20-LHND // channels[2] = 00-LHED 3 00-LHED 10-LHED 20-LHED // channels[3] = 10-LHZ // channels[4] = 10-LHND // channels[5] = 10-LHED // channels[6] = 20-LHZ // channels[7] = 20-LHND // channels[8] = 20-LHED final String plotTitle = String.format("%04d%03d [Stn:%s] [Event:%s] %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, eventString, plotString); final String pngName = String.format("%s/%s.%s.%s.png", outputDir, eventString, station, plotString); File outputFile = new File(pngName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format("== plotZNE_3x3: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return;/* ww w . j av a 2 s. c om*/ } if (channelData.size() != channels.length) { System.out.format("== plotZNE_3x3: Error: We have [%d channels] but [%d channelData]\n", channels.length, channelData.size()); return; } XYSeries[] series = new XYSeries[channels.length]; for (int i = 0; i < channels.length; i++) { series[i] = new XYSeries(channels[i].toString()); double[] data = channelData.get(i); //for (int k = 0; k < xsecs.length; k++){ for (int k = 0; k < data.length; k++) { series[i].add(xsecs[k], data[k]); } } // I. Panel I = Verticals // Use the first data array, within the plotted range (nstart - nend) to scale the plots: double[] data = channelData.get(0); double ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Paint[] paints = new Paint[] { Color.red, Color.blue, Color.green }; for (int i = 0; i < paints.length; i++) { renderer.setSeriesPaint(i, paints[i]); renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, false); } final NumberAxis verticalAxis = new NumberAxis("Displacement (m)"); verticalAxis.setRange(new Range(-ymax, ymax)); //verticalAxis.setTickUnit( new NumberTickUnit(5) ); final NumberAxis horizontalAxis = new NumberAxis("Time (s)"); horizontalAxis.setRange(new Range(nstart, nend)); //horizontalAxis.setRange( new Range(0.00009 , 110) ); final NumberAxis hAxis = new NumberAxis("Time (s)"); hAxis.setRange(new Range(nstart, nend)); final XYSeriesCollection seriesCollection1 = new XYSeriesCollection(); seriesCollection1.addSeries(series[0]); seriesCollection1.addSeries(series[3]); seriesCollection1.addSeries(series[6]); //final XYPlot xyplot1 = new XYPlot((XYDataset)seriesCollection1, null, verticalAxis, renderer); //final XYPlot xyplot1 = new XYPlot((XYDataset)seriesCollection1, horizontalAxis, verticalAxis, renderer); final XYPlot xyplot1 = new XYPlot((XYDataset) seriesCollection1, hAxis, verticalAxis, renderer); double x = .95 * xsecs[nend]; double y = .90 * ymax; XYTextAnnotation annotation1 = new XYTextAnnotation("Vertical", x, y); annotation1.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot1.addAnnotation(annotation1); // II. Panel II = North // Use the first data array, within the plotted range (nstart - nend) to scale the plots: data = channelData.get(1); ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final NumberAxis verticalAxisN = new NumberAxis("Displacement (m)"); verticalAxisN.setRange(new Range(-ymax, ymax)); final XYSeriesCollection seriesCollection2 = new XYSeriesCollection(); seriesCollection2.addSeries(series[1]); seriesCollection2.addSeries(series[4]); seriesCollection2.addSeries(series[7]); final XYPlot xyplot2 = new XYPlot((XYDataset) seriesCollection2, null, verticalAxisN, renderer); XYTextAnnotation annotation2 = new XYTextAnnotation("North-South", x, y); annotation2.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot2.addAnnotation(annotation2); // III. Panel III = East // Use the first data array, within the plotted range (nstart - nend) to scale the plots: data = channelData.get(2); ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final NumberAxis verticalAxisE = new NumberAxis("Displacement (m)"); verticalAxisE.setRange(new Range(-ymax, ymax)); final XYSeriesCollection seriesCollection3 = new XYSeriesCollection(); seriesCollection3.addSeries(series[2]); seriesCollection3.addSeries(series[5]); seriesCollection3.addSeries(series[8]); final XYPlot xyplot3 = new XYPlot((XYDataset) seriesCollection3, null, verticalAxisE, renderer); XYTextAnnotation annotation3 = new XYTextAnnotation("East-West", x, y); annotation3.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot3.addAnnotation(annotation3); //CombinedXYPlot combinedPlot = new CombinedXYPlot( horizontalAxis, CombinedXYPlot.VERTICAL ); CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis); combinedPlot.add(xyplot1, 1); combinedPlot.add(xyplot2, 1); combinedPlot.add(xyplot3, 1); combinedPlot.setGap(15.); final JFreeChart chart = new JFreeChart(combinedPlot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 800); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:org.f3.tools.framework.Reporter.java
private String generateImage(String refName, String name, Number changeFactor) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(changeFactor, 0, 0); JFreeChart chart = ChartFactory.createBarChart("", "", "%change", dataset, PlotOrientation.HORIZONTAL, false, false, false);/*from www .j a v a 2 s .c o m*/ try { Color bgcolor = null; double value = changeFactor.doubleValue(); if (value == Double.POSITIVE_INFINITY || value == Double.NEGATIVE_INFINITY) { bgcolor = Color.YELLOW; } else if (value > 5) { bgcolor = Color.GREEN; } else if (value >= -5 && value <= 5) { bgcolor = Color.WHITE; } else { bgcolor = Color.RED; } chart.setBackgroundPaint(bgcolor); File dirFile = new File(IMAGE_DIRNAME); if (!dirFile.exists()) { dirFile.mkdirs(); } File ofile = new File(dirFile, name); ChartUtilities.saveChartAsPNG(ofile, chart, 300, 100); return getImageRef(refName, name); } catch (IOException ioe) { Utils.logger.severe(ioe.getMessage()); } return null; }
From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart2.java
public static JFreeChart createChart(DataItems nor, DataItems abnor, String title, String protocol1, String protocol2) {// ww w .j a va 2s .c o m // ? XYDataset xydataset1 = TimeSeriesChart1.createNormalDataset(nor, protocol1); JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "", "", xydataset1); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); XYLineAndShapeRenderer xylineandshaperenderer1 = (XYLineAndShapeRenderer) xyplot.getRenderer(); // ??1?1 NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 6D, 6D); // ??? // ?? xylineandshaperenderer1.setSeriesLinesVisible(0, true); xylineandshaperenderer1.setBaseShapesVisible(false); xylineandshaperenderer1.setSeriesShape(0, double1); xylineandshaperenderer1.setSeriesPaint(0, Color.blue); xylineandshaperenderer1.setSeriesFillPaint(0, Color.blue); xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.blue); xylineandshaperenderer1.setSeriesStroke(0, new BasicStroke(0.5F)); // ? XYDataset xydataset2 = TimeSeriesChart1.createNormalDataset(abnor, protocol2); /* XYTextAnnotation localXYTextAnnotation = new XYTextAnnotation("aa",10, Double.parseDouble(abnor.getElementAt(10).getData())); xyplot.addAnnotation(localXYTextAnnotation);*/ XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer(); int datasetcount = xyplot.getDatasetCount(); xyplot.setDataset(datasetcount, xydataset2); xyplot.setRenderer(datasetcount, xylineandshaperenderer2); /* System.out.println("DatasetCount="+xyplot.getDatasetCount()); for(int c=0;c<xyplot.getDatasetCount();c++){ System.out.println("DatasetSeriesCount="+xyplot.getDataset(c).getSeriesCount()); System.out.println("Dataset["+c+"]="+xyplot.getDataset(c).getSeriesKey(0)); }*/ /* // ??? xylineandshaperenderer2.setBaseShapesVisible(false); // ?? xylineandshaperenderer2.setSeriesLinesVisible(0, true); xylineandshaperenderer2.setSeriesShape(0, double1); // xylineandshaperenderer2.setSeriesPaint(0, Color.green); xylineandshaperenderer2.setSeriesFillPaint(0, Color.green); xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green); xylineandshaperenderer2.setUseFillPaint(true); xylineandshaperenderer2 .setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F)); */ xylineandshaperenderer2.setSeriesLinesVisible(0, true); xylineandshaperenderer2.setBaseShapesVisible(false); xylineandshaperenderer2.setSeriesShape(0, double1); xylineandshaperenderer2.setSeriesPaint(0, Color.GREEN); xylineandshaperenderer2.setSeriesFillPaint(0, Color.GREEN); xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green); xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F)); jfreechart.getLegend().setVisible(true); return jfreechart; }
From source file:org.trade.ui.chart.renderer.VolumeBarRenderer.java
/** * Draws the visual representation of a single data item. * /* w w w . ja va 2s . c om*/ * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the area within which the plot is being drawn. * @param info * collects information about the drawing. * @param plot * the plot (can be used to obtain standard color information * etc). * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param dataset * the dataset. * @param series * the series index (zero-based). * @param item * the item index (zero-based). * @param crosshairState * crosshair information for the plot (<code>null</code> * permitted). * @param pass * the pass index. * @see org.jfree.chart.renderer.xy.XYItemRenderer#drawItem(Graphics2D, * XYItemRendererState, Rectangle2D, PlotRenderingInfo, XYPlot, * ValueAxis, ValueAxis, XYDataset, int, int, CrosshairState, int) */ public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { if (!getItemVisible(series, item)) { return; } VolumeDataset volumeDataset = (VolumeDataset) dataset; VolumeItem volumeItem = (VolumeItem) volumeDataset.getSeries(series).getDataItem(item); if (volumeItem.isSide()) { this.color = Color.GREEN; } else { this.color = Color.RED; } double value0; double value1; if (this.getUseYInterval()) { value0 = volumeDataset.getStartYValue(series, item); value1 = volumeDataset.getEndYValue(series, item); } else { value0 = this.getBase(); value1 = volumeDataset.getYValue(series, item); } if (Double.isNaN(value0) || Double.isNaN(value1)) { return; } if (value0 <= value1) { if (!rangeAxis.getRange().intersects(value0, value1)) { return; } } else { if (!rangeAxis.getRange().intersects(value1, value0)) { return; } } double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge()); double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge()); double bottom = Math.min(translatedValue0, translatedValue1); double top = Math.max(translatedValue0, translatedValue1); double startX = volumeItem.getPeriod().getFirstMillisecond(); if (Double.isNaN(startX)) { return; } double endX = volumeItem.getPeriod().getLastMillisecond(); if (Double.isNaN(endX)) { return; } if (startX <= endX) { if (!domainAxis.getRange().intersects(startX, endX)) { return; } } else { if (!domainAxis.getRange().intersects(endX, startX)) { return; } } // is there an alignment adjustment to be made? if (this.getBarAlignmentFactor() >= 0.0 && this.getBarAlignmentFactor() <= 1.0) { double x = volumeDataset.getXValue(series, item); double interval = endX - startX; startX = x - interval * this.getBarAlignmentFactor(); endX = startX + interval; } RectangleEdge location = plot.getDomainAxisEdge(); double translatedStartX = domainAxis.valueToJava2D(startX, dataArea, location); double translatedEndX = domainAxis.valueToJava2D(endX, dataArea, location); double translatedWidth = Math.max(1, Math.abs(translatedEndX - translatedStartX)); RectangleEdge domainEdge = plot.getDomainAxisEdge(); double xx = domainAxis.valueToJava2D(startX, dataArea, domainEdge); if (getMargin() > 0.0) { double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; } Rectangle2D bar = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { // clip left and right bounds to data area bottom = Math.max(bottom, dataArea.getMinX()); top = Math.min(top, dataArea.getMaxX()); bar = new Rectangle2D.Double(bottom, xx, top - bottom, translatedWidth); } else if (orientation == PlotOrientation.VERTICAL) { // clip top and bottom bounds to data area bottom = Math.max(bottom, dataArea.getMinY()); top = Math.min(top, dataArea.getMaxY()); bar = new Rectangle2D.Double(xx - (translatedWidth / 2), bottom, translatedWidth, top - bottom); } boolean positive = (value1 > 0.0); boolean inverted = rangeAxis.isInverted(); RectangleEdge barBase; if (orientation == PlotOrientation.HORIZONTAL) { if (positive && inverted || !positive && !inverted) { barBase = RectangleEdge.RIGHT; } else { barBase = RectangleEdge.LEFT; } } else { if (positive && !inverted || !positive && inverted) { barBase = RectangleEdge.BOTTOM; } else { barBase = RectangleEdge.TOP; } } if (getShadowsVisible()) { this.getBarPainter().paintBarShadow(g2, this, series, item, bar, barBase, !this.getUseYInterval()); } this.getBarPainter().paintBar(g2, this, series, item, bar, barBase); if (isItemLabelVisible(series, item)) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); drawItemLabel(g2, dataset, series, item, plot, generator, bar, value1 < 0.0); } // update the cross hair point double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); double transX1 = domainAxis.valueToJava2D(x1, dataArea, location); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge()); int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, plot.getOrientation()); EntityCollection entities = state.getEntityCollection(); // add an entity for the item... if (entities != null) { String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } XYItemEntity entity = new XYItemEntity(bar, dataset, series, item, tip, null); entities.add(entity); } }
From source file:barChart1.BarChartDemo.java
/** * Creates a sample chart.//w w w. jav a 2 s . c om * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("Belgium vs Italy vs Ireland ", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(64, 0, 0)); GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.yellow, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); renderer.setSeriesPaint(3, gp2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:de.codesourcery.jasm16.ide.ui.viewcontainers.Perspective.java
public Perspective(String id, final ViewContainerManager viewContainerManager, IApplicationConfig appConfig) { super("jASM16 DCPU emulator V" + de.codesourcery.jasm16.compiler.Compiler.getVersionNumber()); if (viewContainerManager == null) { throw new IllegalArgumentException("viewContainerManager must not be null"); }// w w w .ja v a 2 s . co m if (appConfig == null) { throw new IllegalArgumentException("appConfig must not be null"); } if (StringUtils.isBlank(id)) { throw new IllegalArgumentException("ID must not be NULL/blank."); } this.viewContainerManager = viewContainerManager; this.id = id; this.applicationConfig = appConfig; setPreferredSize(new Dimension(400, 200)); getContentPane().add(desktop); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBackground(Color.BLACK); setForeground(Color.GREEN); desktop.setBackground(Color.BLACK); desktop.setForeground(Color.GREEN); menuManager.addEntry(new MenuEntry("File/Quit") { @Override public void onClick() { dispose(); try { applicationConfig.saveConfiguration(); } catch (IOException e) { e.printStackTrace(); } finally { System.exit(0); } } }); final SizeAndLocation sizeAndLoc = applicationConfig.getViewCoordinates(getID()); if (sizeAndLoc != null) { setLocation(sizeAndLoc.getLocation()); setSize(sizeAndLoc.getSize()); setPreferredSize(sizeAndLoc.getSize()); } else { setPreferredSize(new Dimension(600, 800)); pack(); } setJMenuBar(menuManager.getMenuBar()); }
From source file:com.netsteadfast.greenstep.action.CommonMeterChartAction.java
private void fillChart(String title, float value, int lowerBound, int upperBound) throws Exception { DefaultValueDataset dataset = new DefaultValueDataset(); dataset.setValue(value);/* w ww . j av a 2 s. c o m*/ DialPlot plot = new DialPlot(); plot.setView(0.0d, 0.0d, 1.0d, 1.0d); plot.setDataset(0, dataset); StandardDialFrame frame = new StandardDialFrame(); plot.setDialFrame(frame); DialBackground dialBackground = new DialBackground(); dialBackground.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); plot.setBackground(dialBackground); DialTextAnnotation textAnnotation = new DialTextAnnotation(title); textAnnotation.setRadius(0.555555555555555555D); plot.addLayer(textAnnotation); DialValueIndicator valueIndicator = new DialValueIndicator(0); plot.addLayer(valueIndicator); StandardDialScale scale1 = new StandardDialScale(); scale1.setLowerBound(lowerBound); scale1.setUpperBound(upperBound); scale1.setStartAngle(-140); // -120 scale1.setExtent(-260D); // -300D scale1.setTickRadius(0.88D); scale1.setTickLabelOffset(0.14999999999999999D); scale1.setTickLabelFont(new Font("", Font.TRUETYPE_FONT, 14)); plot.addScale(0, scale1); StandardDialRange standarddialrange0 = new StandardDialRange(lowerBound, (upperBound * 0.6), Color.red); standarddialrange0.setInnerRadius(0.52000000000000002D); standarddialrange0.setOuterRadius(0.55000000000000004D); plot.addLayer(standarddialrange0); StandardDialRange standarddialrange1 = new StandardDialRange((upperBound * 0.6), (upperBound * 0.8), Color.orange); standarddialrange1.setInnerRadius(0.52000000000000002D); standarddialrange1.setOuterRadius(0.55000000000000004D); plot.addLayer(standarddialrange1); StandardDialRange standarddialrange2 = new StandardDialRange((upperBound * 0.8), upperBound, Color.green); standarddialrange2.setInnerRadius(0.52000000000000002D); standarddialrange2.setOuterRadius(0.55000000000000004D); plot.addLayer(standarddialrange2); Pointer pointer = new Pointer(0); pointer.setFillPaint(new Color(144, 196, 246)); plot.addPointer(pointer); plot.mapDatasetToScale(0, 0); DialCap dialcap = new DialCap(); dialcap.setRadius(0.0700000000000001D); plot.setCap(dialcap); this.chart = new JFreeChart(plot); //this.chart.setBackgroundPaint(new Color(234, 244, 253)); this.chart.setBackgroundPaint(Color.white); }