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:wattsup.jsdk.ui.LineChartPanelSupport.java

@Override
public JFreeChart createChart() {
    this.timeSeries_ = new TimeSeriesCollection();
    this.dataset_ = new TranslatingXYDataset(this.timeSeries_);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(this.getTitle(), null, this.getAxisLabel(),
            this.dataset_, true, true, false);

    chart.setBackgroundPaint(getBackground());
    XYPlot xyPlot = chart.getXYPlot();// www  .j ava2 s .  com
    xyPlot.setOrientation(PlotOrientation.VERTICAL);
    xyPlot.setBackgroundPaint(Color.WHITE);
    xyPlot.setDomainGridlinePaint(Color.BLACK.darker());
    xyPlot.setRangeGridlinePaint(Color.BLACK.darker());
    xyPlot.setAxisOffset(new RectangleInsets(5.0D, 5.0D, 5.0D, 5.0D));
    xyPlot.setDomainCrosshairLockedOnData(true);
    xyPlot.setRangeCrosshairVisible(true);
    chart.setAntiAlias(true);

    return chart;
}

From source file:edu.fullerton.timeseriesapp.TimeSeriesApp.java

public ArrayList<Integer> makePlot(ArrayList<ChanDataBuffer> dbufs, boolean compact) throws WebUtilException {
    int imageId;//from w  ww  .ja v a  2  s.  c  o  m
    try {
        PluginSupport psupport = new PluginSupport();
        String gtitle = psupport.getTitle(dbufs, compact);
        String xAxisLabel = "";
        XYSeriesCollection xyds = new XYSeriesCollection();
        TimeSeriesCollection mtds = new TimeSeriesCollection();

        compact = dbufs.size() > 2 ? false : compact;
        for (ChanDataBuffer dbuf : dbufs) {
            int npts = dbuf.getDataLength();
            int sum = 1;
            if (npts > 2000) {
                sum = npts / 2000;
            }
            String legend = psupport.getLegend(dbuf, compact);
            if (timeAxis.equalsIgnoreCase("utc")) {
                TimeSeries ts = psupport.getTimeSeries(dbuf, legend, sum);
                xAxisLabel = "Time (UTC)";
                mtds.addSeries(ts);
            } else {
                boolean isDt = timeAxis.equalsIgnoreCase("dt");
                XYSeries xys = psupport.addXySeries(dbuf, legend, isDt, sum);
                xAxisLabel = psupport.getxAxisLabel();
                xyds.addSeries(xys);
            }
        }
        Double minx, miny, maxx, maxy;
        Double[] rng = new Double[4];

        if (timeAxis.equalsIgnoreCase("utc")) {
            PluginSupport.getRangeLimits(mtds, rng);
        } else {
            int skip = 0;
            PluginSupport.getRangeLimits(xyds, rng, skip);
        }
        minx = rng[0];
        miny = rng[1];
        maxx = rng[2];
        maxy = rng[3];

        int exp;
        if (timeAxis.equalsIgnoreCase("utc")) {
            exp = PluginSupport.scaleRange(mtds, miny, maxy);
        } else {
            exp = PluginSupport.scaleRange(xyds, miny, maxy);
        }

        ChartPanel cpnl;
        DefaultXYDataset ds = new DefaultXYDataset();
        JFreeChart chart;
        if (timeAxis.equalsIgnoreCase("utc")) {
            chart = ChartFactory.createTimeSeriesChart(gtitle, "Time (UTC)", "Counts", ds, true, true, false);
        } else {
            chart = ChartFactory.createXYLineChart(gtitle, xAxisLabel, "Counts", ds, PlotOrientation.VERTICAL,
                    true, false, false);
        }
        chart.setBackgroundPaint(Color.WHITE);
        chart.setAntiAlias(true);

        XYPlot plot = (XYPlot) chart.getPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);

        NumberAxis rangeAxis = new NumberAxis("Counts");
        ScaledAxisNumberFormat sanf = new ScaledAxisNumberFormat();
        sanf.setExp(exp);
        NumberTickUnit tickUnit;
        double plotRange;
        if (maxy != 0 && Math.abs(maxy - miny) < Math.abs(maxy) * 1e-30) {
            // this garbage is to get jFreeChart to always put labels on the Y axis
            double dt = Math.abs(miny) / 10;
            double scaledMin = (miny - dt) * Math.pow(10., exp);
            double scaledMax = (maxy + dt) * Math.pow(10., exp);
            rangeAxis.setRange(scaledMin, scaledMax);
            plotRange = scaledMax - scaledMin;
            rangeAxis.setAutoRange(false);
        } else {
            sanf.setMinMax(miny, maxy);
            plotRange = maxy - miny;
            rangeAxis.setAutoRange(true);
        }
        tickUnit = rangeAxis.getTickUnit();
        double tickSize = tickUnit.getSize();
        int nticks = (int) ((plotRange) / tickSize);
        if (nticks > yTicks) {
            double newTickSize = plotRange / yTicks;
            rangeAxis.setTickUnit(new NumberTickUnit(newTickSize));
        }
        rangeAxis.setNumberFormatOverride(sanf);
        rangeAxis.setAutoRangeIncludesZero(false);
        plot.setRangeAxis(rangeAxis);

        if (timeAxis.equalsIgnoreCase("utc")) {
            plot.setDataset(0, mtds);

        } else {
            plot.setDataset(0, xyds);
        }

        // Set the line thickness
        XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
        BasicStroke str = new BasicStroke(lineThickness);
        int n = plot.getSeriesCount();
        for (int i = 0; i < n; i++) {
            r.setSeriesStroke(i, str);
        }

        if (compact) {
            chart.removeLegend();
        }
        cpnl = new ChartPanel(chart);
        if (outFilename.isEmpty()) {
            imageId = psupport.saveImageAsPNG(cpnl);
        } else {
            imageId = 0;
            psupport.saveImageAsPdfFile(chart, outFilename);
        }

    } catch (SQLException | NoSuchAlgorithmException | IOException ex) {
        throw new WebUtilException(ex);
    }
    ArrayList<Integer> ret = new ArrayList<>();
    ret.add(imageId);
    return ret;
}

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

private JFreeChart generateDriverBarChart() {
    try {/*from w  w w .  j a  v a 2 s  . c o m*/
        String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT);
        String resultUnitX = _testSuite.getParam(Constants.RESULT_UNIT_X);

        // Ensure japex.resultUnitX is not null
        if (resultUnitX == null) {
            resultUnitX = "";
        }

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        DefaultCategoryDataset datasetX = new DefaultCategoryDataset();

        // Find first normalizer driver (if any) and adjust unit            
        DriverImpl normalizerDriver = null;
        for (DriverImpl driver : _testSuite.getDriverInfoList()) {
            if (driver.isNormal()) {
                normalizerDriver = driver;
                break;
            }
        }

        // Check if normalizer driver can be used as such
        if (normalizerDriver != null) {
            if (normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN) == 0.0
                    || normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN) == 0.0
                    || normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN) == 0.0) {
                System.out.println("Warning: Driver '" + normalizerDriver.getName()
                        + "' cannot be used to normalize results");
                normalizerDriver = null;
            } else {
                resultUnit = "% of " + resultUnit;
                if (resultUnitX != null) {
                    resultUnitX = "% of " + resultUnitX;
                }
            }
        }

        boolean hasValueX = false;

        // Generate charts
        for (DriverImpl di : _testSuite.getDriverInfoList()) {
            if (normalizerDriver != null) {
                dataset.addValue(
                        normalizerDriver == di ? 100.0
                                : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN)
                                        / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN)),
                        di.getName(), "Arithmetic Mean");
                dataset.addValue(
                        normalizerDriver == di ? 100.0
                                : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN)
                                        / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN)),
                        di.getName(), "Geometric Mean");
                dataset.addValue(
                        normalizerDriver == di ? 100.0
                                : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN)
                                        / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN)),
                        di.getName(), "Harmonic Mean");

                if (di.hasParam(Constants.RESULT_ARIT_MEAN_X)) {
                    datasetX.addValue(
                            normalizerDriver == di ? 100.0
                                    : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN_X)
                                            / normalizerDriver
                                                    .getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN_X)),
                            di.getName(), "Arithmetic Mean");
                    datasetX.addValue(
                            normalizerDriver == di ? 100.0
                                    : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN_X)
                                            / normalizerDriver
                                                    .getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN_X)),
                            di.getName(), "Geometric Mean");
                    datasetX.addValue(
                            (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN_X)
                                    / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN_X)),
                            di.getName(), "Harmonic Mean");
                    hasValueX = true;
                }
            } else {
                dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN), di.getName(),
                        "Arithmetic Mean");
                dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN), di.getName(),
                        "Geometric Mean");
                dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN), di.getName(),
                        "Harmonic Mean");

                if (di.hasParam(Constants.RESULT_ARIT_MEAN_X)) {
                    datasetX.addValue(di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN_X), di.getName(),
                            "Arithmetic Mean");
                    datasetX.addValue(di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN_X), di.getName(),
                            "Geometric Mean");
                    datasetX.addValue(di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN_X), di.getName(),
                            "Harmonic Mean");
                    hasValueX = true;
                }
            }

        }

        int nextPlotIndex = 1;
        CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot();

        // Use same renderer in combine charts to get same colors
        BarRenderer3D renderer = new BarRenderer3D();
        renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());

        // Bar chart for secondary data set based on japex.resultValueX
        if (hasValueX) {
            NumberAxis rangeAxisX = new NumberAxis(resultUnitX);
            CategoryPlot subplotX = new CategoryPlot(datasetX, null, rangeAxisX, renderer);

            // Set transparency and clear legend for this plot
            subplotX.setForegroundAlpha(0.7f);
            subplotX.setFixedLegendItems(new LegendItemCollection());

            plot.add(subplotX, nextPlotIndex++);
            _chartHeight += 50; // Adjust chart height
        } else {
        }

        // Bar chart for main data set based on japex.resultValue
        NumberAxis rangeAxis = new NumberAxis(resultUnit);
        CategoryPlot subplot = new CategoryPlot(dataset, null, rangeAxis, renderer);
        subplot.setForegroundAlpha(0.7f); // transparency
        plot.add(subplot, nextPlotIndex);

        // Create chart and save it as JPEG
        String chartTitle = "Result Summary";
        JFreeChart chart = new JFreeChart(hasValueX ? chartTitle : (chartTitle + "(" + resultUnit + ")"),
                new Font("SansSerif", Font.BOLD, 14), plot, true);
        chart.setAntiAlias(true);
        return chart;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

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

@Override
public void onInitialize() {
    super.onInitialize();

    final Long assignmentId = ((Model<Long>) getDefaultModel()).getObject();

    final Assignment assignment = this.businessService.getAssignment(assignmentId.longValue());

    AssignmentStatisticsPanel.this.window.setTitle(
            (new StringResourceModel("label.statistics.title", null, new Object[] { assignment.getName() })
                    .getString()));//ww  w  .  j a  v  a2 s  . com

    final List<GbStudentGradeInfo> gradeInfo = this.businessService.buildGradeMatrix(Arrays.asList(assignment));

    final List<Double> allGrades = new ArrayList<>();

    for (int i = 0; i < gradeInfo.size(); i++) {
        final GbStudentGradeInfo studentGradeInfo = gradeInfo.get(i);

        final Map<Long, GbGradeInfo> studentGrades = studentGradeInfo.getGrades();
        final GbGradeInfo grade = studentGrades.get(assignmentId);

        if (grade == null || grade.getGrade() == null) {
            // this is not the grade you are looking for
        } else {
            allGrades.add(Double.valueOf(grade.getGrade()));
        }
    }

    Collections.sort(allGrades);

    final DefaultCategoryDataset data = new DefaultCategoryDataset();

    final Map<String, Integer> counts = new TreeMap<>();
    Integer extraCredits = 0;

    // Start off with a 0-50% range
    counts.put(String.format("%d-%d", 0, 50), 0);

    final int range = 10;
    for (int start = 50; start < 100; start = start + range) {
        final String key = String.format("%d-%d", start, start + range);
        counts.put(key, 0);
    }

    for (final Double grade : allGrades) {
        if (isExtraCredit(grade, assignment)) {
            extraCredits = extraCredits + 1;
            continue;
        }

        final double percentage;
        if (GradingType.PERCENTAGE.equals(this.gradingType)) {
            percentage = grade;
        } else {
            percentage = grade / assignment.getPoints() * 100;
        }

        final int total = Double.valueOf(Math.ceil(percentage) / range).intValue();

        int start = total * range;

        if (start == 100) {
            start = start - range;
        }

        String key = String.format("%d-%d", start, start + range);

        if (start < 50) {
            key = String.format("%d-%d", 0, 50);
        }

        counts.put(key, counts.get(key) + 1);
    }

    for (final String label : counts.keySet()) {
        data.addValue(counts.get(label), "count", label);
    }
    if (extraCredits > 0) {
        data.addValue(extraCredits, "count", getString("label.statistics.chart.extracredit"));
    }

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

    chart.setBorderVisible(false);

    chart.setAntiAlias(false);

    final CategoryPlot categoryPlot = chart.getCategoryPlot();
    final BarRenderer br = (BarRenderer) categoryPlot.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()));

    categoryPlot.setRenderer(br);

    // show only integers in the count axis
    categoryPlot.getRangeAxis().setStandardTickUnits(new NumberTickUnitSource(true));
    categoryPlot.setBackgroundPaint(Color.white);

    add(new JFreeChartImageWithToolTip("chart", Model.of(chart), "tooltip", 540, 300));

    add(new Label("graded", String.valueOf(allGrades.size())));

    if (allGrades.size() > 0) {
        add(new Label("average", constructAverageLabel(allGrades, assignment)));
        add(new Label("median", constructMedianLabel(allGrades, assignment)));
        add(new Label("lowest", constructLowestLabel(allGrades, assignment)));
        add(new Label("highest", constructHighestLabel(allGrades, assignment)));
        add(new Label("deviation", constructStandardDeviationLabel(allGrades)));
    } else {
        add(new Label("average", "-"));
        add(new Label("median", "-"));
        add(new Label("lowest", "-"));
        add(new Label("highest", "-"));
        add(new Label("deviation", "-"));
    }

    add(new GbAjaxLink("done") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            AssignmentStatisticsPanel.this.window.close(target);
        }
    });
}

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

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

    // Get number of tests from first driver
    final int nOfTests = driverInfoList.get(0).getAggregateTestCases().size();

    int groupSizesIndex = 0;
    int[] groupSizes = calculateGroupSizes(nOfTests, _plotGroupSize);

    try {//  w w w  .j av a  2s . com
        String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT);
        String resultUnitX = _testSuite.getParam(Constants.RESULT_UNIT_X);

        // Ensure japex.resultUnitX is not null
        if (resultUnitX == null) {
            resultUnitX = "";
        }

        // Find first normalizer driver (if any)
        DriverImpl normalizerDriver = null;
        for (DriverImpl di : driverInfoList) {
            if (di.isNormal()) {
                normalizerDriver = di;
                break;
            }
        }

        // Check if normalizer driver can be used as such
        if (normalizerDriver != null) {
            if (normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN) == 0.0
                    || normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN) == 0.0
                    || normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN) == 0.0) {
                normalizerDriver = null;
            } else {
                resultUnit = "% of " + resultUnit;
                if (resultUnitX != null) {
                    resultUnitX = "% of " + resultUnitX;
                }
            }
        }

        // Generate charts 
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        DefaultCategoryDataset datasetX = new DefaultCategoryDataset();

        boolean hasValueX = false;

        int i = 0, thisGroupSize = 0;
        for (; i < nOfTests; i++) {

            for (DriverImpl di : driverInfoList) {
                TestCaseImpl tc = (TestCaseImpl) di.getAggregateTestCases().get(i);

                // User normalizer driver if defined
                if (normalizerDriver != null) {
                    TestCaseImpl normalTc = (TestCaseImpl) normalizerDriver.getAggregateTestCases().get(i);

                    dataset.addValue(
                            normalizerDriver == di ? 100.0
                                    : (100.0 * tc.getDoubleParamNoNaN(Constants.RESULT_VALUE)
                                            / normalTc.getDoubleParamNoNaN(Constants.RESULT_VALUE)),
                            _plotDrivers ? tc.getName() : di.getName(),
                            _plotDrivers ? di.getName() : tc.getName());

                    if (tc.hasParam(Constants.RESULT_VALUE_X)) {
                        datasetX.addValue(
                                (100.0 * tc.getDoubleParamNoNaN(Constants.RESULT_VALUE_X)
                                        / normalTc.getDoubleParamNoNaN(Constants.RESULT_VALUE_X)),
                                _plotDrivers ? tc.getName() : di.getName(),
                                _plotDrivers ? di.getName() : tc.getName());
                        hasValueX = true;
                    }
                } else {
                    dataset.addValue(tc.getDoubleParamNoNaN(Constants.RESULT_VALUE),
                            _plotDrivers ? tc.getName() : di.getName(),
                            _plotDrivers ? di.getName() : tc.getName());

                    if (tc.hasParam(Constants.RESULT_VALUE_X)) {
                        datasetX.addValue(tc.getDoubleParamNoNaN(Constants.RESULT_VALUE_X),
                                _plotDrivers ? tc.getName() : di.getName(),
                                _plotDrivers ? di.getName() : tc.getName());
                        hasValueX = true;
                    }
                }

            }

            thisGroupSize++;

            // Generate chart for this group if complete
            if (thisGroupSize == groupSizes[groupSizesIndex]) {
                int nextPlotIndex = 1;
                CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot();

                // Use same renderer in combine charts to get same colors
                BarRenderer3D renderer = new BarRenderer3D();
                renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());

                // Bar chart for secondary data set based on japex.resultValueX
                if (hasValueX) {
                    NumberAxis rangeAxisX = new NumberAxis(resultUnitX);
                    CategoryPlot subplotX = new CategoryPlot(datasetX, null, rangeAxisX, renderer);

                    // Set transparency and clear legend for this plot
                    subplotX.setForegroundAlpha(0.7f);
                    subplotX.setFixedLegendItems(new LegendItemCollection());

                    plot.add(subplotX, nextPlotIndex++);
                    _chartHeight += 50; // Adjust chart height
                }

                // Bar chart for main data set based on japex.resultValue
                NumberAxis rangeAxis = new NumberAxis(resultUnit);
                CategoryPlot subplot = new CategoryPlot(dataset, null, rangeAxis, renderer);
                subplot.setForegroundAlpha(0.7f); // transparency
                plot.add(subplot, nextPlotIndex);

                // Create chart and save it as JPEG
                String chartTitle = _plotDrivers ? "Results per Driver" : "Results per Test";
                JFreeChart chart = new JFreeChart(
                        hasValueX ? chartTitle : (chartTitle + "(" + resultUnit + ")"),
                        new Font("SansSerif", Font.BOLD, 14), plot, true);
                chart.setAntiAlias(true);
                ChartUtilities.saveChartAsJPEG(new File(baseName + Integer.toString(nOfFiles) + extension),
                        chart, _chartWidth, _chartHeight);

                nOfFiles++;
                groupSizesIndex++;
                thisGroupSize = 0;

                // Create fresh data sets
                dataset = new DefaultCategoryDataset();
                datasetX = new DefaultCategoryDataset();
            }
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return nOfFiles;
}

From source file:eu.cassandra.platform.gui.GUI.java

public JFreeChart createChart(String title, final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, "Time", "Consumption (W)", dataset,
            false, true, true);/*w  w w .j a  v a 2s . c om*/

    DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
    axis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1));
    axis.setTickMarkPosition(DateTickMarkPosition.START);
    axis.setDateFormatOverride(new SimpleDateFormat("dd"));

    //      XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    //      BasicStroke basicStroke = new BasicStroke(1f);
    //      renderer.setSeriesStroke(0, basicStroke);
    //      chart.getXYPlot().setRenderer(renderer);

    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);

    return chart;
}

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

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

    // Get number of tests from first driver
    final int nOfTests = driverInfoList.get(0).getAggregateTestCases().size();

    int groupSizesIndex = 0;
    int[] groupSizes = calculateGroupSizes(nOfTests, _plotGroupSize);

    try {/*www  .j ava 2  s . com*/
        String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT);

        // Generate charts 
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        int i = 0, thisGroupSize = 0;
        for (; i < nOfTests; i++) {

            for (DriverImpl di : driverInfoList) {
                TestCaseImpl tc = (TestCaseImpl) di.getAggregateTestCases().get(i);

                dataset.addValue(tc.getDoubleParamNoNaN(Constants.RESULT_VALUE),
                        _plotDrivers ? di.getName() : tc.getName(), _plotDrivers ? tc.getName() : di.getName());
            }

            thisGroupSize++;

            // Generate chart for this group if complete
            if (thisGroupSize == groupSizes[groupSizesIndex]) {
                JFreeChart chart = ChartFactory.createLineChart(
                        (_plotDrivers ? "Results per Driver (" : "Results per Test (") + resultUnit + ")", "",
                        resultUnit, dataset, PlotOrientation.VERTICAL, true, true, false);

                configureLineChart(chart);

                chart.setAntiAlias(true);
                ChartUtilities.saveChartAsJPEG(new File(baseName + Integer.toString(nOfFiles) + extension),
                        chart, _chartWidth, _chartHeight);

                nOfFiles++;
                groupSizesIndex++;
                thisGroupSize = 0;
                dataset = new DefaultCategoryDataset();
            }
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return nOfFiles;
}

From source file:com.epiq.bitshark.ui.FrequencyDomainPanel.java

/**
 * Initialize the graph/*from ww  w .j  av  a2 s .  co  m*/
 */
private void initGraph() {

    this.series = new BasicSeries("FFT");
    XYSeriesCollection dataset = new XYSeriesCollection(series);

    JFreeChart graph = ChartFactory.createXYLineChart(null, // title
            "", // no x-axis label
            "", // no y-axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // no legend
            false, // no tooltips
            false // no URLs
    );

    graph.setBorderVisible(false);
    graph.setPadding(new RectangleInsets(-5, 0, 0, 0));
    graph.setBackgroundPaint(null);
    graph.setBackgroundImageAlpha(0.0f);
    graph.setAntiAlias(true);

    plot = (XYPlot) graph.getPlot();

    powerAxis = new PowerAxis();
    plot.setRangeAxis(powerAxis);

    frequencyAxis = new FrequencyAxis();
    frequencyAxis.setTickLabelInsets(new RectangleInsets(10, 0, 0, 0));
    plot.setDomainAxis(frequencyAxis);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setBaseShapesFilled(true);
        renderer.setSeriesPaint(0, Common.EPIQ_GREEN);
        renderer.setSeriesStroke(0, new BasicStroke(1.0f));
    }

    plot.setBackgroundAlpha(0.0f);
    plot.setBackgroundPaint(null);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));

    // X-axis setup
    plot.getDomainAxis().setAutoRange(false);
    plot.getDomainAxis().setVisible(true);
    plot.getDomainAxis().setRange(0, FMCUartClient.BLOCK_SIZE - 1);
    plot.setDomainCrosshairVisible(false);
    plot.setDomainCrosshairPaint(new Color(46, 46, 46));

    // Y-axis setup
    plot.getRangeAxis().setAutoRange(false);
    plot.getRangeAxis().setVisible(true);
    plot.getRangeAxis().setRange(-50, 70);
    plot.setRangeCrosshairVisible(false);

    markerAnnotation.setVisible(false);
    plot.addAnnotation(markerAnnotation);
    plot.addAnnotation(markerTextAnnotation);

    this.markerTitle.setFont(new Font("Tahoma", Font.BOLD, 12));
    this.markerTitle.setFrame(new BlockBorder(new Color(46, 46, 46)));
    this.markerTitle.setBackgroundPaint(new Color(200, 200, 255, 100));
    this.markerTitle.setText("");
    this.markerTitle.setPadding(5, 15, 5, 15);
    this.markerTitle.setExpandToFitSpace(false);
    this.markerTitle.setBounds(new Rectangle2D.Double(0, 0, 100, 30));

    chartPanel = new ChartPanel(graph, false);
    chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    chartPanel.setMinimumDrawWidth(0);
    chartPanel.setMinimumDrawHeight(0);
    chartPanel.setMouseZoomable(true);
    chartPanel.setOpaque(false);

    chartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            markerLocked = !markerLocked;
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            updateMouseMarker(event);
        }

    });

    chartPanel.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
            if (!markerLocked) {
                markerAnnotation.setVisible(false);
                plot.setDomainCrosshairVisible(false);
                markerTitle.setVisible(false);
                markerTitle.setText("");
            }
        }

    });

    chartPanel.addMouseWheelListener(new MouseWheelListener() {
        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            int clicks = e.getWheelRotation();
            plot.getRangeAxis().setUpperBound(plot.getRangeAxis().getUpperBound() + clicks);
            plot.getRangeAxis().setLowerBound(plot.getRangeAxis().getLowerBound() + clicks);
        }
    });

}

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

public void generateDriverChart(String fileName) {
    try {/*from ww w. j  a  va 2 s . c o m*/
        JFreeChart chart = null;
        String chartType = _testSuite.getParam(Constants.CHART_TYPE);

        if (chartType.equalsIgnoreCase("barchart")) {
            chart = generateDriverBarChart();
        } else if (chartType.equalsIgnoreCase("scatterchart")) {
            chart = generateDriverScatterChart();
        } else if (chartType.equalsIgnoreCase("linechart")) {
            chart = generateDriverLineChart();
        } else {
            assert false;
        }

        chart.setAntiAlias(true);
        ChartUtilities.saveChartAsJPEG(new File(fileName), chart, _chartWidth, _chartHeight);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:jboost.visualization.HistogramFrame.java

private JFreeChart createRocChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYLineChart("ROC", // chart title
            "False positive rate", // x axis label
            "True positive rate", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include
            // legend
            true, // tooltips
            false // urls
    );/*w  ww  .  j a v a 2  s .com*/

    chart.setAntiAlias(false);
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    chart.setRenderingHints(hints);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    lower_tprMarker = new ValueMarker(0.5);
    lower_tprMarker.setPaint(Color.blue);
    lower_fprMarker = new ValueMarker(0.5);
    lower_fprMarker.setPaint(Color.blue);
    plot.addRangeMarker(lower_tprMarker);
    plot.addDomainMarker(lower_fprMarker);

    upper_tprMarker = new ValueMarker(0.5);
    upper_tprMarker.setPaint(Color.red);
    upper_fprMarker = new ValueMarker(0.5);
    upper_fprMarker.setPaint(Color.red);
    plot.addRangeMarker(upper_tprMarker);
    plot.addDomainMarker(upper_fprMarker);

    return chart;

}