Example usage for org.jfree.chart.title TextTitle setFont

List of usage examples for org.jfree.chart.title TextTitle setFont

Introduction

In this page you can find the example usage for org.jfree.chart.title TextTitle setFont.

Prototype

public void setFont(Font font) 

Source Link

Document

Sets the font used to display the title string.

Usage

From source file:unalcol.termites.boxplots.RoundNumber1.java

/**
 * Creates a new demo.//w  ww . ja  va2 s.  c o m
 *
 * @param title the frame title.
 * @param pf
 */
public RoundNumber1(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Round number");
    final NumberAxis yAxis = new NumberAxis("");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 16);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round Number" + getTitle(pf), new Font("SansSerif", Font.BOLD, 18),
            plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);

    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("roundnumber1" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 450, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(RoundNumber1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RoundNumber1.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.netflix.ice.basic.BasicWeeklyCostEmailService.java

private File createImage(ApplicationGroup appgroup) throws IOException {

    Map<String, Double> costs = Maps.newHashMap();
    DateTime end = new DateTime(DateTimeZone.UTC).withDayOfWeek(1).withMillisOfDay(0);
    Interval interval = new Interval(end.minusWeeks(numWeeks), end);

    for (Product product : products) {
        List<ResourceGroup> resourceGroups = getResourceGroups(appgroup, product);
        if (resourceGroups.size() == 0) {
            continue;
        }//from   ww w. j a v a  2  s.c om
        DataManager dataManager = config.managers.getCostManager(product, ConsolidateType.weekly);
        if (dataManager == null) {
            continue;
        }
        TagLists tagLists = new TagLists(accounts, regions, null, Lists.newArrayList(product), null, null,
                resourceGroups);
        Map<Tag, double[]> data = dataManager.getData(interval, tagLists, TagType.Product, AggregateType.none,
                false);
        for (Tag tag : data.keySet()) {
            for (int week = 0; week < numWeeks; week++) {
                String key = tag + "|" + week;
                if (costs.containsKey(key))
                    costs.put(key, data.get(tag)[week] + costs.get(key));
                else
                    costs.put(key, data.get(tag)[week]);
            }
        }
    }

    boolean hasData = false;
    for (Map.Entry<String, Double> entry : costs.entrySet()) {
        if (!entry.getKey().contains("monitor") && entry.getValue() != null && entry.getValue() >= 0.1) {
            hasData = true;
            break;
        }
    }
    if (!hasData)
        return null;

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (Product product : products) {
        for (int week = 0; week < numWeeks; week++) {
            String weekStr = String.format("%s - %s week",
                    formatter.print(end.minusWeeks(numWeeks - week)).substring(5),
                    formatter.print(end.minusWeeks(numWeeks - week - 1)).substring(5));
            dataset.addValue(costs.get(product + "|" + week), product.name, weekStr);
        }
    }

    JFreeChart chart = ChartFactory.createBarChart3D(appgroup.getDisplayName() + " Weekly AWS Costs", "",
            "Costs", dataset, PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    BarRenderer3D renderer = (BarRenderer3D) categoryplot.getRenderer();
    renderer.setItemLabelAnchorOffset(10.0);
    TextTitle title = chart.getTitle();
    title.setFont(title.getFont().deriveFont((title.getFont().getSize() - 3)));

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() {
        public java.lang.String generateLabel(org.jfree.data.category.CategoryDataset dataset, int row,
                int column) {
            return costFormatter.format(dataset.getValue(row, column));
        }
    });
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setNumberFormatOverride(costFormatter);

    BufferedImage image = chart.createBufferedImage(1200, 400);
    File outputfile = File.createTempFile("awscost", "png");
    ImageIO.write(image, "png", outputfile);

    return outputfile;
}

From source file:org.martus.client.swingui.actions.ActionMenuCharts.java

private JFreeChart createChart(ChartAnswers answers, MiniFieldSpec fieldToCount,
        HashMap<String, Integer> counts) throws Exception, TokenInvalidException {
    String selectedFieldLabel = fieldToCount.getLabel();
    if (selectedFieldLabel.equals(""))
        selectedFieldLabel = getLocalization().getFieldLabel(fieldToCount.getTag());

    JFreeChart chart = createRawChart(answers, counts, selectedFieldLabel);
    new MartusChartTheme().apply(chart);
    TextTitle subtitle = new TextTitle(answers.getSubtitle());
    subtitle.setFont(FontHandler.getDefaultFont());
    chart.addSubtitle(subtitle);/*from  ww w.  j  a  v a  2 s .c o m*/
    chart.addSubtitle(createLegend(chart));

    String today = getLocalization().formatDateTime(new Date().getTime());
    String chartCreatedOnLabel = getLocalization().getFieldLabel("ChartCreatedOn");
    chartCreatedOnLabel = TokenReplacement.replaceToken(chartCreatedOnLabel, "#Date#", today);
    chart.addSubtitle(new ShortTextTitle(chartCreatedOnLabel));
    return chart;
}

From source file:org.toobsframework.pres.chart.ChartBuilder.java

private JFreeChart finishChart(IRequest componentRequest, ChartDefinition chartDef, Plot plot, Map params) {

    JFreeChart chart = new JFreeChart(
            ChartUtil.evaluateTextLabel(componentRequest, chartDef.getTitle(), params),
            ChartUtil.getFont(chartDef.getTitle(), JFreeChart.DEFAULT_TITLE_FONT), plot,
            chartDef.isShowLegend());//from   w  ww. j ava 2 s  . com

    if (chartDef.getSubtitle() != null) {
        TextTitle subtitle = new TextTitle(
                ChartUtil.evaluateTextLabel(componentRequest, chartDef.getSubtitle(), params));
        if (chartDef.getSubtitle().getFont() != null) {
            subtitle.setFont(ChartUtil.getFont(chartDef.getSubtitle(), null));
        }
        subtitle.setPosition(ChartUtil.getPosition(chartDef.getSubtitle().getPosition()));
        subtitle.setPadding(
                ChartUtil.getRectangle(componentRequest, chartDef.getSubtitle().getPadding(), params));
        subtitle.setVerticalAlignment(
                ChartUtil.getVerticalAlignment(chartDef.getSubtitle().getVerticalAlignment()));
        subtitle.setPaint(ChartUtil.getColor(chartDef.getSubtitle().getColor()));
        chart.addSubtitle(subtitle);
    }

    chart.setBackgroundPaint(ChartUtil.getColor(chartDef.getBackgroundColor()));
    if (chartDef.getTitle() != null && chartDef.getTitle().getColor() != null) {
        chart.getTitle().setPaint(ChartUtil.getColor(chartDef.getTitle().getColor()));
    }

    if (chartDef.isShowLegend()) {
        ChartUtil.configureLegend(componentRequest, chart, chartDef.getLegend(), params);
    }

    return chart;
}

From source file:nu.nethome.tools.protocol_analyzer.RawMessageDistributionWindow.java

private void configurePanelLooks(JFreeChart chart, int selectionSeries) {
    TextTitle title = chart.getTitle(); // fix title
    Font titleFont = title.getFont();
    titleFont = titleFont.deriveFont(Font.PLAIN, (float) 14.0);
    title.setFont(titleFont);
    title.setPaint(Color.darkGray);
    XYPlot plot = chart.getXYPlot();//from  w  w w. ja v a 2s .c o  m
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    XYLineAndShapeRenderer signalRenderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
    signalRenderer.setSeriesStroke(selectionSeries, new BasicStroke(5f));
}

From source file:unalcol.termites.boxplots.BestAgentsPercentageInfoCollected.java

/**
 * Creates a new demo.//from  www  . ja v a2 s  .  c  o  m
 *
 * @param title the frame title.
 * @param pf
 */
public BestAgentsPercentageInfoCollected(final String title, ArrayList<Double> pf) {

    super(title);
    String sDirectorio = experimentsDir;

    Hashtable<String, List> info = new Hashtable();

    //String[] aMode = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4"};
    /*for (String mode : aMode) {
     info.put(mode, new ArrayList());
     }*/
    createSampleDataset(pf, info);
    AddDataFailingExperiments(sDirectorio, pf, info);
    final BoxAndWhiskerCategoryDataset dataset = addDataSet(info);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Information Collected");
    final NumberAxis yAxis = new NumberAxis("");

    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 13);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Information Collected " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 18), plot, true);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);

    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("BestAgentsPercentageInfoCollected" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 350, 350, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(BestAgentsPercentageInfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(BestAgentsPercentageInfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:unalcol.termites.boxplots.BestAgentsRoundInfoCollected.java

/**
 * Creates a new demo.//from  ww  w . j av  a  2s. c o  m
 *
 * @param title the frame title.
 * @param pf
 */
public BestAgentsRoundInfoCollected(final String title, ArrayList<Double> pf) {

    super(title);
    String sDirectorio = experimentsDir;

    Hashtable<String, List> info = new Hashtable();

    /*for (String mode : aMode) {
    info.put(mode, new ArrayList());
    }*/

    createSampleDataset(pf, info);
    AddDataFailingExperiments(sDirectorio, pf, info);
    final BoxAndWhiskerCategoryDataset dataset = addDataSet(info);
    System.out.println("info" + info);
    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Information Collected");
    final NumberAxis yAxis = new NumberAxis("");

    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 13);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round of Best Agents " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 18), plot, true);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);

    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("BestAgentsRound" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 450, 350, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(BestAgentsRoundInfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(BestAgentsRoundInfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartTimeSeriesGraphSource.java

/**
 * Initializes the graph.  This method generates the backing {@link JFreeChart} from the time series and graph
 * parameter data./*from   w w w  .java 2s  . c o  m*/
 *
 * @throws GraphException if the initialization fails
 */
public void initialize() throws GraphException {
    String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE);
    String xLabel = getParam(GraphSource.GRAPH_X_LABEL, String.class, DEFAULT_DOMAIN_LABEL);
    String yLabel = getParam(GraphSource.GRAPH_Y_LABEL, String.class, DEFAULT_RANGE_LABEL);
    Shape graphShape = getParam(GraphSource.GRAPH_SHAPE, Shape.class, DEFAULT_GRAPH_SHAPE);
    Paint graphColor = getParam(GraphSource.GRAPH_COLOR, Paint.class, DEFAULT_GRAPH_COLOR);
    boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND);
    boolean graphToolTip = getParam(GraphSource.GRAPH_TOOL_TIP, Boolean.class, DEFAULT_GRAPH_TOOL_TIP);
    Stroke graphStroke = getParam(GraphSource.GRAPH_STROKE, Stroke.class, DEFAULT_GRAPH_STROKE);
    Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT);
    boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER);
    boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER);
    Double offset = getParam(GraphSource.AXIS_OFFSET, Double.class, DEFAULT_AXIS_OFFSET);

    checkSeriesType(data);
    @SuppressWarnings("unchecked")
    List<? extends TimeSeriesInterface> timeData = (List<? extends TimeSeriesInterface>) data;

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    int seriesCount = 1;
    for (TimeSeriesInterface series : timeData) {
        dataset.addSeries(buildTimeSeries(series, seriesCount));
        seriesCount += 1;
    }

    // actually create the chart
    this.chart = ChartFactory.createTimeSeriesChart(title, xLabel, yLabel, dataset, false, graphToolTip, false);

    // start customizing it
    Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR);
    Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor);
    Paint graphDomainGridlinePaint = getParam(GraphSource.GRAPH_DOMAIN_GRIDLINE_PAINT, Paint.class,
            backgroundColor);
    Paint graphRangeGridlinePaint = getParam(GraphSource.GRAPH_RANGE_GRIDLINE_PAINT, Paint.class,
            backgroundColor);

    this.chart.setBackgroundPaint(backgroundColor);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(plotColor);
    plot.setAxisOffset(new RectangleInsets(offset, offset, offset, offset));
    plot.setDomainGridlinePaint(graphDomainGridlinePaint);
    plot.setRangeGridlinePaint(graphRangeGridlinePaint);

    if (graphBorder) {

    } else {
        plot.setOutlinePaint(null);
    }

    //Use a TextTitle to change the font of the graph title
    TextTitle title1 = new TextTitle();
    title1.setText(title);
    title1.setFont(titleFont);
    chart.setTitle(title1);

    //Makes a wrapper for the legend to remove the border around it
    if (legend) {
        LegendTitle legend1 = new LegendTitle(chart.getPlot());
        BlockContainer wrapper = new BlockContainer(new BorderArrangement());
        if (legendBorder) {
            wrapper.setFrame(new BlockBorder(1, 1, 1, 1));
        } else {
            wrapper.setFrame(new BlockBorder(0, 0, 0, 0));
        }
        BlockContainer items = legend1.getItemContainer();
        items.setPadding(2, 10, 5, 2);
        wrapper.add(items);
        legend1.setWrapper(wrapper);
        legend1.setPosition(RectangleEdge.BOTTOM);
        legend1.setHorizontalAlignment(HorizontalAlignment.CENTER);

        if (params.get(GraphSource.LEGEND_FONT) instanceof Font) {
            legend1.setItemFont(((Font) params.get(GraphSource.LEGEND_FONT)));
        }

        chart.addSubtitle(legend1);
    }

    boolean include0 = getParam(GraphSource.GRAPH_RANGE_INCLUDE_0, Boolean.class, true);
    NumberAxis numAxis = (NumberAxis) plot.getRangeAxis();
    double rangeLower = getParam(GraphSource.GRAPH_RANGE_LOWER_BOUND, Double.class, numAxis.getLowerBound());
    double rangeUpper = getParam(GraphSource.GRAPH_RANGE_UPPER_BOUND, Double.class, numAxis.getUpperBound());
    boolean graphRangeIntegerTick = getParam(GraphSource.GRAPH_RANGE_INTEGER_TICK, Boolean.class, false);
    boolean graphRangeMinorTickVisible = getParam(GraphSource.GRAPH_RANGE_MINOR_TICK_VISIBLE, Boolean.class,
            true);

    if (include0) {
        rangeLower = 0;
    }

    numAxis.setRange(rangeLower, rangeUpper);

    if (graphRangeIntegerTick) {
        numAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    numAxis.setMinorTickMarksVisible(graphRangeMinorTickVisible);
    setupFont(numAxis, GraphSource.GRAPH_Y_AXIS_FONT);

    if (params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT) instanceof Font) {
        numAxis.setLabelFont(((Font) params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT)));
    }

    TimeResolution minimumResolution = getMinimumResolution(timeData);
    DateFormat dateFormat = getParam(GraphSource.GRAPH_DATE_FORMATTER, DateFormat.class,
            new DefaultDateFormatFactory().getFormat(minimumResolution));

    if (params.get(DATE_AXIS) instanceof DateAxis) {
        DateAxis dateAxis = (DateAxis) params.get(DATE_AXIS);
        dateAxis.setLabel(xLabel);
        plot.setDomainAxis(dateAxis);
    }
    DateAxis dateAxis = ((DateAxis) plot.getDomainAxis());
    dateAxis.setDateFormatOverride(dateFormat);

    if (params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT) instanceof Font) {
        dateAxis.setLabelFont(((Font) params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT)));
    }

    int minTick = getParam(GraphSource.GRAPH_MIN_DOMAIN_TICK, Integer.class, 1);
    if (minTick <= 0) {
        minTick = 1;
    }

    dateAxis.setTickUnit(getDateTickUnit(minimumResolution, minTick), false, false);
    //dateAxis.setMinorTickMarksVisible(true);
    //dateAxis.setMinorTickCount(7);
    dateAxis.setMinorTickMarkOutsideLength(2);

    Integer minorTick = getParam(GraphSource.GRAPH_MINOR_TICKS, Integer.class, null);
    if (minorTick != null) {
        int minorVal = minorTick;
        if (minorVal > 0) {
            dateAxis.setMinorTickCount(minorVal);
        }
    }

    setupFont(dateAxis, GraphSource.GRAPH_X_AXIS_FONT);

    //double lowerMargin = getParam(DOMAIN_AXIS_LOWER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_LOWER_MARGIN);
    double lowerMargin = getParam(DOMAIN_AXIS_LOWER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_LOWER_MARGIN);
    dateAxis.setLowerMargin(lowerMargin);

    //double upperMargin = getParam(DOMAIN_AXIS_UPPER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_UPPER_MARGIN);
    double upperMargin = getParam(DOMAIN_AXIS_UPPER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_UPPER_MARGIN);
    dateAxis.setUpperMargin(upperMargin);

    Date domainLower = getParam(GraphSource.GRAPH_DOMAIN_LOWER_BOUND, Date.class, dateAxis.getMinimumDate());
    Date domainUpper = getParam(GraphSource.GRAPH_DOMAIN_UPPER_BOUND, Date.class, dateAxis.getMaximumDate());

    dateAxis.setRange(domainLower, domainUpper);

    // depending on the domain axis range, display either 1 tick per day, week, month or year
    TickUnits standardUnits = new TickUnits();
    standardUnits.add(new DateTickUnit(DateTickUnitType.DAY, 1));
    standardUnits.add(new DateTickUnit(DateTickUnitType.DAY, 7));
    standardUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 1));
    standardUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 1));
    dateAxis.setStandardTickUnits(standardUnits);

    TimeSeriesRenderer renderer = new TimeSeriesRenderer(dataset);
    setupRenderer(renderer, graphColor, graphShape, graphStroke);
    renderer.setBaseFillPaint(Color.BLACK);
    renderer.setSeriesOutlinePaint(0, Color.WHITE);

    //renderer.setUseOutlinePaint(true);

    plot.setRenderer(renderer);
    this.initialized = true;
}

From source file:ch.algotrader.client.chart.ChartTab.java

public void init(ChartDefinitionVO chartDefinition) {

    // remove all components first
    this.removeAll();

    resetPopupMenu();/*  w w  w  . jav  a2s .co m*/

    this.chartDefinition = chartDefinition;

    // create the plot
    XYPlot plot = new XYPlot();

    // add gridlines
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);

    // create the JFreeChart
    JFreeChart chart = new JFreeChart(plot);
    this.setChart(chart);

    // init the maps
    this.bars = new HashMap<>();
    this.indicators = new HashMap<>();
    this.markers = new HashMap<>();
    this.markersSelectionStatus = new HashMap<>();

    // init domain axis
    initDomainAxis(chartDefinition);

    // init range axis
    initRangeAxis(chartDefinition);

    // create a subtitle
    TextTitle title = new TextTitle();
    title.setFont(new Font("SansSerif", 0, 9));
    chart.addSubtitle(title);

    // crosshair
    plot.setDomainCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(true);
}

From source file:net.sf.jasperreports.components.spiderchart.FillSpiderChart.java

protected JFreeChart evaluateChart(byte evaluation) throws JRException {
    maxValue = (Double) fillContext.evaluate(getPlot().getMaxValueExpression(), evaluation);
    titleText = (String) fillContext.evaluate(getChartSettings().getTitleExpression(), evaluation);
    subtitleText = (String) fillContext.evaluate(getChartSettings().getSubtitleExpression(), evaluation);
    anchorName = (String) fillContext.evaluate(getChartSettings().getAnchorNameExpression(), evaluation);
    hyperlinkReference = (String) fillContext.evaluate(getChartSettings().getHyperlinkReferenceExpression(),
            evaluation);/*  w ww  .j  a va  2  s . c  o m*/
    hyperlinkAnchor = (String) fillContext.evaluate(getChartSettings().getHyperlinkAnchorExpression(),
            evaluation);
    hyperlinkPage = (Integer) fillContext.evaluate(getChartSettings().getHyperlinkPageExpression(), evaluation);
    hyperlinkTooltip = (String) fillContext.evaluate(getChartSettings().getHyperlinkTooltipExpression(),
            evaluation);
    hyperlinkParameters = JRFillHyperlinkHelper.evaluateHyperlinkParameters(getChartSettings(),
            expressionEvaluator, evaluation);

    dataset.evaluateDatasetRun(evaluation);
    dataset.finishDataset();

    chartHyperlinkProvider = new CategoryChartHyperlinkProvider(dataset.getItemHyperlinks());

    bookmarkLevel = getChartSettings().getBookmarkLevel();

    SpiderWebPlot spiderWebPlot = new SpiderWebPlot((DefaultCategoryDataset) dataset.getCustomDataset());

    if (getPlot().getAxisLineColor() != null) {
        spiderWebPlot.setAxisLinePaint(getPlot().getAxisLineColor());
    }
    if (getPlot().getAxisLineWidth() != null) {
        spiderWebPlot.setAxisLineStroke(new BasicStroke(getPlot().getAxisLineWidth()));
    }
    if (getPlot().getBackcolor() != null) {
        spiderWebPlot.setBackgroundPaint(getPlot().getBackcolor());
    }
    if (getPlot().getBackgroundAlpha() != null) {
        spiderWebPlot.setBackgroundAlpha(getPlot().getBackgroundAlpha());
    }
    if (getPlot().getForegroundAlpha() != null) {
        spiderWebPlot.setForegroundAlpha(getPlot().getForegroundAlpha());
    }
    if (getPlot().getHeadPercent() != null) {
        spiderWebPlot.setHeadPercent(getPlot().getHeadPercent());
    }
    if (getPlot().getInteriorGap() != null) {
        spiderWebPlot.setInteriorGap(getPlot().getInteriorGap());
    }
    if (getPlot().getLabelColor() != null) {
        spiderWebPlot.setLabelPaint(getPlot().getLabelColor());
    }
    if (getPlot().getLabelFont() != null) {
        spiderWebPlot.setLabelFont(JRFontUtil.getAwtFont(getPlot().getLabelFont(), Locale.getDefault()));
    }
    if (getPlot().getLabelGap() != null) {
        spiderWebPlot.setAxisLabelGap(getPlot().getLabelGap());
    }
    if (maxValue != null) {
        spiderWebPlot.setMaxValue(maxValue);
    }
    if (getPlot().getRotation() != null) {
        spiderWebPlot.setDirection(getPlot().getRotation().getRotation());
    }
    if (getPlot().getStartAngle() != null) {
        spiderWebPlot.setStartAngle(getPlot().getStartAngle());
    }
    if (getPlot().getTableOrder() != null) {
        spiderWebPlot.setDataExtractOrder(getPlot().getTableOrder().getOrder());
    }
    if (getPlot().getWebFilled() != null) {
        spiderWebPlot.setWebFilled(getPlot().getWebFilled());
    }

    spiderWebPlot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    spiderWebPlot.setLabelGenerator(new StandardCategoryItemLabelGenerator());

    Font titleFont = getChartSettings().getTitleFont() != null
            ? JRFontUtil.getAwtFont(getChartSettings().getTitleFont(), Locale.getDefault())
            : TextTitle.DEFAULT_FONT;

    JFreeChart jfreechart = new JFreeChart(titleText, titleFont, spiderWebPlot, true);

    if (chartSettings.getBackcolor() != null) {
        jfreechart.setBackgroundPaint(chartSettings.getBackcolor());
    }

    RectangleEdge titleEdge = getEdge(getChartSettings().getTitlePosition(), RectangleEdge.TOP);

    if (titleText != null) {
        TextTitle title = jfreechart.getTitle();
        title.setText(titleText);
        if (getChartSettings().getTitleColor() != null) {
            title.setPaint(getChartSettings().getTitleColor());
        }

        title.setFont(titleFont);
        title.setPosition(titleEdge);
        jfreechart.setTitle(title);
    }

    if (subtitleText != null) {
        TextTitle subtitle = new TextTitle(subtitleText);
        subtitle.setText(subtitleText);
        if (getChartSettings().getSubtitleColor() != null) {
            subtitle.setPaint(getChartSettings().getSubtitleColor());
        }

        if (getChartSettings().getSubtitleColor() != null) {
            Font subtitleFont = getChartSettings().getSubtitleFont() != null
                    ? JRFontUtil.getAwtFont(getChartSettings().getSubtitleFont(), Locale.getDefault())
                    : TextTitle.DEFAULT_FONT;
            subtitle.setFont(subtitleFont);
        }

        subtitle.setPosition(titleEdge);

        jfreechart.addSubtitle(subtitle);
    }

    // Apply all of the legend formatting options
    LegendTitle legend = jfreechart.getLegend();

    if (legend != null) {
        legend.setVisible((chartSettings.getShowLegend() == null || chartSettings.getShowLegend()));
        if (legend.isVisible()) {
            if (getChartSettings().getLegendColor() != null) {
                legend.setItemPaint(getChartSettings().getLegendColor());
            }
            if (getChartSettings().getLegendBackgroundColor() != null) {
                legend.setBackgroundPaint(getChartSettings().getLegendBackgroundColor());
            }

            if (getChartSettings().getLegendFont() != null) {
                legend.setItemFont(
                        JRFontUtil.getAwtFont(getChartSettings().getLegendFont(), Locale.getDefault()));
            }
            legend.setPosition(getEdge(getChartSettings().getLegendPosition(), RectangleEdge.BOTTOM));
        }
    }
    return jfreechart;

}