@Override public void customize(JFreeChart chart, ReportParameters reportParameters) { BarRenderer barRenderer = (BarRenderer) chart.getCategoryPlot().getRenderer(); // barRenderer.setBaseSeriesVisible(false);//QUITA LAS BARRAS // barRenderer.setBaseSeriesVisibleInLegend(false); // barRenderer.setDrawBarOutline(false); barRenderer.setShadowVisible(false); barRenderer.setBarPainter(new CustomBarPainter()); barRenderer.setItemMargin(0); // QUITA ESPACIOS ENTRE BARRA Y BARRA CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis(); domainAxis.setUpperMargin(0); domainAxis.setLowerMargin(0); domainAxis.setCategoryMargin(0); domainAxis.setAxisLineVisible(false); // este es util Plot plot = chart.getPlot(); // plot.setOutlineVisible(false); plot.setInsets(new RectangleInsets(0, 0, 0, 0)); // este sera util CategoryPlot categoryPlot = chart.getCategoryPlot(); categoryPlot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); // FAFO6categoryPlot.setRangeGridlinePaint(Color.WHITE); categoryPlot.setDomainGridlinesVisible(false); // FAFO5categoryPlot.setRangeGridlinesVisible(false); // categoryPlot.setBackgroundPaint(Color.white); categoryPlot.setOutlineVisible(false); ValueAxis valueAsix = categoryPlot.getRangeAxis(); valueAsix.setAxisLineVisible(false); // este es muy util valueAsix.setRange(0, objDatosReporte.getIntMaxRango()); valueAsix.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // este es muy util }
/** * Sets the properties of the specified axis to match the properties defined on this panel. * * @param axis the axis. */ public void setAxisProperties(Axis axis) { super.setAxisProperties(axis); ValueAxis valueAxis = (ValueAxis) axis; valueAxis.setAutoRange(this.autoRange); if (!this.autoRange) { valueAxis.setRange(this.minimumValue, this.maximumValue); } valueAxis.setAutoTickUnitSelection(this.autoTickUnitSelection); }
public void adjustAxis(ValueAxis axis, int numDecimalPlaces) { final double lowerRange = MathUtils.round( (Double) getBindingContext().getBinding("min").getPropertyValue(), roundFactor(numDecimalPlaces)); final double upperRange = MathUtils.round( (Double) getBindingContext().getBinding("max").getPropertyValue(), roundFactor(numDecimalPlaces)); axis.setRange(lowerRange, upperRange); }
private JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart( "Dynamic Data Demo", "Time", "Value", xydataset, true, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); ValueAxis valueaxis = xyplot.getDomainAxis(); valueaxis.setAutoRange(true); valueaxis.setFixedAutoRange(60000D); valueaxis = xyplot.getRangeAxis(); valueaxis.setRange(0.0D, 200D); return jfreechart; }
private void finishScalingUpdate( AxisRangeControl axisRangeControl, ValueAxis newAxis, ValueAxis oldAxis) { if (axisRangeControl.isAutoMinMax()) { newAxis.setAutoRange(false); acceptableDeviationDataset.removeAllSeries(); regressionDataset.removeAllSeries(); getPlot().removeAnnotation(r2Annotation); newAxis.setAutoRange(true); axisRangeControl.adjustComponents(newAxis, 3); newAxis.setAutoRange(false); computeRegressionAndAcceptableDeviationData(); } else { newAxis.setAutoRange(false); newAxis.setRange(oldAxis.getRange()); } }
@Override public JFreeChart createChart(int nbr) { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); // DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); bias for (Tuple<String, double[]> tuple : this.mreDblFileList) { for (int h = 0; h < 24; h++) { dataset0.addValue(tuple.getSecond()[h], tuple.getFirst(), Integer.toString(h + 1)); } } this.chart_ = ChartFactory.createLineChart( "", "Hour", "Mean rel error [%]", dataset0, PlotOrientation.VERTICAL, true, // legend? true, // tooltips? false // URLs? ); CategoryPlot plot = this.chart_.getCategoryPlot(); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); final LineAndShapeRenderer renderer = new LineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, Color.GREEN); renderer.setSeriesPaint(2, Color.BLUE); renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); plot.setRenderer(0, renderer); Color transparent = new Color(0, 0, 255, 0); this.chart_.setBackgroundPaint( transparent); // pink : Color.getHSBColor((float) 0.0, (float) 0.0, (float) 0.93) plot.setBackgroundPaint(Color.getHSBColor((float) 0.0, (float) 0.0, (float) 0.93)); plot.setRangeGridlinePaint(Color.gray); plot.setRangeGridlinesVisible(true); final CategoryAxis axisX = new CategoryAxis("Hour"); axisX.setTickLabelFont(new Font("SansSerif", Font.BOLD, 15)); plot.setDomainAxis(axisX); // final ValueAxis axis2 = new NumberAxis("Mean abs bias [agent/h]"); // plot.setRangeAxis(1, axis2); final ValueAxis axisY = plot.getRangeAxis(0); axisY.setRange(0.0, 100.0); axisY.setTickLabelFont(new Font("SansSerif", Font.BOLD, 21)); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); renderer2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator()); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); this.chart_.getLegend().setItemFont(new Font("SansSerif", Font.BOLD, 17)); this.chart_.getLegend().setVisible(false); return this.chart_; }
public String generateBarChart( String hitSection, HttpSession session, PrintWriter pw, String courseId, int studentId) { /* int groupId=0; if (groupName.equals("All")){ groupId=0; }else{ groupId = studStatisticBean.getGroupIdByName(groupName); }*/ String filename = null; try { // Retrieve list of WebHits StudentsConceptChartDataSet cDataSet = new StudentsConceptChartDataSet(studStatisticBean, courseId, studentId); ArrayList list = cDataSet.getDataBySection(hitSection); // Throw a custom NoDataException if there is no data if (list.size() == 0) { System.out.println("No data has been found"); throw new NoDataException(); } // Create and populate a CategoryDataset Iterator iter = list.listIterator(); DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); while (iter.hasNext()) { StudentsConceptHit wh = (StudentsConceptHit) iter.next(); // Comparable c1= Double.parseDouble(wh.getHitDegree()); dataSet.addValue( wh.getHitDegree(), "degree of mastery for concept ", String.valueOf(wh.getHitConcept())); } // Create the chart object CategoryAxis categoryAxis = new CategoryAxis("Concepts"); ValueAxis valueAxis = new NumberAxis("Degree of Mastery"); valueAxis.setRange(0.0, 6.0); categoryAxis.setCategoryLabelPositions( new CategoryLabelPositions().createUpRotationLabelPositions(45)); BarRenderer renderer = new BarRenderer(); renderer.setDrawBarOutline(true); renderer.setItemURLGenerator( new StandardCategoryURLGenerator("xy_chart.jsp", "series", "section")); StandardCategoryToolTipGenerator scttg = new StandardCategoryToolTipGenerator(); renderer.setToolTipGenerator(scttg); Plot plot = new CategoryPlot(dataSet, categoryAxis, valueAxis, renderer); JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(java.awt.Color.white); // Write the chart image to the temporary directory ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); filename = ServletUtilities.saveChartAsPNG(chart, 600, 400, info, session); // Write the image map to the PrintWriter ChartUtilities.writeImageMap(pw, filename, info); pw.flush(); } catch (NoDataException e) { System.out.println(e.toString()); filename = "public_nodata_500x300.png"; } catch (Exception e) { System.out.println("Exception - " + e.toString()); e.printStackTrace(System.out); filename = "public_error_500x300.png"; } return filename; }
private JFreeChart createChart() { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart( null, // chart title null, // x axis label null, // y axis label null, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customization... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) { if ((dataTable.isDate(indexAxis)) || (dataTable.isDateTime(indexAxis))) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(indexAxis)); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); chart.getXYPlot().setDomainAxis(domainAxis); } } else { plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US)); ((NumberAxis) plot.getDomainAxis()).setAutoRangeStickyZero(false); ((NumberAxis) plot.getDomainAxis()).setAutoRangeIncludesZero(false); } ValueAxis xAxis = plot.getDomainAxis(); if (indexAxis > -1) xAxis.setLabel(getDataTable().getColumnName(indexAxis)); else xAxis.setLabel(SERIESINDEX_LABEL); xAxis.setAutoRange(true); xAxis.setLabelFont(LABEL_FONT_BOLD); xAxis.setTickLabelFont(LABEL_FONT); xAxis.setVerticalTickLabels(isLabelRotating()); if (indexAxis > 0) { if (getRangeForDimension(indexAxis) != null) { xAxis.setRange(getRangeForDimension(indexAxis)); } } else { if (getRangeForName(SERIESINDEX_LABEL) != null) { xAxis.setRange(getRangeForName(SERIESINDEX_LABEL)); } } // renderer and range axis synchronized (dataTable) { int numberOfSelectedColumns = 0; for (int c = 0; c < dataTable.getNumberOfColumns(); c++) { if (getPlotColumn(c)) { if (dataTable.isNumerical(c)) { numberOfSelectedColumns++; } } } int columnCount = 0; for (int c = 0; c < dataTable.getNumberOfColumns(); c++) { if (getPlotColumn(c)) { if (dataTable.isNumerical(c)) { // YIntervalSeries series = new YIntervalSeries(this.dataTable.getColumnName(c)); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries(dataTable.getColumnName(c)); Iterator<DataTableRow> i = dataTable.iterator(); int index = 1; while (i.hasNext()) { DataTableRow row = i.next(); double value = row.getValue(c); if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) { double indexValue = row.getValue(indexAxis); series.add(indexValue, value); } else { series.add(index++, value); } } dataset.addSeries(series); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Color color = getColorProvider().getPointColor(1.0d); if (numberOfSelectedColumns > 1) { color = getColorProvider() .getPointColor(columnCount / (double) (numberOfSelectedColumns - 1)); } renderer.setSeriesPaint(0, color); renderer.setSeriesStroke( 0, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); renderer.setSeriesShapesVisible(0, false); NumberAxis yAxis = new NumberAxis(dataTable.getColumnName(c)); if (getRangeForDimension(c) != null) { yAxis.setRange(getRangeForDimension(c)); } else { yAxis.setAutoRange(true); yAxis.setAutoRangeStickyZero(false); yAxis.setAutoRangeIncludesZero(false); } yAxis.setLabelFont(LABEL_FONT_BOLD); yAxis.setTickLabelFont(LABEL_FONT); if (numberOfSelectedColumns > 1) { yAxis.setAxisLinePaint(color); yAxis.setTickMarkPaint(color); yAxis.setLabelPaint(color); yAxis.setTickLabelPaint(color); } plot.setRangeAxis(columnCount, yAxis); plot.setRangeAxisLocation(columnCount, AxisLocation.TOP_OR_LEFT); plot.setDataset(columnCount, dataset); plot.setRenderer(columnCount, renderer); plot.mapDatasetToRangeAxis(columnCount, columnCount); columnCount++; } } } } chart.setBackgroundPaint(Color.white); return chart; }