List of usage examples for org.jfree.chart.axis NumberAxis setInverted
public void setInverted(boolean flag)
From source file:org.optaplanner.examples.cheaptime.swingui.CheapTimePanel.java
private XYPlot createTaskAssignmentPlot(TangoColorFactory tangoColorFactory, CheapTimeSolution solution) { OHLCSeriesCollection seriesCollection = new OHLCSeriesCollection(); Map<Machine, OHLCSeries> machineSeriesMap = new LinkedHashMap<Machine, OHLCSeries>( solution.getMachineList().size()); HighLowRenderer renderer = new HighLowRenderer(); renderer.setTickLength(0.0);// ww w .ja va2s . c o m int seriesIndex = 0; OHLCSeries unassignedProjectSeries = new OHLCSeries("Unassigned"); seriesCollection.addSeries(unassignedProjectSeries); machineSeriesMap.put(null, unassignedProjectSeries); renderer.setSeriesStroke(seriesIndex, new BasicStroke(3.0f)); renderer.setSeriesPaint(seriesIndex, TangoColorFactory.SCARLET_1); seriesIndex++; for (Machine machine : solution.getMachineList()) { OHLCSeries machineSeries = new OHLCSeries(machine.getLabel()); seriesCollection.addSeries(machineSeries); machineSeriesMap.put(machine, machineSeries); renderer.setSeriesStroke(seriesIndex, new BasicStroke(3.0f)); renderer.setSeriesPaint(seriesIndex, tangoColorFactory.pickColor(machine)); seriesIndex++; } List<TaskAssignment> taskAssignmentList = new ArrayList<TaskAssignment>(solution.getTaskAssignmentList()); Collections.sort(taskAssignmentList, groupByMachineCheckBox.isSelected() ? groupByMachineTaskAssignmentComparator : stableTaskAssignmentComparator); int pixelIndex = 0; for (TaskAssignment taskAssignment : taskAssignmentList) { Task task = taskAssignment.getTask(); Integer startPeriod = taskAssignment.getStartPeriod(); Integer endPeriod = taskAssignment.getEndPeriod(); if (startPeriod == null) { startPeriod = task.getStartPeriodRangeFrom(); endPeriod = startPeriod + task.getDuration(); } OHLCSeries machineSeries = machineSeriesMap.get(taskAssignment.getMachine()); machineSeries.add(new FixedMillisecond(pixelIndex), task.getStartPeriodRangeFrom(), startPeriod, endPeriod, task.getStartPeriodRangeTo() + task.getDuration()); pixelIndex++; } NumberAxis domainAxis = new NumberAxis("Task"); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); domainAxis.setRange(-0.5, taskAssignmentList.size() - 0.5); domainAxis.setInverted(true); return new XYPlot(seriesCollection, domainAxis, null, renderer); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.BlockChart.java
/** * Creates a chart for the specified dataset. * //from www . java 2s. c o m * @param dataset the dataset. * * @return A chart instance. */ public JFreeChart createChart(DatasetMap datasets) { XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1"); //Creates the xAxis with its label and style NumberAxis xAxis = new NumberAxis(xLabel); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); xAxis.setLabel(xLabel); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { xAxis.setLabelFont(addLabelsStyle.getFont()); xAxis.setLabelPaint(addLabelsStyle.getColor()); } //Creates the yAxis with its label and style NumberAxis yAxis = new NumberAxis(yLabel); yAxis.setAutoRangeIncludesZero(false); yAxis.setInverted(false); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); yAxis.setTickLabelsVisible(true); yAxis.setLabel(yLabel); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { yAxis.setLabelFont(addLabelsStyle.getFont()); yAxis.setLabelPaint(addLabelsStyle.getColor()); } yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); Color outboundCol = new Color(Integer.decode(outboundColor).intValue()); //Sets the graph paint scale and the legend paintscale LookupPaintScale paintScale = new LookupPaintScale(zvalues[0], (new Double(zrangeMax)).doubleValue(), outboundCol); LookupPaintScale legendPaintScale = new LookupPaintScale(0.5, 0.5 + zvalues.length, outboundCol); for (int ke = 0; ke <= (zvalues.length - 1); ke++) { Double key = (new Double(zvalues[ke])); Color temp = (Color) colorRangeMap.get(key); paintScale.add(zvalues[ke], temp); legendPaintScale.add(0.5 + ke, temp); } //Configures the renderer XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setPaintScale(paintScale); double blockHeight = (new Double(blockH)).doubleValue(); double blockWidth = (new Double(blockW)).doubleValue(); renderer.setBlockWidth(blockWidth); renderer.setBlockHeight(blockHeight); //configures the plot with title, subtitle, axis ecc. XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); plot.setDomainCrosshairPaint(Color.black); plot.setForegroundAlpha(0.66f); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); JFreeChart 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(); chart.setBackgroundPaint(Color.white); //Sets legend labels SymbolAxis scaleAxis = new SymbolAxis(null, legendLabels); scaleAxis.setRange(0.5, 0.5 + zvalues.length); scaleAxis.setPlot(new PiePlot()); scaleAxis.setGridBandsVisible(false); scaleAxis.setLabel(zLabel); //scaleAxis.setLabelAngle(3.14/2); scaleAxis.setLabelFont(addLabelsStyle.getFont()); scaleAxis.setLabelPaint(addLabelsStyle.getColor()); //draws legend as chart subtitle PaintScaleLegend psl = new PaintScaleLegend(legendPaintScale, scaleAxis); psl.setAxisOffset(2.0); psl.setPosition(RectangleEdge.RIGHT); psl.setMargin(new RectangleInsets(5, 1, 5, 1)); chart.addSubtitle(psl); if (yLabels != null) { //Sets y legend labels LookupPaintScale legendPaintScale2 = new LookupPaintScale(0, (yLabels.length - 1), Color.white); for (int ke = 0; ke < yLabels.length; ke++) { Color temp = Color.white; legendPaintScale2.add(1 + ke, temp); } SymbolAxis scaleAxis2 = new SymbolAxis(null, yLabels); scaleAxis2.setRange(0, (yLabels.length - 1)); scaleAxis2.setPlot(new PiePlot()); scaleAxis2.setGridBandsVisible(false); //draws legend as chart subtitle PaintScaleLegend psl2 = new PaintScaleLegend(legendPaintScale2, scaleAxis2); psl2.setAxisOffset(5.0); psl2.setPosition(RectangleEdge.LEFT); psl2.setMargin(new RectangleInsets(8, 1, 40, 1)); psl2.setStripWidth(0); psl2.setStripOutlineVisible(false); chart.addSubtitle(psl2); } return chart; }
From source file:net.sourceforge.processdash.ev.ui.ScheduleBalancingDialog.java
private void addChartToPanel(JPanel panel, int gridY) { // create a dataset for displaying schedule data chartData = new ChartData(); updateChart();/*from w w w . j av a2s . c o m*/ // customize a renderer for displaying schedules XYBarRenderer renderer = new XYBarRenderer(); renderer.setUseYInterval(true); renderer.setBaseToolTipGenerator(chartData); renderer.setDrawBarOutline(true); // use an inverted, unadorned numeric Y-axis NumberAxis yAxis = new NumberAxis(); yAxis.setInverted(true); yAxis.setTickLabelsVisible(false); yAxis.setTickMarksVisible(false); yAxis.setUpperMargin(0); // use a Date-based X-axis DateAxis xAxis = new DateAxis(); // create an XY plot to display the data XYPlot plot = new XYPlot(chartData, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(false); plot.setNoDataMessage(TaskScheduleDialog.resources.getString("Chart.No_Data_Message")); // create a chart and a chart panel JFreeChart chart = new JFreeChart(plot); chart.removeLegend(); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setInitialDelay(50); chartPanel.setDismissDelay(60000); chartPanel.setMinimumDrawHeight(40); chartPanel.setMinimumDrawWidth(40); chartPanel.setMaximumDrawHeight(3000); chartPanel.setMaximumDrawWidth(3000); chartPanel.setPreferredSize(new Dimension(300, gridY * 25)); // add the chart to the dialog content pane GridBagConstraints c = new GridBagConstraints(); c.gridy = gridY; c.gridwidth = 4; c.weightx = 2; c.weighty = 1; c.fill = GridBagConstraints.BOTH; c.insets = new Insets(10, 0, 0, 0); panel.add(chartPanel, c); // retrieve the colors used for each chart bar, and register those // colors with the schedule rows so they can act as a legend for (int i = scheduleRows.size(); i-- > 0;) { ScheduleTableRow oneRow = scheduleRows.get(i); oneRow.addColoredIcon(renderer.lookupSeriesPaint(i)); } }
From source file:diet.gridr.g5k.gui.GanttChart.java
/** * Method creating the chart//from w w w .ja va2 s . c o m * * @param dataset dataset containing the data for the chart * @return a chart */ private JFreeChart createChart(XYZDataset dataset) { DateAxis xAxis = new DateAxis("Date"); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); xAxis.setDateFormatOverride(new SimpleDateFormat(durationsFormatterArray[this.visualizationDuration])); xAxis.setRange(Calendar.getInstance().getTime(), new Date(System.currentTimeMillis() + HistoryUtil.durationsTimesArray[visualizationDuration] - HistoryUtil.blockWidthsArray[visualizationDuration])); NumberAxis yAxis = new NumberAxis("Nodes"); yAxis.setAutoRangeIncludesZero(false); yAxis.setInverted(true); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); yAxis.setRange(1, numberOfNodes); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYBlockRenderer renderer = new XYBlockRenderer(); LookupPaintScale paintScale = new LookupPaintScale(); for (int i = 0; i < jobsList.get(visualizationDuration).size(); i++) { // String jobId = jobsList.get(visualizationDuration).get(i).getId().substring(0,jobsList.get(visualizationDuration).get(i).getId().indexOf(".")); String jobId = jobsList.get(visualizationDuration).get(i).getParameterValue(GridJob.KEY_GRID_JOB_ID); int seed = Integer.parseInt(jobId); Random rng = new Random(seed); Color tempColor = Color.red; int red = tempColor.getRed(); int green = tempColor.getGreen(); int blue = tempColor.getBlue(); int redRNG = rng.nextInt(255); int greenRNG = rng.nextInt(255); int blueRNG = rng.nextInt(255); if (red == redRNG && green == greenRNG && blue == blueRNG) { tempColor = new Color(rng.nextInt(255), rng.nextInt(255), rng.nextInt(255)); } else { tempColor = new Color(redRNG, greenRNG, blueRNG); } if (seed == 0) tempColor = Color.red; paintScale.add(new Double(i), tempColor); } renderer.setBlockWidth(HistoryUtil.blockWidthsArray[visualizationDuration]); renderer.setBlockAnchor(RectangleAnchor.TOP_LEFT); renderer.setPaintScale(paintScale); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); JFreeChart chart = new JFreeChart("Gantt Chart activity for cluster " + siteName, plot); chart.removeLegend(); chart.setBackgroundPaint(Color.white); LoggingManager.log(Level.CONFIG, LoggingManager.RESOURCESTOOL, this.getClass().getName(), "createChart", "Chart created"); return chart; }
From source file:projects.wdlf47tuc.ProcessAllSwathcal.java
/** * Plots the CMD using the existing dataset. Used whenever chart annotations change, without the * underlying plot data changing. This method identifies all sources lying within the boxed region * and loads them into the secondary list {@link #boxedSources}. * //from w w w . ja v a 2s . co m * @param allSources * The {@link Source}s to plot * @return * A JFreeChart presenting the colour-magnitude diagram for the current selection criteria and colours. */ private JFreeChart plotCmd() { XYSeries outside = new XYSeries("Outside"); XYSeries inside = new XYSeries("Inside"); // Use a Path2D.Double instance to determine polygon intersection Path2D.Double path = new Path2D.Double(); boxedSources.clear(); boolean performBoxSelection = (points.size() > 2); if (performBoxSelection) { // Initialise Path2D object path.moveTo(points.get(0)[0], points.get(0)[1]); for (double[] point : points) { path.lineTo(point[0], point[1]); } } for (Source source : selectedSources) { double magnitude = source.getMag(magFilter); double col1 = source.getMag(col1Filter); double col2 = source.getMag(col2Filter); double x = col1 - col2; double y = magnitude; if (performBoxSelection) { Point2D.Double point = new Point2D.Double(x, y); if (path.contains(point)) { inside.add(x, y); boxedSources.add(source); } else { outside.add(x, y); } } else { outside.add(x, y); } } final XYSeriesCollection data = new XYSeriesCollection(); data.addSeries(outside); data.addSeries(inside); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShape(0, new Ellipse2D.Float(-0.5f, -0.5f, 1, 1)); renderer.setSeriesPaint(0, ChartColor.BLACK); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesShape(1, new Ellipse2D.Float(-0.5f, -0.5f, 1, 1)); renderer.setSeriesPaint(1, ChartColor.RED); NumberAxis xAxis = new NumberAxis(col1Filter.toString() + " - " + col2Filter.toString()); xAxis.setRange(getXRange()); NumberAxis yAxis = new NumberAxis(magFilter.toString()); yAxis.setRange(getYRange()); yAxis.setInverted(true); // Configure plot XYPlot xyplot = new XYPlot(data, xAxis, yAxis, renderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.white); // Specify selection box, if points have been specified if (!points.isEmpty()) { double[] coords = new double[points.size() * 2]; for (int i = 0; i < points.size(); i++) { double[] point = points.get(i); coords[2 * i + 0] = point[0]; coords[2 * i + 1] = point[1]; } XYPolygonAnnotation box = new XYPolygonAnnotation(coords, new BasicStroke(2.0f), Color.BLUE); xyplot.addAnnotation(box); } // Configure chart JFreeChart chart = new JFreeChart("47 Tuc CMD", xyplot); chart.setBackgroundPaint(Color.white); chart.setTitle("47 Tuc colour-magnitude diagram"); chart.removeLegend(); return chart; }
From source file:org.operamasks.faces.render.graph.ChartRenderer.java
private void setNumberAxisStyles(NumberAxis axis, UIAxis comp) { axis.setInverted(comp.isInverted()); Object lowerBound = comp.getLowerBound(); Object upperBound = comp.getUpperBound(); Double lowerMargin = comp.getLowerMargin(); Double upperMargin = comp.getUpperMargin(); if (lowerBound != null) axis.setLowerBound(Coercion.coerceToDouble(lowerBound)); if (upperBound != null) axis.setUpperBound(Coercion.coerceToDouble(upperBound)); if (lowerMargin != null) axis.setLowerMargin(lowerMargin); if (upperMargin != null) axis.setUpperMargin(upperMargin); Double tickStep = comp.getTickStep(); String tickFormat = comp.getTickLabelFormat(); if ((tickStep != null && tickStep > 0) || tickFormat != null) { if (tickFormat == null) { axis.setTickUnit(new NumberTickUnit(tickStep)); } else if (tickStep == null) { NumberFormat format = new DecimalFormat(tickFormat); axis.setNumberFormatOverride(format); } else {/*from w w w. j a v a2s . c om*/ NumberFormat format = new DecimalFormat(tickFormat); axis.setTickUnit(new NumberTickUnit(tickStep, format)); } } }
From source file:ucar.unidata.idv.control.chart.VerticalProfileChart.java
/** * Add a series to the charts// w w w.j av a2 s . com * * * @param series series * @param lineState line state * @param paramIdx param index * @param renderer renderer * @param rangeVisible range visible * * @return the Axis */ protected Axis addSeries(XYSeries series, LineState lineState, int paramIdx, XYItemRenderer renderer, boolean rangeVisible) { if (lineState.getRange() != null) { addRange(lineState.getRange().getMin(), lineState.getRange().getMax(), "Fixed range from: " + lineState.getName()); } if (numberFormat == null) { numberFormat = new DecimalFormat() { public StringBuffer format(double number, StringBuffer result, FieldPosition fieldPosition) { String s = control.getDisplayConventions().format(number); result.append(s); return result; } }; } String name = lineState.getName(); Unit unit = lineState.unit; XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); NumberAxis rangeAxis; NumberAxis domainAxis = null; String axisLabel = name + ((unit != null) ? " [" + unit + "]" : ""); if (lineState.getUseLogarithmicRange() && false) { rangeAxis = new FixedWidthLogarithmicAxis(axisLabel); } else { //rangeAxis = new FixedWidthNumberAxis(axisLabel); rangeAxis = new NumberAxis(axisLabel); ((NumberAxis) rangeAxis).setAutoRangeIncludesZero(lineState.getRangeIncludesZero()); VerticalProfileInfo vpInfo = (VerticalProfileInfo) profiles.get(0); Unit altUnit = vpInfo.getAltitudeUnit(); if (altUnit != null && paramIdx == 0 && !(altUnit.equals(CommonUnit.meter))) { String dlabel = "Altitude " + "[" + altUnit + "]"; domainAxis = new NumberAxis(dlabel); if (altUnit.isConvertible(CommonUnits.HECTOPASCAL)) domainAxis.setInverted(true); } } //For now lets use the default number formatting for the range // rangeAxis.setNumberFormatOverride(numberFormat); rangeAxis.setVisible(rangeVisible); ucar.unidata.util.Range r = lineState.getRange(); if (r != null) { rangeAxis.setRange(new org.jfree.data.Range(r.getMin(), r.getMax())); } if (renderer == null) { renderer = getRenderer(lineState); } Paint c = lineState.getColor(paramIdx); rangeAxis.setLabelPaint(Color.black); renderer.setSeriesPaint(0, c); renderer.setSeriesStroke(0, lineState.getStroke()); if (!lineState.getAxisVisible()) { rangeAxis.setVisible(false); } AxisLocation side = null; ChartHolder chartHolder = getChartHolder(lineState); if (rangeAxis.isVisible()) { if (lineState.getSide() == LineState.SIDE_UNDEFINED) { side = AxisLocation.BOTTOM_OR_RIGHT; } else if (lineState.getSide() == LineState.SIDE_LEFT) { side = AxisLocation.TOP_OR_LEFT; } else { side = AxisLocation.BOTTOM_OR_RIGHT; } chartHolder.lastSide = side; } synchronized (MUTEX) { if (domainAxis == null) { if (isConservedSounding) chartHolder.add(dataset, renderer, side); else chartHolder.add(dataset, rangeAxis, renderer, side); } else chartHolder.add(dataset, rangeAxis, domainAxis, renderer, side); } return rangeAxis; }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Create a horizontal bar chart.// w w w .j a va 2 s.c o m * * @return a horizontal bar chart. */ public JFreeChart createHorizontalBarChart() { // create a default chart based on some sample data... final String title = this.resources.getString("bar.horizontal.title"); final String domain = this.resources.getString("bar.horizontal.domain"); final String range = this.resources.getString("bar.horizontal.range"); final CategoryDataset data = DemoDatasetFactory.createCategoryDataset(); final JFreeChart chart = ChartFactory.createBarChart(title, domain, range, data, PlotOrientation.HORIZONTAL, true, true, false); // then customise it a little... // chart.getLegend().setAnchor(Legend.EAST); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.orange)); final CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeCrosshairVisible(false); final NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); axis.setInverted(true); return chart; }
From source file:com.peterbochs.instrument.InstrumentPanel.java
private static JFreeChart createEmptyChart(XYZDataset dataset) { NumberAxis xAxis = new NumberAxis("address"); xAxis.setLowerMargin(0.0);/*from w ww .j av a 2 s. com*/ xAxis.setUpperMargin(0.0); NumberAxis yAxis = new NumberAxis("address"); yAxis.setAutoRangeIncludesZero(false); yAxis.setInverted(false); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); // yAxis.setAxisLinePaint(Color.pink); // yAxis.setTickMarkPaint(Color.white); yAxis.setTickLabelFont(new Font("Dialog", 0, 7)); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); MyXYBlockRenderer renderer = new MyXYBlockRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); // plot.setBackgroundPaint(Color.white); // plot.setDomainGridlineStroke(new BasicStroke(1)); plot.setDomainGridlinePaint(Color.white); // plot.setRangeGridlineStroke(new BasicStroke(1)); plot.setRangeGridlinePaint(Color.white); JFreeChart chart = new JFreeChart("Memory read/write hot zone", new Font("Serif", Font.PLAIN, 12), plot, true); chart.removeLegend(); chart.setBackgroundPaint(Color.white); return chart; }