List of usage examples for org.jfree.chart.plot XYPlot setDomainGridlinesVisible
public void setDomainGridlinesVisible(boolean visible)
From source file:gsn.charts.GsnChartJfreechart.java
public JFreeChart createChart(Collection<Data> datas) { TimeSeries t1 = new TimeSeries("S1"); Iterator<Data> iter = datas.iterator(); Data data;/*www .j a v a2 s. com*/ while (iter.hasNext()) { data = iter.next(); t1.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class, new Date((Long) data.getP2()), TimeZone.getDefault()), data.getValue()); } XYDataset dataset = new TimeSeriesCollection(t1); JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false); chart.setAntiAlias(true); chart.setTextAntiAlias(true); chart.setBackgroundPaint(Color.WHITE); // XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("No Data to Display"); plot.setDomainGridlinesVisible(true); plot.setBackgroundPaint(Color.WHITE); plot.setInsets(new RectangleInsets(5, 14, 0, 5)); // DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(ssdf); axis.setTickLabelFont(TICK_FONT); ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setTickLabelFont(TICK_FONT); // return chart; }
From source file:binky.reportrunner.ui.actions.admin.GetAuditChartAction.java
@Override @PreAuthorize("hasRole('ROLE_ADMIN')") public String execute() throws Exception { // do some stuff and get a chart going // DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); TimeSeriesCollection dataSet = new TimeSeriesCollection(); List<RunnerHistoryEvent> events = auditService.getSuccessEvents(module, new Date(fromDate), new Date(toDate)); Map<String, TimeSeries> serieses = new HashMap<String, TimeSeries>(); for (RunnerHistoryEvent e : events) { TimeSeries s = serieses.get(e.getMethod()); if (s == null) { s = new TimeSeries(e.getMethod()); serieses.put(e.getMethod(), s); }// www. j a v a2 s. co m s.addOrUpdate(new Millisecond(e.getTimeStamp()), e.getRunTime()); } for (TimeSeries s : serieses.values()) { dataSet.addSeries(s); } chart = ChartFactory.createTimeSeriesChart(module, "", "run time (ms)", dataSet, true, false, false); // .createLineChart("","","Run Time (ms)",dataSet,PlotOrientation.VERTICAL, // true,false,false); XYPlot linePlot = (XYPlot) chart.getPlot(); linePlot.setDomainGridlinesVisible(true); linePlot.setRangeGridlinesVisible(true); linePlot.setRangeGridlinePaint(Color.black); linePlot.setDomainGridlinePaint(Color.black); TextTitle subTitle = new TextTitle("Successful Executions"); subTitle.setFont(new Font("Arial", Font.ITALIC, 10)); chart.addSubtitle(subTitle); chart.getTitle().setFont(new Font("Arial", Font.BOLD, 12)); DateAxis axis = (DateAxis) linePlot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("hh:mm:ss dd-MM-yyyy")); XYItemRenderer r = linePlot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } chart.setAntiAlias(true); chart.setTextAntiAlias(true); return SUCCESS; }
From source file:networkanalyzer.DynamicPing.java
public JFreeChart createChart(final XYDataset dataset) { final JFreeChart result = ChartFactory.createTimeSeriesChart("Ping Chart", //title "Time", //x-axis "Ping", //y-axis dataset, false, false, false); final XYPlot plot = result.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); ValueAxis xaxis = plot.getDomainAxis(); xaxis.setAutoRange(true);//from www . ja v a 2 s . c o m xaxis.setFixedAutoRange(60000.0); xaxis.setVerticalTickLabels(true); ValueAxis yaxis = plot.getRangeAxis(); yaxis.setAutoRange(true); return result; }
From source file:subterranean.crimson.server.graphics.graphs.LineChart.java
private JFreeChart createChart(final XYDataset dataset) { final JFreeChart result = ChartFactory.createTimeSeriesChart("", "", "", dataset, false, false, false); XYPlot plot = result.getXYPlot(); plot.setDataset(1, new TimeSeriesCollection(s2)); plot.setBackgroundPaint(new Color(0x000000)); plot.setDomainGridlinesVisible(false); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinesVisible(false); plot.setRangeGridlinePaint(Color.lightGray); ValueAxis xaxis = plot.getDomainAxis(); xaxis.setAutoRange(true);//from w w w. ja va 2s . c om xaxis.setFixedAutoRange(160000.0); // 160 seconds xaxis.setVerticalTickLabels(false); ValueAxis yaxis = plot.getRangeAxis(); yaxis.setAutoRange(true); yaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return result; }
From source file:org.ala.spatial.web.services.GDMWSController.java
public static void generateCharts123(String outputdir) { try {/*from w ww . j av a 2 s. c om*/ IniReader ir = new IniReader(outputdir + "/gdm_params.txt"); double intercept = ir.getDoubleValue("GDMODEL", "Intercept"); // 1. read the ObservedVsPredicted.csv file System.out.println("Loading csv data"); CSVReader csv = new CSVReader(new FileReader(outputdir + "ObservedVsPredicted.csv")); List<String[]> rawdata = csv.readAll(); double[][] dataCht1 = new double[2][rawdata.size() - 1]; double[][] dataCht2 = new double[2][rawdata.size() - 1]; // for Chart 1: obs count int[] obscount = new int[11]; for (int i = 0; i < obscount.length; i++) { obscount[i] = 0; } System.out.println("populating data"); for (int i = 1; i < rawdata.size(); i++) { String[] row = rawdata.get(i); double obs = Double.parseDouble(row[4]); dataCht1[0][i - 1] = Double.parseDouble(row[6]); dataCht1[1][i - 1] = obs; dataCht2[0][i - 1] = Double.parseDouble(row[5]) - intercept; dataCht2[1][i - 1] = obs; int obc = (int) Math.round(obs * 10); obscount[obc]++; } DefaultXYDataset dataset1 = new DefaultXYDataset(); dataset1.addSeries("", dataCht1); DefaultXYDataset dataset2 = new DefaultXYDataset(); dataset2.addSeries("", dataCht2); DefaultCategoryDataset dataset3 = new DefaultCategoryDataset(); for (int i = 0; i < obscount.length; i++) { String col = "0." + i + "-0." + (i + 1); if (i == 10) { col = "0.9-1.0"; } dataset3.addValue(obscount[i] + 100, "col", col); } generateChartByType("Response Histogram", "Observed Dissimilarity Class", "Number of Site Pairs", dataset3, outputdir, "bar", "resphist"); XYDotRenderer renderer = new XYDotRenderer(); //Shape cross = ShapeUtilities.createDiagonalCross(3, 1); //renderer.setSeriesShape(0, cross); renderer.setDotWidth(3); renderer.setDotHeight(3); renderer.setSeriesPaint(0, Color.BLACK); JFreeChart jChart1 = ChartFactory.createScatterPlot( "Observed versus predicted compositional dissimilarity", "Predicted Compositional Dissimilarity", "Observed Compositional Dissimilarity", dataset1, PlotOrientation.VERTICAL, false, false, false); jChart1.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); XYPlot plot = (XYPlot) jChart1.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1)); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); plot.setRenderer(0, renderer); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setAutoRangeIncludesZero(false); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); double dMinPred = domain.getRange().getLowerBound(); double dMaxPred = domain.getRange().getUpperBound(); double dMinObs = range.getRange().getLowerBound(); double dMaxObs = range.getRange().getUpperBound(); System.out.println("1..pred.min.max: " + dMinPred + ", " + dMaxPred); int regressionLineSegs = 10; double dInc = (dMaxPred - dMinPred) / regressionLineSegs; double[][] dataReg1 = new double[2][regressionLineSegs + 1]; DefaultXYDataset dsReg1 = new DefaultXYDataset(); int i = 0; for (double d = dMinPred; d <= dMaxPred; d += dInc, i++) { dataReg1[0][i] = d; dataReg1[1][i] = d; } dsReg1.addSeries("", dataReg1); XYSplineRenderer regressionRenderer = new XYSplineRenderer(); regressionRenderer.setBaseSeriesVisibleInLegend(true); regressionRenderer.setSeriesPaint(0, Color.RED); regressionRenderer.setSeriesStroke(0, new BasicStroke(1.5f)); regressionRenderer.setBaseShapesVisible(false); plot.setDataset(1, dsReg1); plot.setRenderer(1, regressionRenderer); System.out.println("Writing image...."); ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/obspredissim.png"), jChart1, 600, 400); // For chart 3 JFreeChart jChart2 = ChartFactory.createScatterPlot( "Observed compositional dissimilarity vs predicted ecological distance", "Predicted ecological distance", "Observed Compositional Dissimilarity", dataset2, PlotOrientation.VERTICAL, false, false, false); jChart2.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); plot = (XYPlot) jChart2.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1)); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); plot.setRenderer(0, renderer); domain = (NumberAxis) plot.getDomainAxis(); domain.setAutoRangeIncludesZero(false); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); dMinPred = domain.getRange().getLowerBound(); dMaxPred = domain.getRange().getUpperBound(); dMinObs = range.getRange().getLowerBound(); dMaxObs = range.getRange().getUpperBound(); System.out.println("2.pred.min.max: " + dMinPred + ", " + dMaxPred); regressionLineSegs = 10; dInc = (dMaxPred - dMinPred) / regressionLineSegs; dataReg1 = new double[2][regressionLineSegs + 1]; dsReg1 = new DefaultXYDataset(); i = 0; for (double d = dMinPred; d <= dMaxPred; d += dInc, i++) { dataReg1[0][i] = d; dataReg1[1][i] = (1.0 - Math.exp(-d)); } dsReg1.addSeries("", dataReg1); regressionRenderer.setBaseSeriesVisibleInLegend(true); regressionRenderer.setSeriesPaint(0, Color.RED); regressionRenderer.setSeriesStroke(0, new BasicStroke(1.5f)); regressionRenderer.setBaseShapesVisible(false); plot.setDataset(1, dsReg1); plot.setRenderer(1, regressionRenderer); System.out.println("Writing image...."); ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/dissimdist.png"), jChart2, 600, 400); } catch (Exception e) { System.out.println("Unable to generate charts 2 and 3:"); e.printStackTrace(System.out); } }
From source file:eu.choreos.chart.XYChart.java
private JFreeChart createChart(XYDataset dataset, String chartTitle) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title "Execution size", // domain axis label "Range", // range axis label dataset, // initial series PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );/*from w w w .jav a 2 s . c o m*/ // set chart background chart.setBackgroundPaint(Color.white); // set a few custom plot features XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(new Color(0xffffe0)); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); // set the plot's axes to display integers TickUnitSource ticks = NumberAxis.createIntegerTickUnits(); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setStandardTickUnits(ticks); domain.resizeRange(1.1); domain.setLowerBound(0.5); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setStandardTickUnits(ticks); range.setUpperBound(range.getUpperBound() * 1.1); // render shapes and lines XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true); plot.setRenderer(renderer); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); // set the renderer's stroke Stroke stroke = new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL); renderer.setBaseOutlineStroke(stroke); // label the points NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(2); XYItemLabelGenerator generator = new StandardXYItemLabelGenerator( StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); return chart; }
From source file:slash.navigation.converter.gui.profileview.ProfileView.java
private XYPlot createPlot(JFreeChart chart) { XYPlot plot = chart.getXYPlot(); plot.setForegroundAlpha(0.65F);//from www . j a v a 2 s .c om plot.setDomainGridlinesVisible(preferences.getBoolean(X_GRID_PREFERENCE, true)); plot.setRangeGridlinesVisible(preferences.getBoolean(Y_GRID_PREFERENCE, true)); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(createIntegerTickUnits()); Font font = new JLabel().getFont(); rangeAxis.setLabelFont(font); NumberAxis valueAxis = (NumberAxis) plot.getDomainAxis(); valueAxis.setStandardTickUnits(createIntegerTickUnits()); valueAxis.setLowerMargin(0.0); valueAxis.setUpperMargin(0.0); valueAxis.setLabelFont(font); plot.getRenderer().setBaseToolTipGenerator(null); return plot; }
From source file:edu.cudenver.bios.chartsvc.resource.LegendResource.java
private XYPlot buildScatterPlot(Chart chart) throws ResourceException { // the first series is treated as the x values if (chart.getSeries() == null || chart.getSeries().size() <= 0) throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "No data series specified"); // create the jfree chart series XYSeriesCollection chartData = new XYSeriesCollection(); // use a spline renderer to make the connecting lines smooth XYSplineRenderer rend = new XYSplineRenderer(); int seriesIdx = 0; for (Series series : chart.getSeries()) { XYSeries xySeries = new XYSeries(series.getLabel()); List<Double> xList = series.getXCoordinates(); List<Double> yList = series.getYCoordinates(); if (xList != null && yList != null && xList.size() == yList.size()) { for (int i = 0; i < xList.size(); i++) { xySeries.add(xList.get(i), yList.get(i)); }/*from w ww.j a va 2s . c o m*/ } // set the line style rend.setSeriesPaint(seriesIdx, Color.BLACK); if (seriesIdx > 0) { rend.setSeriesStroke(seriesIdx, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { (float) seriesIdx, (float) 2 * seriesIdx }, 0.0f)); } // add the series to the data set chartData.addSeries(xySeries); seriesIdx++; } // turn off shapes displayed at each data point to make a smooth curve rend.setBaseShapesVisible(false); // Create the line chart NumberAxis xAxis = new NumberAxis(); xAxis.setAutoRangeIncludesZero(false); if (chart.getXAxis() != null) { Axis xAxisSpec = chart.getXAxis(); xAxis.setLabel(xAxisSpec.getLabel()); if (!Double.isNaN(xAxisSpec.getRangeMin()) && !Double.isNaN(xAxisSpec.getRangeMax())) { xAxis.setRange(xAxisSpec.getRangeMin(), xAxisSpec.getRangeMax()); } } NumberAxis yAxis = new NumberAxis(); if (chart.getYAxis() != null) { Axis yAxisSpec = chart.getYAxis(); yAxis.setLabel(chart.getYAxis().getLabel()); if (!Double.isNaN(yAxisSpec.getRangeMin()) && !Double.isNaN(yAxisSpec.getRangeMax())) { xAxis.setRange(yAxisSpec.getRangeMin(), yAxisSpec.getRangeMax()); } } XYPlot plot = new XYPlot((XYDataset) chartData, xAxis, yAxis, rend); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); return plot; }
From source file:org.sonar.server.charts.deprecated.SparkLinesChart.java
private void configurePlot() { XYPlot plot = (XYPlot) jfreechart.getPlot(); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setDataset(dataset);// www .j a v a 2s . c om plot.setDomainAxis(x); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setRangeAxis(y); plot.setRenderer(renderer); plot.setBackgroundAlpha(0.0f); }
From source file:org.n52.io.img.ChartRenderer.java
private void showGridlinesOnChart(XYPlot xyPlot) { xyPlot.setDomainGridlinesVisible(showGrid); xyPlot.setRangeGridlinesVisible(showGrid); }