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:systeminformation.Chart.java

public JFreeChart create3DPieChart(PieDataset dataset) {
    JFreeChart chart = ChartFactory.createPieChart3D("", dataset, true, true, true);
    PiePlot3D p = (PiePlot3D) chart.getPlot();

    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0%"));
    p.setLabelGenerator(gen);//from w  w  w .  ja  va 2  s.  c  o m
    //        p.setSimpleLabels(true);
    p.setForegroundAlpha(0.5f);
    p.setBackgroundAlpha(0.2f);
    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);
    chart.setBorderVisible(true);

    return chart;
}

From source file:edu.cuny.cat.ui.SpecialistView.java

private void setupShoutPlots() {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("", "Time", "Price", dataset, true, true,
            false);/*from w  ww.jav  a  2 s. c o m*/
    chart.setAntiAlias(true);
    chart.setBackgroundPaint(getContentPane().getBackground());
    xyplot = (XYPlot) chart.getPlot();
    xyplot.setNoDataMessage("NO DATA");
    xyplot.setRenderer(new XYLineAndShapeRenderer());
    final NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setTickMarkInsideLength(2.0F);
    numberaxis1.setTickMarkOutsideLength(0.0F);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDomainZoomable(true);
    chartPanel.setRangeZoomable(true);

    chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(20, 5, 5, 20),
            BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Shouts"),
                    BorderFactory.createEmptyBorder(5, 5, 5, 5))));

    getContentPane().add(chartPanel, BorderLayout.CENTER);

    pack();
}

From source file:com.xpn.xwiki.plugin.charts.ChartCustomizer.java

public static void customizeChart(JFreeChart jfchart, ChartParams params) {
    // title//from www . ja va2  s  . com
    if (params.get(ChartParams.TITLE_PREFIX + ChartParams.TITLE_SUFFIX) != null) {
        TextTitle title = new TextTitle(params.getString(ChartParams.TITLE_PREFIX + ChartParams.TITLE_SUFFIX));

        customizeTitle(title, params, ChartParams.TITLE_PREFIX);

        jfchart.setTitle(title);
    }

    // subtitle
    if (params.get(ChartParams.SUBTITLE_PREFIX + ChartParams.TITLE_SUFFIX) != null) {
        TextTitle subtitle = new TextTitle(
                params.getString(ChartParams.SUBTITLE_PREFIX + ChartParams.TITLE_SUFFIX));

        customizeTitle(subtitle, params, ChartParams.SUBTITLE_PREFIX);

        jfchart.addSubtitle(subtitle);
    }

    // legend
    LegendTitle legend = jfchart.getLegend();

    customizeLegend(legend, params);

    // anti-alias
    if (params.get(ChartParams.ANTI_ALIAS) != null) {
        jfchart.setAntiAlias(params.getBoolean(ChartParams.ANTI_ALIAS).booleanValue());
    }
    // background color
    if (params.get(ChartParams.BACKGROUND_COLOR) != null) {
        jfchart.setBackgroundPaint(params.getColor(ChartParams.BACKGROUND_COLOR));
    }

    // border
    if (params.get(ChartParams.BORDER_VISIBLE) != null
            && params.getBoolean(ChartParams.BORDER_VISIBLE).booleanValue()) {
        jfchart.setBorderVisible(true);
        if (params.get(ChartParams.BORDER_COLOR) != null) {
            jfchart.setBorderPaint(params.getColor(ChartParams.BORDER_COLOR));
        }
        if (params.get(ChartParams.BORDER_STROKE) != null) {
            jfchart.setBorderStroke(params.getStroke(ChartParams.BORDER_STROKE));
        }
    }
}

From source file:org.deegree.graphics.charts.ChartsBuilder.java

/**
 * Initializes the chart with the values from the properties file config.properties
 *
 * @param chart/*from   w w w .  java 2 s .c  o  m*/
 * @param chartConfigs
 *            to configure the output chart
 * @return initialized chart
 */
protected JFreeChart configChart(JFreeChart chart, ChartConfig chartConfigs) {

    chart.setAntiAlias(chartConfigs.isGenAntiAliasing());

    chart.setBorderVisible(chartConfigs.isGenBorderVisible());

    String rectanglkeInsets = chartConfigs.getGenRectangleInsets();
    if (!rectanglkeInsets.startsWith("!")) {
        String[] insets = rectanglkeInsets.split(",");
        if (insets.length == 4) {
            try {
                double top = Double.parseDouble(insets[0]);
                double left = Double.parseDouble(insets[1]);
                double buttom = Double.parseDouble(insets[2]);
                double right = Double.parseDouble(insets[3]);
                RectangleInsets rectInsets = new RectangleInsets(top, left, buttom, right);
                chart.setPadding(rectInsets);
            } catch (Exception e) {
                LOG.logError(Messages.getMessage("GRA_CHART_BAD_FORMAT_INSETS"));
            }
        } else {
            LOG.logError(Messages.getMessage("GRA_CHART_BAD_FORMAT_INSETS"));
        }
    }

    chart.setTextAntiAlias(chartConfigs.isGenTextAntiAlias());
    chart.setBackgroundPaint(chartConfigs.getGenBackgroundColor());

    chart.getPlot().setOutlineVisible(chartConfigs.isPlotOutlineVisible());
    chart.getPlot().setForegroundAlpha((float) chartConfigs.getPlotForegroundOpacity());
    chart.getPlot().setBackgroundPaint(chartConfigs.getPlotBackgroundColor());
    return chart;
}

From source file:com.google.gwt.benchmarks.viewer.server.ReportImageServer.java

private void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {

    String uri = request.getRequestURI();
    String requestString = uri.split("test_images/")[1];
    String[] requestParams = requestString.split("/");

    String reportName = URLDecoder.decode(requestParams[0], charset);
    String categoryName = URLDecoder.decode(requestParams[1], charset);
    // String className = URLDecoder.decode(requestParams[2], charset);
    String testName = URLDecoder.decode(requestParams[3], charset);
    String agent = URLDecoder.decode(requestParams[4], charset);

    ReportDatabase db = ReportDatabase.getInstance();
    Report report = db.getReport(reportName);
    List<Category> categories = report.getCategories();
    Category category = getCategoryByName(categories, categoryName);
    List<Benchmark> benchmarks = category.getBenchmarks();
    Benchmark benchmark = getBenchmarkByName(benchmarks, testName);
    List<Result> results = benchmark.getResults();
    Result result = getResultsByAgent(results, agent);

    String title = BrowserInfo.getBrowser(agent);
    JFreeChart chart = createChart(testName, result, title, results);

    chart.getTitle().setFont(Font.decode("Verdana BOLD 12"));
    chart.setAntiAlias(true);
    chart.setBorderVisible(true);/*  ww  w .  j a v  a2 s. c  o  m*/
    chart.setBackgroundPaint(new Color(241, 241, 241));

    Plot plot = chart.getPlot();

    plot.setDrawingSupplier(getDrawingSupplier());
    plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 640, 480, new Color(200, 200, 200)));

    if (plot instanceof XYPlot) {
        XYPlot xyplot = (XYPlot) plot;
        Font labelFont = Font.decode("Verdana PLAIN");
        xyplot.getDomainAxis().setLabelFont(labelFont);
        xyplot.getRangeAxis().setLabelFont(labelFont);
        org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
        xyitemrenderer.setStroke(new BasicStroke(4));
        if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
            XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
            xylineandshaperenderer.setShapesVisible(true);
            xylineandshaperenderer.setShapesFilled(true);
        }
    }

    // Try to fit all the graphs into a 1024 window, with a min of 240 and a max
    // of 480
    final int graphWidth = Math.max(240, Math.min(480, (1024 - 10 * results.size()) / results.size()));
    BufferedImage img = chart.createBufferedImage(graphWidth, 240);
    byte[] image = EncoderUtil.encode(img, ImageFormat.PNG);

    // The images have unique URLs; might as well set them to never expire.
    response.setHeader("Cache-Control", "max-age=0");
    response.setHeader("Expires", "Fri, 2 Jan 1970 00:00:00 GMT");
    response.setContentType("image/png");
    response.setContentLength(image.length);

    OutputStream output = response.getOutputStream();
    output.write(image);
}

From source file:org.eevolution.form.CRPDetail.java

/**
 * Create Chart based on UOM/*from  www.ja  v a  2 s  . co  m*/
 * 
 * @param dataset
 * @param title
 * @param uom
 * @return JFreeChart Chart based On UOM
 */
public JFreeChart createChart(CategoryDataset dataset, String title, MUOM uom) {

    JFreeChart chart = ChartFactory.createBarChart3D(title, Msg.translate(Env.getCtx(), "Day"), // X-Axis label
            Msg.translate(Env.getCtx(), (uom == null) ? "" : uom.getName()), // Y-Axis
            // label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    chart.setBackgroundPaint(Color.WHITE);
    chart.setAntiAlias(true);
    chart.setBorderVisible(true);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.GRAY);

    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.GRAY);

    BarRenderer3D barrenderer = (BarRenderer3D) plot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    barrenderer.setBaseItemLabelGenerator(new LabelGenerator());
    barrenderer.setBaseItemLabelsVisible(true);
    barrenderer.setSeriesPaint(0, new Color(10, 80, 150, 128));
    barrenderer.setSeriesPaint(1, new Color(180, 60, 50, 128));

    ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
            TextAnchor.TOP_CENTER);
    barrenderer.setPositiveItemLabelPosition(itemlabelposition);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    return chart;
}

From source file:org.deegree.graphics.charts.ChartsBuilder.java

/**
 * Creates a BufferedImage instance from a given chart, according to the given additional parameters
 *
 * @param chart/*from w w w .j  a v a2s .co m*/
 * @param width
 *            of the generated image
 * @param height
 *            of the generated image
 * @param imageType
 *            ex image/png, image/jpg
 * @return BufferedImage
 */
protected BufferedImage createBufferedImage(JFreeChart chart, int width, int height, String imageType) {

    chart.setTextAntiAlias(true);
    chart.setAntiAlias(true);
    BufferedImage image = new BufferedImage(width, height, mapImageformat(imageType));
    Graphics2D g2 = image.createGraphics();
    chart.draw(g2, new Rectangle(new Dimension(width, height)));
    return image;
}

From source file:com.estate.pdf.Page.java

protected void drawTaxPie(Rectangle rct, double totalValue, double tax, String taxLabel, String netLabel) {
    double taxPercent = (tax / totalValue) * 100;
    double netValuePercent = 100 - taxPercent;

    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue(taxLabel, taxPercent);
    dataset.setValue(netLabel, netValuePercent);

    PiePlot3D plot = new PiePlot3D(dataset);
    plot.setLabelGenerator(new StandardPieItemLabelGenerator());
    plot.setInsets(new Insets(0, 5, 5, 5));
    plot.setToolTipGenerator(new CustomeGenerators.CustomToolTipGenerator());
    plot.setLabelGenerator(new CustomeGenerators.CustomLabelGenerator());
    plot.setSectionPaint(0, new Color(pgRed));
    plot.setSectionPaint(1, new Color(pgGreen));
    plot.setForegroundAlpha(.6f);//from  www  .ja  v a  2  s.  c o  m
    plot.setOutlinePaint(Color.white);
    plot.setBackgroundPaint(Color.white);

    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);

    Rectangle page = rct;

    try {
        Image img = Image.getInstance(chart.createBufferedImage((int) page.getWidth(), (int) page.getHeight()),
                null);
        drawDiagram(img, rct, 0, 72);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

}

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

protected void configureSubChart(final JFreeChart chart) {
    final TextTitle chartTitle = chart.getTitle();
    if (chartTitle != null) {
        if (getPieTitleFont() != null) {
            chartTitle.setFont(getPieTitleFont());
        } else {//ww  w .  j a v a  2 s .co m
            final Font titleFont = Font.decode(getTitleFont());
            chartTitle.setFont(titleFont);
        }
    }

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

    final LegendTitle chLegend = chart.getLegend();
    if (chLegend != null) {
        final RectangleEdge loc = translateEdge(getLegendLocation().toLowerCase());
        if (loc != null) {
            chLegend.setPosition(loc);
        }
        if (getLegendFont() != null) {
            chLegend.setItemFont(Font.decode(getLegendFont()));
        }
        if (!isDrawLegendBorder()) {
            chLegend.setBorder(BlockBorder.NONE);
        }
        if (getLegendBackgroundColor() != null) {
            chLegend.setBackgroundPaint(getLegendBackgroundColor());
        }
        if (getLegendTextColor() != null) {
            chLegend.setItemPaint(getLegendTextColor());
        }
    }

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

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

From source file:org.trade.ui.chart.CandlestickChart.java

/**
 * Method createChart./* w  w  w  .j  a v a2s  .  c o m*/
 * 
 * @param strategyData
 *            StrategyData
 * @param title
 *            String
 * @return JFreeChart
 */
private JFreeChart createChart(StrategyData strategyData, String title, Tradingday tradingday) {

    DateAxis dateAxis = new DateAxis("Date");
    dateAxis.setVerticalTickLabels(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm"));
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    NumberAxis priceAxis = new NumberAxis("Price");
    priceAxis.setAutoRange(true);
    priceAxis.setAutoRangeIncludesZero(false);
    XYPlot pricePlot = new XYPlot(strategyData.getCandleDataset(), dateAxis, priceAxis,
            strategyData.getCandleDataset().getRenderer());
    pricePlot.setOrientation(PlotOrientation.VERTICAL);
    pricePlot.setDomainPannable(true);
    pricePlot.setRangePannable(true);
    pricePlot.setDomainCrosshairVisible(true);
    pricePlot.setDomainCrosshairLockedOnData(true);
    pricePlot.setRangeCrosshairVisible(true);
    pricePlot.setRangeCrosshairLockedOnData(true);
    pricePlot.setRangeGridlinePaint(new Color(204, 204, 204));
    pricePlot.setDomainGridlinePaint(new Color(204, 204, 204));
    pricePlot.setBackgroundPaint(Color.white);

    /*
     * Calculate the number of 15min segments in this trading day. i.e.
     * 6.5hrs/15min = 26 and there are a total of 96 = one day
     */

    int segments15min = (int) (tradingday.getClose().getTime() - tradingday.getOpen().getTime())
            / (1000 * 60 * 15);

    SegmentedTimeline segmentedTimeline = new SegmentedTimeline(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE,
            segments15min, (96 - segments15min));

    Date startDate = tradingday.getOpen();
    Date endDate = tradingday.getClose();

    if (!strategyData.getCandleDataset().getSeries(0).isEmpty()) {
        startDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0).getDataItem(0)).getPeriod()
                .getStart();
        startDate = TradingCalendar.getSpecificTime(tradingday.getOpen(), startDate);
        endDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0)
                .getDataItem(strategyData.getCandleDataset().getSeries(0).getItemCount() - 1)).getPeriod()
                        .getStart();
        endDate = TradingCalendar.getSpecificTime(tradingday.getClose(), endDate);
    }

    segmentedTimeline.setStartTime(startDate.getTime());
    segmentedTimeline.addExceptions(getNonTradingPeriods(startDate, endDate, tradingday.getOpen(),
            tradingday.getClose(), segmentedTimeline));
    dateAxis.setTimeline(segmentedTimeline);

    // Build Combined Plot
    CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(dateAxis);
    mainPlot.add(pricePlot, 4);

    int axixIndex = 0;
    int datasetIndex = 0;

    /*
     * Change the List of indicators so that the candle dataset is the first
     * one in the list. The main chart must be plotted first.
     */
    List<IndicatorDataset> indicators = new ArrayList<IndicatorDataset>(0);
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (!IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (int i = 0; i < indicators.size(); i++) {
        IndicatorDataset indicator = indicators.get(i);
        if (indicator.getDisplaySeries(0)) {

            if (indicator.getSubChart(0)) {
                String axisName = "Price";
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    axisName = ((CandleSeries) indicator.getSeries(0)).getSymbol();
                } else {
                    org.trade.dictionary.valuetype.IndicatorSeries code = org.trade.dictionary.valuetype.IndicatorSeries
                            .newInstance(indicator.getType(0));
                    axisName = code.getDisplayName();
                }
                NumberAxis subPlotAxis = new NumberAxis(axisName);
                subPlotAxis.setAutoRange(true);
                subPlotAxis.setAutoRangeIncludesZero(false);

                XYPlot subPlot = new XYPlot((XYDataset) indicator, dateAxis, subPlotAxis,
                        indicator.getRenderer());

                subPlot.setOrientation(PlotOrientation.VERTICAL);
                subPlot.setDomainPannable(true);
                subPlot.setRangePannable(true);
                subPlot.setDomainCrosshairVisible(true);
                subPlot.setDomainCrosshairLockedOnData(true);
                subPlot.setRangeCrosshairVisible(true);
                subPlot.setRangeCrosshairLockedOnData(true);
                subPlot.setRangeGridlinePaint(new Color(204, 204, 204));
                subPlot.setDomainGridlinePaint(new Color(204, 204, 204));
                subPlot.setBackgroundPaint(Color.white);
                XYItemRenderer renderer = subPlot.getRendererForDataset((XYDataset) indicator);
                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
                mainPlot.add(subPlot, 1);

            } else {
                datasetIndex++;
                pricePlot.setDataset(datasetIndex, (XYDataset) indicator);
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    // add secondary axis
                    axixIndex++;

                    final NumberAxis axis2 = new NumberAxis(
                            ((CandleSeries) indicator.getSeries(0)).getSymbol());
                    axis2.setAutoRange(true);
                    axis2.setAutoRangeIncludesZero(false);
                    pricePlot.setRangeAxis(datasetIndex, axis2);
                    pricePlot.setRangeAxisLocation(i + 1, AxisLocation.BOTTOM_OR_RIGHT);
                    pricePlot.mapDatasetToRangeAxis(datasetIndex, axixIndex);
                    pricePlot.setRenderer(datasetIndex, new StandardXYItemRenderer());
                } else {
                    pricePlot.setRenderer(datasetIndex, indicator.getRenderer());
                }
                XYItemRenderer renderer = pricePlot.getRendererForDataset((XYDataset) indicator);

                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
            }
        }
    }
    JFreeChart jfreechart = new JFreeChart(title, null, mainPlot, true);
    jfreechart.setAntiAlias(false);
    return jfreechart;
}