Example usage for org.jfree.chart JFreeChart setAntiAlias

List of usage examples for org.jfree.chart JFreeChart setAntiAlias

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart setAntiAlias.

Prototype

public void setAntiAlias(boolean flag) 

Source Link

Document

Sets a flag that indicates whether or not anti-aliasing is used when the chart is drawn.

Usage

From source file:org.sakaiproject.gradebookng.tool.panels.SettingsGradingSchemaPanel.java

/**
 * Build the data for the chart//www .  ja va2s.c o  m
 * 
 * @return
 */
private JFreeChart getChartData() {

    // just need the list
    final List<CourseGrade> courseGrades = this.courseGradeMap.values().stream().collect(Collectors.toList());

    // get current grading schema (from model so that it reflects current state)
    final List<GbGradingSchemaEntry> gradingSchemaEntries = this.model.getObject().getGradingSchemaEntries();

    final DefaultCategoryDataset data = new DefaultCategoryDataset();
    final Map<String, Integer> counts = new LinkedHashMap<>(); // must retain order so graph can be printed correctly

    // add all schema entries (these will be sorted according to {@link LetterGradeComparator})
    gradingSchemaEntries.forEach(e -> {
        counts.put(e.getGrade(), 0);
    });

    // now add the count of each course grade for those schema entries
    this.total = 0;
    for (final CourseGrade g : courseGrades) {

        // course grade may not be released so we have to skip it
        if (StringUtils.isBlank(g.getMappedGrade())) {
            continue;
        }

        counts.put(g.getMappedGrade(), counts.get(g.getMappedGrade()) + 1);
        this.total++;
    }

    // build the data
    final ListIterator<String> iter = new ArrayList<>(counts.keySet()).listIterator(0);
    while (iter.hasNext()) {
        final String c = iter.next();
        data.addValue(counts.get(c), "count", c);
    }

    final JFreeChart chart = ChartFactory.createBarChart(null, // the chart title
            getString("settingspage.gradingschema.chart.xaxis"), // the label for the category (x) axis
            getString("label.statistics.chart.yaxis"), // the label for the value (y) axis
            data, // the dataset for the chart
            PlotOrientation.HORIZONTAL, // the plot orientation
            false, // show legend
            true, // show tooltips
            false); // show urls

    chart.getCategoryPlot().setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    chart.setBorderVisible(false);
    chart.setAntiAlias(false);

    final CategoryPlot plot = chart.getCategoryPlot();
    final BarRenderer br = (BarRenderer) plot.getRenderer();

    br.setItemMargin(0);
    br.setMinimumBarLength(0.05);
    br.setMaximumBarWidth(0.1);
    br.setSeriesPaint(0, new Color(51, 122, 183));
    br.setBarPainter(new StandardBarPainter());
    br.setShadowPaint(new Color(220, 220, 220));
    BarRenderer.setDefaultShadowsVisible(true);

    br.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(getString("label.statistics.chart.tooltip"),
            NumberFormat.getInstance()));

    plot.setRenderer(br);

    // show only integers in the count axis
    plot.getRangeAxis().setStandardTickUnits(new NumberTickUnitSource(true));

    // make x-axis wide enough so we don't get ... suffix
    plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(2.0f);

    plot.setBackgroundPaint(Color.white);

    chart.setTitle(getString("settingspage.gradingschema.chart.heading"));

    return chart;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.AbstractChartExpression.java

protected void configureChart(final JFreeChart chart) {
    // Misc Properties
    final TextTitle chartTitle = chart.getTitle();
    if (chartTitle != null) {
        final Font titleFont = Font.decode(getTitleFont());
        chartTitle.setFont(titleFont);//  w w  w .  j ava 2s .  c om
    }

    if (isAntiAlias() == false) {
        chart.setAntiAlias(false);
    }

    chart.setBorderVisible(isShowBorder());

    final Color backgroundColor = parseColorFromString(getBackgroundColor());
    if (backgroundColor != null) {
        chart.setBackgroundPaint(backgroundColor);
    }

    if (plotBackgroundColor != null) {
        chart.getPlot().setBackgroundPaint(plotBackgroundColor);
    }
    chart.getPlot().setBackgroundAlpha(plotBackgroundAlpha);
    chart.getPlot().setForegroundAlpha(plotForegroundAlpha);
    final Color borderCol = parseColorFromString(getBorderColor());
    if (borderCol != null) {
        chart.setBorderPaint(borderCol);
    }

    //remove legend if showLegend = false
    if (!isShowLegend()) {
        chart.removeLegend();
    } else { //if true format legend
        final LegendTitle chLegend = chart.getLegend();
        if (chLegend != null) {
            final RectangleEdge loc = translateEdge(legendLocation.toLowerCase());
            if (loc != null) {
                chLegend.setPosition(loc);
            }
            if (getLegendFont() != null) {
                chLegend.setItemFont(Font.decode(getLegendFont()));
            }
            if (!isDrawLegendBorder()) {
                chLegend.setBorder(BlockBorder.NONE);
            }
            if (legendBackgroundColor != null) {
                chLegend.setBackgroundPaint(legendBackgroundColor);
            }
            if (legendTextColor != null) {
                chLegend.setItemPaint(legendTextColor);
            }
        }

    }

    final Plot plot = chart.getPlot();
    plot.setNoDataMessageFont(Font.decode(getLabelFont()));

    final String message = getNoDataMessage();
    if (message != null) {
        plot.setNoDataMessage(message);
    }

    plot.setOutlineVisible(isChartSectionOutline());

    if (backgroundImage != null) {
        if (plotImageCache != null) {
            plot.setBackgroundImage(plotImageCache);
        } else {
            final ExpressionRuntime expressionRuntime = getRuntime();
            final ProcessingContext context = expressionRuntime.getProcessingContext();
            final ResourceKey contentBase = context.getContentBase();
            final ResourceManager manager = context.getResourceManager();
            try {
                final ResourceKey key = createKeyFromString(manager, contentBase, backgroundImage);
                final Resource resource = manager.create(key, null, Image.class);
                final Image image = (Image) resource.getResource();
                plot.setBackgroundImage(image);
                plotImageCache = image;
            } catch (Exception e) {
                logger.error("ABSTRACTCHARTEXPRESSION.ERROR_0007_ERROR_RETRIEVING_PLOT_IMAGE", e); //$NON-NLS-1$
                throw new IllegalStateException("Failed to process chart");
            }
        }
    }
}

From source file:com.googlecode.psiprobe.controllers.RenderChartController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    final int SERIES_NUM = 9; // the max number of series

    ///*from   www  .  j av  a  2 s . c om*/
    // get Series Color from the request
    //
    int[] seriesColor = new int[SERIES_NUM];
    seriesColor[0] = Utils.toIntHex(request.getParameter("s1c"), 0x9bd2fb);
    seriesColor[1] = Utils.toIntHex(request.getParameter("s2c"), 0xFF0606);
    for (int i = 2; i < SERIES_NUM; i++) {
        seriesColor[i] = Utils.toIntHex(request.getParameter("s" + (i + 1) + "c"), -1);
    }

    //
    // get Series Outline Color from the request
    //
    int[] seriesOutlineColor = new int[SERIES_NUM];
    seriesOutlineColor[0] = Utils.toIntHex(request.getParameter("s1o"), 0x0665aa);
    seriesOutlineColor[1] = Utils.toIntHex(request.getParameter("s2o"), 0x9d0000);
    for (int i = 2; i < SERIES_NUM; i++) {
        seriesOutlineColor[i] = Utils.toIntHex(request.getParameter("s" + (i + 1) + "o"), -1);
    }

    //
    // background color
    //
    int backgroundColor = Utils.toIntHex(request.getParameter("bc"), 0xFFFFFF);
    //
    // grid color
    //
    int gridColor = Utils.toIntHex(request.getParameter("gc"), 0);
    //
    // X axis title
    //
    String xLabel = ServletRequestUtils.getStringParameter(request, "xl", "");
    //
    // Y axis title
    //
    String yLabel = ServletRequestUtils.getStringParameter(request, "yl", "");
    //
    // image width
    //
    int width = ServletRequestUtils.getIntParameter(request, "xz", 800);
    //
    // image height
    //
    int height = ServletRequestUtils.getIntParameter(request, "yz", 400);
    //
    // show legend?
    //
    boolean showLegend = ServletRequestUtils.getBooleanParameter(request, "l", true);
    //
    // Series provider
    //
    String provider = ServletRequestUtils.getStringParameter(request, "p", null);
    //
    // Chart type
    //
    String chartType = ServletRequestUtils.getStringParameter(request, "ct", "area");

    DefaultTableXYDataset ds = new DefaultTableXYDataset();

    if (provider != null) {
        Object o = getApplicationContext().getBean(provider);
        if (o instanceof SeriesProvider) {
            ((SeriesProvider) o).populate(ds, statsCollection, request);
        } else {
            logger.error("SeriesProvider \"" + provider + "\" does not implement " + SeriesProvider.class);
        }

    }

    //
    // Build series data from the give statistic
    //

    JFreeChart chart = null;
    if ("area".equals(chartType)) {

        chart = ChartFactory.createXYAreaChart("", xLabel, yLabel, ds, PlotOrientation.VERTICAL, showLegend,
                false, false);

        ((XYAreaRenderer) chart.getXYPlot().getRenderer()).setOutline(true);

    } else if ("stacked".equals(chartType)) {

        chart = ChartFactory.createStackedXYAreaChart("", xLabel, yLabel, ds, PlotOrientation.VERTICAL,
                showLegend, false, false);

    } else if ("line".equals(chartType)) {

        chart = ChartFactory.createXYLineChart("", xLabel, yLabel, ds, PlotOrientation.VERTICAL, showLegend,
                false, false);

        final XYLine3DRenderer renderer = new XYLine3DRenderer();
        renderer.setDrawOutlines(true);
        renderer.setLinesVisible(true);
        renderer.setShapesVisible(true);
        renderer.setStroke(new BasicStroke(2));
        renderer.setXOffset(1);
        renderer.setYOffset(1);
        chart.getXYPlot().setRenderer(renderer);
    }

    if (chart != null) {
        chart.setAntiAlias(true);
        chart.setBackgroundPaint(new Color(backgroundColor));
        for (int i = 0; i < SERIES_NUM; i++) {
            if (seriesColor[i] >= 0) {
                chart.getXYPlot().getRenderer().setSeriesPaint(i, new Color(seriesColor[i]));
            }
            if (seriesOutlineColor[i] >= 0) {
                chart.getXYPlot().getRenderer().setSeriesOutlinePaint(i, new Color(seriesOutlineColor[i]));
            }
        }
        chart.getXYPlot().setDomainGridlinePaint(new Color(gridColor));
        chart.getXYPlot().setRangeGridlinePaint(new Color(gridColor));
        chart.getXYPlot().setDomainAxis(0, new DateAxis());
        chart.getXYPlot().setDomainAxis(1, new DateAxis());
        chart.getXYPlot().setInsets(new RectangleInsets(-15, 0, 0, 10));

        response.setHeader("Content-type", "image/png");
        response.getOutputStream().write(ChartUtilities.encodeAsPNG(chart.createBufferedImage(width, height)));
    }

    return null;
}

From source file:psiprobe.controllers.RenderChartController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    final int seriesMaxCount = 9; // the max number of series

    // get Series Color from the request
    int[] seriesColor = new int[seriesMaxCount];
    seriesColor[0] = Utils.toIntHex(request.getParameter("s1c"), 0x9bd2fb);
    seriesColor[1] = Utils.toIntHex(request.getParameter("s2c"), 0xFF0606);
    for (int i = 2; i < seriesMaxCount; i++) {
        seriesColor[i] = Utils.toIntHex(request.getParameter("s" + (i + 1) + "c"), -1);
    }/* w ww  .j  a v  a 2 s . co  m*/

    // get Series Outline Color from the request
    int[] seriesOutlineColor = new int[seriesMaxCount];
    seriesOutlineColor[0] = Utils.toIntHex(request.getParameter("s1o"), 0x0665aa);
    seriesOutlineColor[1] = Utils.toIntHex(request.getParameter("s2o"), 0x9d0000);
    for (int i = 2; i < seriesMaxCount; i++) {
        seriesOutlineColor[i] = Utils.toIntHex(request.getParameter("s" + (i + 1) + "o"), -1);
    }

    // background color
    int backgroundColor = Utils.toIntHex(request.getParameter("bc"), 0xFFFFFF);

    // grid color
    int gridColor = Utils.toIntHex(request.getParameter("gc"), 0);

    // X axis title
    String labelX = ServletRequestUtils.getStringParameter(request, "xl", "");

    // Y axis title
    String labelY = ServletRequestUtils.getStringParameter(request, "yl", "");

    // image width
    int width = ServletRequestUtils.getIntParameter(request, "xz", 800);

    // image height
    int height = ServletRequestUtils.getIntParameter(request, "yz", 400);

    // show legend?
    boolean showLegend = ServletRequestUtils.getBooleanParameter(request, "l", true);

    // Series provider
    String provider = ServletRequestUtils.getStringParameter(request, "p", null);

    // Chart type
    String chartType = ServletRequestUtils.getStringParameter(request, "ct", "area");

    DefaultTableXYDataset ds = new DefaultTableXYDataset();

    if (provider != null) {
        Object series = getApplicationContext().getBean(provider);
        if (series instanceof SeriesProvider) {
            ((SeriesProvider) series).populate(ds, statsCollection, request);
        } else {
            logger.error("SeriesProvider '{}' does not implement '{}'", provider, SeriesProvider.class);
        }

    }

    // Build series data from the give statistic
    JFreeChart chart = null;
    if ("area".equals(chartType)) {
        chart = ChartFactory.createXYAreaChart("", labelX, labelY, ds, PlotOrientation.VERTICAL, showLegend,
                false, false);

        ((XYAreaRenderer) chart.getXYPlot().getRenderer()).setOutline(true);

    } else if ("stacked".equals(chartType)) {
        chart = ChartFactory.createStackedXYAreaChart("", labelX, labelY, ds, PlotOrientation.VERTICAL,
                showLegend, false, false);

    } else if ("line".equals(chartType)) {
        chart = ChartFactory.createXYLineChart("", labelX, labelY, ds, PlotOrientation.VERTICAL, showLegend,
                false, false);

        final XYLine3DRenderer renderer = new XYLine3DRenderer();
        renderer.setDrawOutlines(true);
        for (int i = 0; i < seriesMaxCount; i++) {
            renderer.setSeriesLinesVisible(i, true);
            renderer.setSeriesShapesVisible(i, true);
            renderer.setSeriesStroke(i, new BasicStroke(2));
        }
        renderer.setXOffset(1);
        renderer.setYOffset(1);
        chart.getXYPlot().setRenderer(renderer);
    }

    if (chart != null) {
        chart.setAntiAlias(true);
        chart.setBackgroundPaint(new Color(backgroundColor));
        for (int i = 0; i < seriesMaxCount; i++) {
            if (seriesColor[i] >= 0) {
                chart.getXYPlot().getRenderer().setSeriesPaint(i, new Color(seriesColor[i]));
            }
            if (seriesOutlineColor[i] >= 0) {
                chart.getXYPlot().getRenderer().setSeriesOutlinePaint(i, new Color(seriesOutlineColor[i]));
            }
        }
        chart.getXYPlot().setDomainGridlinePaint(new Color(gridColor));
        chart.getXYPlot().setRangeGridlinePaint(new Color(gridColor));
        chart.getXYPlot().setDomainAxis(0, new DateAxis());
        chart.getXYPlot().setDomainAxis(1, new DateAxis());
        chart.getXYPlot().setInsets(new RectangleInsets(-15, 0, 0, 10));

        response.setHeader("Content-type", "image/png");
        response.getOutputStream().write(ChartUtilities.encodeAsPNG(chart.createBufferedImage(width, height)));
    }

    return null;
}

From source file:com.sun.japex.ChartGenerator.java

private int generateTestCaseScatterCharts(String baseName, String extension) {
    int nOfFiles = 0;
    List<DriverImpl> driverInfoList = _testSuite.getDriverInfoList();

    try {//  w  w w. j  a  v  a  2 s .c om
        // Get number of tests from first driver
        final int nOfTests = driverInfoList.get(0).getAggregateTestCases().size();

        DefaultTableXYDataset xyDataset = new DefaultTableXYDataset();

        // Generate charts
        for (DriverImpl di : driverInfoList) {
            XYSeries xySeries = new XYSeries(di.getName(), true, false);
            for (int j = 0; j < nOfTests; j++) {
                TestCaseImpl tc = (TestCaseImpl) di.getAggregateTestCases().get(j);
                try {
                    xySeries.add(tc.getDoubleParamNoNaN(Constants.RESULT_VALUE_X),
                            tc.getDoubleParamNoNaN(Constants.RESULT_VALUE));
                } catch (SeriesException e) {
                    // Ignore duplicate x-valued points
                }

            }
            xyDataset.addSeries(xySeries);
        }

        String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT);
        String resultUnitX = _testSuite.getParam(Constants.RESULT_UNIT_X);

        JFreeChart chart = ChartFactory.createScatterPlot("Results Per Test", resultUnitX, resultUnit,
                xyDataset, PlotOrientation.VERTICAL, true, true, false);

        // Set log scale depending on japex.resultAxis[_X]
        XYPlot plot = chart.getXYPlot();
        if (_testSuite.getParam(Constants.RESULT_AXIS_X).equalsIgnoreCase("logarithmic")) {
            LogarithmicAxis logAxisX = new LogarithmicAxis(resultUnitX);
            logAxisX.setAllowNegativesFlag(true);
            plot.setDomainAxis(logAxisX);
        }
        if (_testSuite.getParam(Constants.RESULT_AXIS).equalsIgnoreCase("logarithmic")) {
            LogarithmicAxis logAxis = new LogarithmicAxis(resultUnit);
            logAxis.setAllowNegativesFlag(true);
            plot.setRangeAxis(logAxis);
        }

        chart.setAntiAlias(true);
        ChartUtilities.saveChartAsJPEG(new File(baseName + Integer.toString(nOfFiles) + extension), chart,
                _chartWidth, _chartHeight);
        nOfFiles++;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return nOfFiles;
}

From source file:cs.cirg.cida.CIDAView.java

@Action
public void plotGraph() {
    lineSeriesComboBox.removeAllItems();
    int numSelectedColumns = userSelectedColumns.size();
    int numSelectedRows = userSelectedRows.size();
    if (numSelectedColumns == 0) {
        return;//from   w  w w  .j  a  v  a  2s  . c om
    }
    StandardDataTable<Numeric> data = (StandardDataTable<Numeric>) ((IOBridgeTableModel) analysisTable
            .getModel()).getDataTable();
    List<Numeric> iterations = data.getColumn(0);

    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();

    for (int i = 0; i < numSelectedColumns; i++) {
        int selectedColumnIndex = userSelectedColumns.get(i);
        List<Numeric> selectedColumn = data.getColumn(selectedColumnIndex);

        XYSeries series = new XYSeries(data.getColumnName(selectedColumnIndex));

        for (int k = 0; k < numSelectedRows; k++) {
            int selectedRowIndex = userSelectedRows.get(k);
            series.add(iterations.get(selectedRowIndex).getReal(),
                    selectedColumn.get(selectedRowIndex).getReal());
        }
        xySeriesCollection.addSeries(series);
        lineSeriesComboBox.addItem(new SeriesPair(i, (String) series.getKey()));
    }

    String chartName = experimentController.getAnalysisName();
    if (chartName.compareTo("") == 0) {
        chartName = CIDAConstants.DEFAULT_CHART_NAME;
    }
    JFreeChart chart = ChartFactory.createXYLineChart(chartName, // Title
            CIDAConstants.CHART_ITERATIONS_LABEL, // X-Axis label
            CIDAConstants.CHART_VALUE_LABEL, // Y-Axis label
            xySeriesCollection, // Dataset
            PlotOrientation.VERTICAL, true, // Show legend,
            false, //tooltips
            false //urls
    );
    chart.setAntiAlias(true);
    chart.setAntiAlias(true);
    XYPlot plot = (XYPlot) chart.getPlot();
    Paint[] paints = new Paint[7];
    paints[0] = Color.RED;
    paints[1] = Color.BLUE;
    paints[2] = new Color(0.08f, 0.5f, 0.04f);
    paints[3] = new Color(1.0f, 0.37f, 0.0f);
    paints[4] = new Color(0.38f, 0.07f, 0.42f);
    paints[5] = Color.CYAN;
    paints[6] = Color.PINK;
    plot.setDrawingSupplier(
            new DefaultDrawingSupplier(paints, paints, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.GRAY);
    plot.setRangeGridlinePaint(Color.GRAY);

    IntervalXYRenderer renderer = new IntervalXYRenderer(true, false);
    plot.setRenderer(renderer);
    lineTickIntervalInput.setText(Integer.toString(renderer.getLineTickInterval()));

    ((ChartPanel) chartPanel).setChart(chart);
}

From source file:edu.ku.brc.specify.utilapps.RegisterApp.java

/**
 * @param chartTitle//from w  w  w. j av  a 2  s.  c om
 * @param xTitle
 * @param values
 */
private void createBarChart(final String chartTitle, final String xTitle,
        final Vector<Pair<String, Integer>> values) {
    String cat = ""; //$NON-NLS-1$
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (Pair<String, Integer> p : values) {
        //System.out.println("["+p.second+"]  ["+p.first+"]");
        //System.out.println("            values.add(new Pair<String, Integer>(\""+p.first+"\", "+p.second+"));");
        dataset.addValue(p.second, p.first, cat);
    }

    // create the chart... 
    JFreeChart chart = ChartFactory.createBarChart3D(chartTitle, // chart title 
            xTitle, // domain axis label 
            "Occurrence", // range axis label 
            dataset, // data 
            PlotOrientation.VERTICAL, true, //maxStrLen > 4 || values.size() > 15,       // include legend 
            true, // tooltips? 
            false // URLs? 
    );
    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);

    // create and display a frame... 
    ChartPanel panel = new ChartPanel(chart, true, true, true, true, true);

    boolean wasVisible = false;
    boolean wasCreated = false;
    if (chartFrame == null) {
        panel.setPreferredSize(new Dimension(800, 600));
        chartFrame = new CustomFrame("Statistics", CustomFrame.OK_BTN, null);
        chartFrame.setOkLabel("Close");
        chartFrame.createUI();
        wasCreated = true;
    } else {
        wasVisible = chartFrame.isVisible();
    }

    chartFrame.setContentPane(panel);

    // Can't believe I have to do this
    Rectangle r = chartFrame.getBounds();
    r.height++;
    chartFrame.setBounds(r);
    r.height--;
    //----
    chartFrame.setBounds(r);

    if (wasCreated) {
        chartFrame.pack();
    }

    if (!wasVisible) {
        UIHelper.centerAndShow(chartFrame);
    }
}

From source file:net.sf.mzmine.chartbasics.chartthemes.EStandardChartTheme.java

@Override
public void apply(JFreeChart chart) {
    // TODO Auto-generated method stub
    super.apply(chart);
    ///*from w  w  w .j a v a  2  s  .co  m*/
    chart.getXYPlot().setDomainGridlinesVisible(showXGrid);
    chart.getXYPlot().setRangeGridlinesVisible(showYGrid);
    // all axes
    for (int i = 0; i < chart.getXYPlot().getDomainAxisCount(); i++) {
        NumberAxis a = (NumberAxis) chart.getXYPlot().getDomainAxis(i);
        a.setTickMarkPaint(axisLinePaint);
        a.setAxisLinePaint(axisLinePaint);
        // visible?
        a.setVisible(showXAxis);
    }
    for (int i = 0; i < chart.getXYPlot().getRangeAxisCount(); i++) {
        NumberAxis a = (NumberAxis) chart.getXYPlot().getRangeAxis(i);
        a.setTickMarkPaint(axisLinePaint);
        a.setAxisLinePaint(axisLinePaint);
        // visible?
        a.setVisible(showYAxis);
    }
    // apply bg
    chart.setBackgroundPaint(this.getChartBackgroundPaint());
    chart.getPlot().setBackgroundPaint(this.getPlotBackgroundPaint());

    for (int i = 0; i < chart.getSubtitleCount(); i++) {
        // visible?
        chart.getSubtitle(i).setVisible(subtitleVisible);
        //
        if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
            ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(this.getChartBackgroundPaint());
    }
    if (chart.getLegend() != null)
        chart.getLegend().setBackgroundPaint(this.getChartBackgroundPaint());

    //
    chart.setAntiAlias(isAntiAliased());
    chart.getTitle().setVisible(isShowTitle());
    chart.getPlot().setBackgroundAlpha(isNoBackground() ? 0 : 1);
}

From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java

private byte[] generateBoxAndWhiskerChart(BoxAndWhiskerCategoryDataset dataset, int width, int height) {
    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(null, null, null, dataset, false);

    // set background
    chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor()));

    // set chart border
    chart.setPadding(new RectangleInsets(10, 5, 5, 5));
    chart.setBorderVisible(true);/*from ww w. java 2s .c om*/
    chart.setBorderPaint(parseColor("#cccccc"));

    // set anti alias
    chart.setAntiAlias(true);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    BufferedImage img = chart.createBufferedImage(width, height);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        ImageIO.write(img, "png", out);
    } catch (IOException e) {
        log.warn("Error occurred while generating SiteStats chart image data", e);
    }
    return out.toByteArray();
}

From source file:ru.spbspu.viewer.DataView.java

@Deprecated
public void buildEnergyGraph2() {
    double[] data = _presenter.getFrameEnergy(getFramePosition(), getWindowWidth(), getWindowWidth());

    CategoryTableXYDataset serie = new CategoryTableXYDataset();
    serie.setNotify(false);// w ww  .ja v a  2  s .  c  o  m
    double step = 1.0 / getDiscretization();
    double startPosition = step * getFramePosition();
    for (int i = 0; i < data.length - 1; i++) {
        serie.add(startPosition, data[i], "");
        startPosition += step;
        //1.0 / getDiscretization() * getFrameWidth() / (data.length - 1);
    }
    JFreeChart chart = ChartFactory.createXYLineChart("", "", "", serie);
    chart.removeLegend();
    chart.setAntiAlias(false);
    XYPlot plot = chart.getXYPlot();
    org.jfree.chart.axis.ValueAxis yAxis = plot.getRangeAxis();

    org.jfree.chart.axis.ValueAxis xAxis = plot.getDomainAxis();
    double start = getFramePosition() * 1.0 / getDiscretization();
    double max = start + getFrameWidth() * 1.0 / getDiscretization();
    xAxis.setRange(start, max);
    ChartPanel chartPanel = new ChartPanel(chart);
    drawGraphOfEnergy(chartPanel);
}