List of usage examples for org.jfree.chart.plot XYPlot setAxisOffset
public void setAxisOffset(RectangleInsets offset)
From source file:org.ramadda.data.services.PointFormHandler.java
/** * create jfree chart/*from w ww . ja v a2 s .c o m*/ * * @param request the request * @param entry The entry * @param dataset the dataset * @param backgroundImage background image * * @return the chart */ public static JFreeChart createTimeseriesChart(Request request, Entry entry, XYDataset dataset, Image backgroundImage) { JFreeChart chart = ChartFactory.createXYLineChart("", // chart title "", // x axis label "Height", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); DateAxis timeAxis = new DateAxis("Time", request.getRepository().TIMEZONE_UTC); NumberAxis valueAxis = new NumberAxis("Data"); valueAxis.setAutoRangeIncludesZero(true); XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(Color.white); if (backgroundImage != null) { plot.setBackgroundImage(backgroundImage); plot.setBackgroundImageAlignment(org.jfree.ui.Align.TOP_LEFT); } plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setInsets(new RectangleInsets(0, 0, 0, 0)); plot.setAxisOffset(new RectangleInsets(5, 0, 5, 0)); return chart; }
From source file:de.fau.amos.ChartRenderer.java
/** * Creates Chart (JFreeChart object) using TimeSeriesCollection. Used for forecast only. * //from ww w .jav a2s. c o m * @param collection TimeSeriesCollection that provides basis for chart. * @param time Time where "real" data ends. * @param unit Unit of displayed values (kWh,TNF,kWh/TNF) * @return Returns finished JFreeChart. */ private JFreeChart createForecastChart(final TimeSeriesCollection collection, String time, String unit) { // Modification of X-Axis Label int day = Integer.parseInt(time.substring(8, 10)); int month = Integer.parseInt(time.substring(5, 7)); int year = Integer.parseInt(time.substring(0, 4)); //get Weekday Calendar c = Calendar.getInstance(); c.set(year, month - 1, day, 0, 0); int weekDay = c.get(Calendar.DAY_OF_WEEK); String dayString = new DateFormatSymbols(Locale.US).getWeekdays()[weekDay] + ", " + day + ". "; String monthString = new DateFormatSymbols(Locale.US).getMonths()[month - 1]; String xAxisLabel = "" + dayString + monthString + " " + time.substring(0, 4); //Creation of the lineChart JFreeChart lineChart = ChartFactory.createTimeSeriesChart("Forecast", // title xAxisLabel, // x-axis label // "Energy Consumption "+("1".equals(unit)?"[kWh]":("2".equals(unit)?"[kWh/TNF]":("3".equals(unit)?"[TNF]":""))), // y-axis label ("1".equals(unit) ? "Energy Consumption [kWh]" : ("2".equals(unit) ? "Energy Consumption [kWh/TNF]" : ("3".equals(unit) ? "Produced Pieces [TNF]" : ""))), collection, // data true, // create legend? false, // generate tooltips? false // generate URLs? ); //graphical modifications for LineChart lineChart.setBackgroundPaint(Color.white); XYPlot plot = lineChart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer() { private static final long serialVersionUID = 1L; // Stroke soild = new BasicStroke(2.0f); Stroke dashed = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 10.0f }, 0.0f); @Override public Stroke getItemStroke(int row, int column) { //third series in collection -> forecast collection if (row == 2) { return dashed; //partial dashed->not needed now, maybe later // double x = collection.getXValue(row, column); // // if ( x > 4){ // return dashed; // } else { // return soild; // } } else return super.getItemStroke(row, column); } }; renderer.setBaseShapesVisible(false); renderer.setBaseShapesFilled(true); renderer.setBaseStroke(new BasicStroke(3)); plot.setRenderer(renderer); return lineChart; }
From source file:de.fau.amos.ChartRenderer.java
/** * Creates Chart with Bars (JFreeChart object) from TimeSeriesCollection. Is used when granularity is set to days, months or years. * Adjusts display of the chart, not the values itself. * //from w w w .jav a2 s . co m * @param collection TimeSeriesCollection that should be used as basis of chart. * @param timeGranularity Selected granularity. Value is similar to granularity contained in TimeSeriesCollection "collection". * @param time first element of time that is displayed. Is used for caption text and axis text. * @param unit Unit of displayed values (kWh or kWh/TNF). * @return Returns finished JFreeChart object. */ private JFreeChart createTimeBarChart(TimeSeriesCollection collection, String timeGranularity, String time, String unit) { String xAxisLabel = null; // Modification of X-Axis Label (depending on the granularity) int month; String monthString = null; switch (timeGranularity) { //for Case "0" see method "createTimeLineChart" case "1": month = Integer.parseInt(time.substring(5, 7)); monthString = new DateFormatSymbols(Locale.US).getMonths()[month - 1]; xAxisLabel = "" + monthString + " " + time.substring(0, 4); break; case "2": xAxisLabel = time.substring(0, 4); break; case "3": xAxisLabel = "Years"; break; default: xAxisLabel = "Timespan"; } JFreeChart barChart = ChartFactory.createXYBarChart("Bar Chart", // title xAxisLabel, // x-axis label true, // date axis? // "Energy Consumption "+("1".equals(unit)?"[kWh]":("2".equals(unit)?"[kWh/TNF]":("3".equals(unit)?"[TNF]":""))), // y-axis label ("1".equals(unit) ? "Energy Consumption [kWh]" : ("2".equals(unit) ? "Energy Consumption [kWh/TNF]" : ("3".equals(unit) ? "Produced Pieces [TNF]" : ""))), collection, // data PlotOrientation.VERTICAL, // orientation true, // create legend? true, // generate tooltips? false // generate URLs? ); //graphical modifications for BarChart barChart.setBackgroundPaint(Color.white); XYPlot plot = barChart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); //Axis modification: Set Axis X-Value directly below the bars DateAxis dateAxis = (DateAxis) plot.getDomainAxis(); dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Axis modification: Remove Values from x-Axis that belong to former/later time element (Month/Day) dateAxis.setLowerMargin(0.01); dateAxis.setUpperMargin(0.01); //Axis modification: Axis values (depending on timeGranularity) if (timeGranularity.equals("1")) { dateAxis.setTickUnit( new DateTickUnit(DateTickUnitType.DAY, 2, new SimpleDateFormat(" dd. ", Locale.US))); } if (timeGranularity.equals("2")) { dateAxis.setTickUnit( new DateTickUnit(DateTickUnitType.MONTH, 1, new SimpleDateFormat(" MMM ", Locale.US))); } if (timeGranularity.equals("3")) { dateAxis.setTickUnit( new DateTickUnit(DateTickUnitType.YEAR, 1, new SimpleDateFormat(" yyyy ", Locale.US))); } ClusteredXYBarRenderer clusteredxybarrenderer = new ClusteredXYBarRenderer(0.25, false); clusteredxybarrenderer.setShadowVisible(false); clusteredxybarrenderer.setBarPainter(new StandardXYBarPainter()); plot.setRenderer(clusteredxybarrenderer); return barChart; }
From source file:io.github.mzmine.modules.plots.msspectrum.MsSpectrumPlotWindowController.java
public void initialize() { final JFreeChart chart = chartNode.getChart(); final XYPlot plot = chart.getXYPlot(); // Do not set colors and strokes dynamically. They are instead provided // by the dataset and configured in configureRenderer() plot.setDrawingSupplier(null);// ww w .ja v a2 s .com plot.setDomainGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor)); plot.setRangeGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor)); plot.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor)); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); // chart properties chart.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor)); // legend properties LegendTitle legend = chart.getLegend(); // legend.setItemFont(legendFont); legend.setFrame(BlockBorder.NONE); // set the X axis (m/z) properties NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setLabel("m/z"); xAxis.setUpperMargin(0.03); xAxis.setLowerMargin(0.03); xAxis.setRangeType(RangeType.POSITIVE); xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20)); // set the Y axis (intensity) properties NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setLabel("Intensity"); yAxis.setRangeType(RangeType.POSITIVE); yAxis.setAutoRangeIncludesZero(true); // set the fixed number formats, because otherwise JFreeChart sometimes // shows exponent, sometimes it doesn't DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat(); xAxis.setNumberFormatOverride(mzFormat); DecimalFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat(); yAxis.setNumberFormatOverride(intensityFormat); chartTitle = chartNode.getChart().getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); chartNode.setCursor(Cursor.CROSSHAIR); // Remove the dataset if it is removed from the list datasets.addListener((Change<? extends MsSpectrumDataSet> c) -> { while (c.next()) { if (c.wasRemoved()) { for (MsSpectrumDataSet ds : c.getRemoved()) { int index = plot.indexOf(ds); plot.setDataset(index, null); } } } }); itemLabelsVisible.addListener((prop, oldVal, newVal) -> { for (MsSpectrumDataSet dataset : datasets) { int datasetIndex = plot.indexOf(dataset); XYItemRenderer renderer = plot.getRenderer(datasetIndex); renderer.setBaseItemLabelsVisible(newVal); } }); legendVisible.addListener((prop, oldVal, newVal) -> { legend.setVisible(newVal); }); }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.GpsScatterPlotUIComponent.java
/*********************************************************************************************** * Customise the XYPlot of a new chart, e.g. for fixed range axes. * Remember that a GPS Scatter Plot has no ChannelSelector. * * @param datasettype/* w w w . ja v a 2s . co m*/ * @param primarydataset * @param secondarydatasets * @param updatetype * @param displaylimit * @param channelselector * @param debug * * @return JFreeChart */ public JFreeChart createCustomisedChart(final DatasetType datasettype, final XYDataset primarydataset, final List<XYDataset> secondarydatasets, final DataUpdateType updatetype, final int displaylimit, final ChannelSelectorUIComponentInterface channelselector, final boolean debug) { final String SOURCE = "GpsScatterPlotUIComponent.createCustomisedChart() "; final JFreeChart jFreeChart; final XYPlot plot; final Stroke strokeCrosshair; final XYDotRenderer renderer; final ValueAxis axisRange; final NumberAxis axisDomain; // See ChartHelper for other calls to ChartFactory // Note that no ChannelSector means no way to control the legend, so turn it off jFreeChart = ChartFactory.createScatterPlot(MSG_WAITING_FOR_DATA, MSG_WAITING_FOR_DATA, MSG_WAITING_FOR_DATA, primarydataset, PlotOrientation.VERTICAL, false, //channelselector.hasLegend(), true, false); jFreeChart.setBackgroundPaint(UIComponentPlugin.DEFAULT_COLOUR_CANVAS.getColor()); // Experimental chart configuration jFreeChart.getTitle().setFont(UIComponentPlugin.DEFAULT_FONT.getFont().deriveFont(20.0f)); plot = (XYPlot) jFreeChart.getPlot(); plot.setBackgroundPaint(ChartHelper.COLOR_PLOT); plot.setDomainGridlinePaint(ChartHelper.COLOR_GRIDLINES); plot.setRangeGridlinePaint(ChartHelper.COLOR_GRIDLINES); plot.setAxisOffset(ChartHelper.PLOT_RECTANGLE_INSETS); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDomainCrosshairVisible(true); plot.setDomainCrosshairLockedOnData(false); plot.setRangeCrosshairVisible(true); plot.setRangeCrosshairLockedOnData(true); // Make the Crosshair more visible by changing the width from the default strokeCrosshair = new BasicStroke(2.0f, // The width of this BasicStroke BasicStroke.CAP_BUTT, // The decoration of the ends of a BasicStroke BasicStroke.JOIN_BEVEL, // The decoration applied where path segments meet 0.0f, // The limit to trim the miter join new float[] { 2.0f, 2.0f }, // The array representing the dashing pattern 0.0f); // The offset to start the dashing pattern plot.setDomainCrosshairStroke(strokeCrosshair); plot.setRangeCrosshairStroke(strokeCrosshair); renderer = new XYDotRenderer(); renderer.setDotWidth(2); renderer.setDotHeight(2); plot.setRenderer(renderer); axisDomain = (NumberAxis) plot.getDomainAxis(); axisRange = plot.getRangeAxis(); // Remember that a GPS Scatter Plot has no ChannelSelector if (canAutorange()) { // The fix could be anywhere... axisDomain.setAutoRangeIncludesZero(false); axisDomain.setAutoRange(true); axisRange.setAutoRange(true); } else { // Allow range to full global extents! axisDomain.setRange(getLinearFixedMinY(), getLinearFixedMaxY()); axisRange.setRange(-90.0, 90.0); } return (jFreeChart); }
From source file:de.tor.tribes.ui.views.DSWorkbenchStatsFrame.java
private void setupPlotDrawing(XYPlot pPlot) { pPlot.setBackgroundPaint(Constants.DS_BACK_LIGHT); pPlot.setDomainGridlinePaint(Color.DARK_GRAY); pPlot.setRangeGridlinePaint(Color.DARK_GRAY); pPlot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); pPlot.setDomainCrosshairVisible(true); pPlot.setRangeCrosshairVisible(true); DateAxis axis = (DateAxis) pPlot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd.MM.yyyy HH:mm:ss")); }
From source file:org.jrecruiter.web.actions.admin.ShowStatisticsAction.java
public final String chartJobCount() throws Exception { final Calendar calendarToday = CalendarUtils.getCalendarWithoutTime(); final Calendar calendar30 = CalendarUtils.getCalendarWithoutTime(); calendar30.add(Calendar.MONTH, -36); final List<JobCountPerDay> jobCountPerDayList = jobService.getJobCountPerDayAndPeriod(calendar30.getTime(), calendarToday.getTime());/*from w ww .j ava 2 s .co m*/ final TimeSeries hitsPerDayData = new TimeSeries("Hits", Day.class); final XYDataset hitsPerDayDataset = new TimeSeriesCollection(hitsPerDayData); this.chart = ChartFactory.createTimeSeriesChart("", super.getText("class.ShowStatisticsAcion.chart.job.count.caption"), "", hitsPerDayDataset, false, true, false); final XYPlot xyplot = (XYPlot) this.chart.getPlot(); for (JobCountPerDay jobCountPerDay : jobCountPerDayList) { final Day day = new Day(jobCountPerDay.getJobDate()); if (jobCountPerDay.getAutomaticallyCleaned()) { final Marker originalEnd = new ValueMarker(day.getFirstMillisecond()); originalEnd.setPaint(new Color(0, 80, 138, 150)); float[] dashPattern = { 6, 2 }; originalEnd.setStroke( new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10, dashPattern, 0)); originalEnd.setLabelAnchor(RectangleAnchor.TOP_LEFT); originalEnd.setLabelTextAnchor(TextAnchor.TOP_RIGHT); originalEnd.setLabel("C"); originalEnd.setAlpha(0.1F); xyplot.addDomainMarker(originalEnd); } hitsPerDayData.add(day, jobCountPerDay.getTotalNumberOfJobs()); } chart.setBackgroundPaint(new Color(255, 255, 255, 0)); xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); xyplot.setBackgroundPaint(new Color(255, 255, 255, 0)); xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer(); if (xyitemrenderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; xylineandshaperenderer.setBaseShapesVisible(false); xyitemrenderer.setSeriesPaint(0, new Color(244, 66, 0)); } DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setAutoRange(true); dateaxis.setAutoTickUnitSelection(true); NumberAxis valueAxis = (NumberAxis) xyplot.getRangeAxis(); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return SUCCESS; }
From source file:org.tolven.web.MenuAction.java
/** * Creates a chart based on MenuData/*w ww .j a va 2 s . c o m*/ * @param dataset a dataset * @return A chart suitable for rendering */ public JFreeChart createChart(String title, XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title "Date", // x-axis label "Value", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); return chart; }
From source file:info.puzz.trackprofiler.gui.TrackProfilerFrame.java
protected void drawChart() throws TrackProfilerException { if (this.track == null) { throw new TrackProfilerException("track_not_loaded"); //$NON-NLS-1$ }//from w ww .java2 s .co m this.computeTrackInfo(); String name = trackFile != null ? trackFile.getName() : "TrackProfiler"; //$NON-NLS-1$ JFreeChart chart; if (TrackProfilerAppContext.getInstance().isFilledGraph()) { chart = ChartFactory.createXYAreaChart(name, new Message(Messages.LENGTH).toString(), new Message(Messages.ELEVATION).toString(), this.toDataset(), PlotOrientation.VERTICAL, true, true, false); } else { chart = ChartFactory.createXYLineChart(name, new Message(Messages.LENGTH).toString(), new Message(Messages.ELEVATION).toString(), this.toDataset(), PlotOrientation.VERTICAL, true, true, false); } chart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) chart.getPlot(); XYAreaRenderer xyarearenderer = new XYAreaRenderer(); xyarearenderer.setSeriesPaint(0, new Color(186, 197, 231, 200)); xyplot.setRenderer(0, xyarearenderer); drawSelectedPoints(xyplot); if (this.track.getWaypoints().size() > 0) { Waypoints markerPoints = new Waypoints(); markerPoints.addAll(this.track.getWaypoints()); for (int i = 0; i < this.track.getWaypoints().size(); i++) { Waypoint waypoint = (Waypoint) this.track.getWaypoints().get(i); prepareWaypontOnChart(xyplot, waypoint); } xyplot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); xyplot.getRangeAxis().setUpperMargin(0.15); } if (showExtreemes) { Vector/* <TrackExtreeme> */ extreemes = this.track.findExtremes(); for (int i = 0; i < extreemes.size(); i++) { Waypoint ex = (Waypoint) extreemes.get(i); prepareWaypontOnChart(xyplot, ex); } } getChartPanel().setChart(chart); getJPanel1().repaint(); }