Example usage for org.jfree.chart JFreeChart setTitle

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

Introduction

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

Prototype

public void setTitle(String text) 

Source Link

Document

Sets the chart title and sends a ChartChangeEvent to all registered listeners.

Usage

From source file:org.jfree.chart.demo.OverlaidBarChartDemo2.java

/**
 * Creates a sample chart.//from   w w  w.j  ava2s  . com
 * 
 * @return A sample chart.
 */
private JFreeChart createChart() {

    // create the first dataset...
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(1.0, "S1", "Category 1");
    dataset1.addValue(4.0, "S1", "Category 2");
    dataset1.addValue(3.0, "S1", "Category 3");
    dataset1.addValue(5.0, "S1", "Category 4");
    dataset1.addValue(5.0, "S1", "Category 5");
    dataset1.addValue(5.0, "S2", "Category 1");
    dataset1.addValue(7.0, "S2", "Category 2");
    dataset1.addValue(6.0, "S2", "Category 3");
    dataset1.addValue(8.0, "S2", "Category 4");
    dataset1.addValue(4.0, "S2", "Category 5");

    // create the first plot...
    final CategoryItemRenderer renderer = new BarRenderer();
    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset1);
    plot.setRenderer(renderer);

    plot.setDomainAxis(new CategoryAxis("Category"));
    plot.setRangeAxis(new NumberAxis("Value"));

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.addValue(6.0, "Prior 1", "Category 1");
    dataset2.addValue(7.0, "Prior 1", "Category 2");
    dataset2.addValue(2.0, "Prior 1", "Category 3");
    dataset2.addValue(6.0, "Prior 1", "Category 4");
    dataset2.addValue(6.0, "Prior 1", "Category 5");
    dataset2.addValue(4.0, "Prior 2", "Category 1");
    dataset2.addValue(2.0, "Prior 2", "Category 2");
    dataset2.addValue(1.0, "Prior 2", "Category 3");
    dataset2.addValue(3.0, "Prior 2", "Category 4");
    dataset2.addValue(2.0, "Prior 2", "Category 5");

    final CategoryItemRenderer renderer2 = new LevelRenderer();
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer2.setSeriesStroke(1, new BasicStroke(2.0f));
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

    final JFreeChart chart = new JFreeChart(plot);
    chart.setTitle("Overlaid Bar Chart");
    //        chart.setLegend(new StandardLegend());
    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:meter_rpm.Stackoverflow.java

private ChartPanel buildDialPlot(int minimumValue, int maximumValue, int majorTickGap) {

    DialPlot plot = new DialPlot();
    plot.setView(0.0D, 0.0D, 1.0D, 1.0D);
    plot.setDataset(0, dataset0);/* w w  w. j av  a  2s  . c o m*/
    plot.setDataset(1, dataset1);

    plot.setDialFrame(new StandardDialFrame());

    DialTextAnnotation dialtextannotation = new DialTextAnnotation("RPM");
    dialtextannotation.setFont(new Font("Dialog", 1, 12));
    dialtextannotation.setRadius(0.69999999999999996D);
    plot.addLayer(dialtextannotation);

    // value indicator uses the real data set
    //plot.addLayer(new DialValueIndicator(0));

    DialValueIndicator dialvalueindicator = new DialValueIndicator(0);
    dialvalueindicator.setFont(new Font("Dialog", Font.BOLD, 12));
    dialvalueindicator.setOutlinePaint(Color.YELLOW);
    dialvalueindicator.setRadius(0.6D);
    dialvalueindicator.setAngle(-90D);
    dialvalueindicator.setTemplateValue(1000);
    plot.addLayer(dialvalueindicator);

    org.jfree.chart.plot.dial.DialPointer.Pin pin1 = new org.jfree.chart.plot.dial.DialPointer.Pin(1);
    pin1.setRadius(0.55000000000000004D);
    plot.addPointer(pin1);

    // needle uses constrained data set
    plot.addLayer(new DialPointer.Pointer(0));

    StandardDialScale scale = new StandardDialScale(0d, 6000, -110, -320, majorTickGap, 4);
    scale.setTickRadius(0.88);
    scale.setTickLabelOffset(0.20);
    scale.setTickLabelFormatter(new DecimalFormat("####"));

    plot.addScale(0, scale);

    StandardDialScale standarddialscale1 = new StandardDialScale(0D, 30D, -120D, -300D, 5D, 4);
    standarddialscale1.setTickRadius(0.5D);
    standarddialscale1.setTickLabelOffset(0.14999999999999999D);
    standarddialscale1.setTickLabelFont(new Font("Dialog", 0, 10));
    standarddialscale1.setMajorTickPaint(Color.RED);
    standarddialscale1.setMinorTickPaint(Color.RED);
    plot.addScale(1, standarddialscale1);

    plot.mapDatasetToScale(1, 1);

    JFreeChart jfreechart = new JFreeChart(plot);
    jfreechart.setTitle("ENGINE RPM & MANIFOLD PRESSURE");
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(400, 400));

    return chartpanel;
}

From source file:org.gephi.desktop.context.ContextPieChart.java

public ContextPieChart() {
    data = new DefaultPieDataset();
    final JFreeChart chart = ChartFactory.createPieChart("Employee Survey", data, false, false, false);
    chart.setTitle(new TextTitle());
    chart.setBackgroundPaint(null);//  www.jav  a 2 s.c  om
    chart.setPadding(new RectangleInsets(0, 0, 0, 0));
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setShadowPaint(null);
    plot.setSimpleLabels(true);
    plot.setLabelBackgroundPaint(null);
    plot.setLabelOutlineStroke(null);
    plot.setLabelShadowPaint(null);
    plot.setOutlineVisible(false);
    plot.setLabelFont(new java.awt.Font("Tahoma", 0, 10));
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelGap(0.5);
    plot.setCircular(true);
    plot.setInteriorGap(0);
    plot.setBackgroundPaint(null);
    plot.setBackgroundAlpha(1f);
    plot.setSectionPaint(NbBundle.getMessage(getClass(), "ContextPieChart.visible"), new Color(0x222222));
    plot.setSectionPaint(NbBundle.getMessage(getClass(), "ContextPieChart.notVisible"), new Color(0xDDDDDD));
    chartPanel = new ChartPanel(chart, 100, 100, 10, 10, 300, 300, true, false, false, false, false, false);
    ((FlowLayout) chartPanel.getLayout()).setHgap(0);
    ((FlowLayout) chartPanel.getLayout()).setVgap(0);
    chartPanel.setOpaque(false);
    chartPanel.setPopupMenu(null);
}

From source file:org.gephi.desktop.partition.PartitionPie.java

public void setup(Partition partition) {
    data = new DefaultPieDataset();
    for (Part p : partition.getParts()) {
        data.setValue(p.getDisplayName(), p.getPercentage());
    }/*from www.ja  v a 2 s  . c o m*/
    final JFreeChart chart = ChartFactory.createPieChart("test", data, false, false, false);
    chart.setTitle(new TextTitle());
    chart.setBackgroundPaint(null);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setShadowPaint(null);
    //plot.setSimpleLabels(true);
    plot.setLabelBackgroundPaint(Color.WHITE);
    plot.setLabelOutlineStroke(null);
    plot.setLabelShadowPaint(null);
    plot.setOutlineVisible(false);
    plot.setLabelFont(new java.awt.Font("Tahoma", 0, 10));
    plot.setLabelPaint(Color.BLACK);
    //plot.setLabelGap(0.05);
    plot.setCircular(true);
    plot.setBackgroundPaint(null);
    plot.setBackgroundAlpha(1f);
    for (Part p : partition.getParts()) {
        plot.setSectionPaint(p.getDisplayName(), p.getColor());
    }
    chartPanel = new ChartPanel(chart, true);
    chartPanel.setOpaque(false);
    chartPanel.setPopupMenu(null);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:com.googlecode.jchav.chart.MinMeanMaxChart.java

/**
 * Construct a new chart to display the given data.
 *
 * @param title The page id, used for the title of the chart.
 * @param data the data to plot.// w  w w.ja v  a  2s  .  com
 */
public MinMeanMaxChart(final String title, final SortedSet<Measurement> data) {
    // The renderer that does all the real work here:
    final MinMaxCategoryRenderer minMaxRenderer = new MinMaxCategoryRenderer();
    minMaxRenderer.setObjectIcon(new FilledCircle());

    // Munge the data into form JFreeChart can use:
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (Measurement m : data) {
        // This ordering gives max=red, min=green, mean=blue
        dataset.addValue(m.getMaximumTime(), "max", m.getBuildId().getBuildName());
        dataset.addValue(m.getAverageTime(), "mean", m.getBuildId().getBuildName());
        dataset.addValue(m.getMinimumTime(), "min", m.getBuildId().getBuildName());
    }

    // Create the plot area:
    final CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset);
    plot.setRenderer(minMaxRenderer);
    plot.setDomainAxis(new CategoryAxis("Build")); // TO DO: i18n
    plot.setRangeAxis(new NumberAxis("RT"));

    // Build labels running diagonally under the bars of the chart.
    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(false);

    // the legend here would be the "min", "max", "mean" strings used when created int category data set.
    boolean showLegend = true;

    // Render the chart:
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend);
    chart.setTitle(title);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderVisible(false);

    if (showLegend) {
        chart.getLegend().setBorder(BlockBorder.NONE);
    }

    this.setChart(chart);

}

From source file:it.marcoberri.mbmeteo.action.chart.GetLastRDial.java

/**
 * Processes requests for both HTTP/* ww w  . j av a  2  s. com*/
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    log.debug("start : " + this.getClass().getName());

    final HashMap<String, String> params = getParams(request.getParameterMap());
    final Integer dimy = Default.toInteger(params.get("dimy"), 600);
    final Integer dimx = Default.toInteger(params.get("dimx"), 800);

    Meteolog meteolog = ds.find(Meteolog.class).order("-time").limit(1).get();

    DefaultValueDataset dataset = new DefaultValueDataset(meteolog.getDayRainfall());

    // get data for diagrams
    DialPlot plot = new DialPlot();
    plot.setView(0.0, 0.0, 1.0, 1.0);
    plot.setDataset(0, dataset);

    GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
            new Color(170, 170, 220));

    DialBackground db = new DialBackground(gp);

    db.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    plot.setBackground(db);

    StandardDialScale scale = new StandardDialScale();
    scale.setLowerBound(0);
    scale.setUpperBound(50);
    scale.setTickLabelOffset(0.14);
    scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    plot.addScale(0, scale);

    DialPointer needle = new DialPointer.Pointer(0);

    plot.addLayer(needle);

    JFreeChart chart1 = new JFreeChart(plot);
    chart1.setTitle("Daily Rain mm");

    final File f = File.createTempFile("mbmeteo", ".jpg");
    ChartUtilities.saveChartAsJPEG(f, chart1, dimx, dimy);

    response.setContentType("image/jpeg");
    response.setHeader("Content-Length", "" + f.length());
    response.setHeader("Content-Disposition", "inline; filename=\"" + f.getName() + "\"");
    final OutputStream out = response.getOutputStream();
    final FileInputStream in = new FileInputStream(f.toString());
    final int size = in.available();
    final byte[] content = new byte[size];
    in.read(content);
    out.write(content);
    in.close();
    out.close();
}

From source file:it.marcoberri.mbmeteo.action.chart.GetLastTDial.java

/**
 * Processes requests for both HTTP//from w w w .  jav  a 2  s.  c o  m
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    log.debug("start : " + this.getClass().getName());

    final HashMap<String, String> params = getParams(request.getParameterMap());
    final Integer dimy = Default.toInteger(params.get("dimy"), 600);
    final Integer dimx = Default.toInteger(params.get("dimx"), 800);

    Meteolog meteolog = ds.find(Meteolog.class).order("-time").limit(1).get();

    DefaultValueDataset dataset = new DefaultValueDataset(meteolog.getOutdoorTemperature());

    // get data for diagrams
    DialPlot plot = new DialPlot();
    plot.setView(0.0, 0.0, 1.0, 1.0);
    plot.setDataset(0, dataset);

    GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
            new Color(170, 170, 220));

    DialBackground db = new DialBackground(gp);

    db.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    plot.setBackground(db);

    StandardDialScale scale = new StandardDialScale();
    scale.setLowerBound(-20);
    scale.setUpperBound(40);
    scale.setTickLabelOffset(0.14);
    scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    plot.addScale(0, scale);

    DialPointer needle = new DialPointer.Pointer(0);

    plot.addLayer(needle);

    JFreeChart chart1 = new JFreeChart(plot);
    chart1.setTitle("Temperature C");

    final File f = File.createTempFile("mbmeteo", ".jpg");
    ChartUtilities.saveChartAsJPEG(f, chart1, dimx, dimy);

    response.setContentType("image/jpeg");
    response.setHeader("Content-Length", "" + f.length());
    response.setHeader("Content-Disposition", "inline; filename=\"" + f.getName() + "\"");
    final OutputStream out = response.getOutputStream();
    final FileInputStream in = new FileInputStream(f.toString());
    final int size = in.available();
    final byte[] content = new byte[size];
    in.read(content);
    out.write(content);
    in.close();
    out.close();
}

From source file:it.marcoberri.mbmeteo.action.chart.GetLastUDial.java

/**
 * Processes requests for both HTTP/*www  .  j  a v  a 2 s  .co m*/
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    log.debug("start : " + this.getClass().getName());

    final HashMap<String, String> params = getParams(request.getParameterMap());
    final Integer dimy = Default.toInteger(params.get("dimy"), 600);
    final Integer dimx = Default.toInteger(params.get("dimx"), 800);

    Meteolog meteolog = ds.find(Meteolog.class).order("-time").limit(1).get();

    DefaultValueDataset dataset = new DefaultValueDataset(meteolog.getOutdoorHumidity());

    // get data for diagrams
    DialPlot plot = new DialPlot();
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    //plot.setView(0.1, 0.1, 0.9, 0.9);
    // plot.set
    plot.setDataset(0, dataset);

    GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
            new Color(170, 170, 220));

    DialBackground db = new DialBackground(gp);
    db.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    plot.setBackground(db);

    StandardDialScale scale = new StandardDialScale();
    scale.setLowerBound(0);
    scale.setUpperBound(100);
    scale.setTickLabelOffset(0.14);
    scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    plot.addScale(0, scale);
    plot.setInsets(RectangleInsets.ZERO_INSETS);

    DialPointer needle = new DialPointer.Pointer(0);

    plot.addLayer(needle);

    JFreeChart chart1 = new JFreeChart(plot);
    chart1.setTitle("Humidity %");

    final File f = File.createTempFile("mbmeteo", ".jpg");
    ChartUtilities.saveChartAsJPEG(f, chart1, dimx, dimy);

    response.setContentType("image/jpeg");
    response.setHeader("Content-Length", "" + f.length());
    response.setHeader("Content-Disposition", "inline; filename=\"" + f.getName() + "\"");
    final OutputStream out = response.getOutputStream();
    final FileInputStream in = new FileInputStream(f.toString());
    final int size = in.available();
    final byte[] content = new byte[size];
    in.read(content);
    out.write(content);
    in.close();
    out.close();
}

From source file:com.romraider.logger.ecu.ui.handler.dash.SmallDialGaugeStyle.java

protected JFreeChart buildChart() {
    DialPlot plot = new DialPlot();
    plot.setView(0.0, 0.0, 1.0, 1.0);//from w  ww  .j a v  a  2s.c  om
    plot.setDataset(0, current);
    plot.setDataset(1, max);
    plot.setDataset(2, min);
    DialFrame dialFrame = new StandardDialFrame();
    plot.setDialFrame(dialFrame);

    GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
            new Color(170, 170, 220));
    DialBackground db = new DialBackground(gp);
    db.setGradientPaintTransformer(new StandardGradientPaintTransformer(VERTICAL));
    plot.setBackground(db);

    unitsLabel.setFont(new Font(Font.DIALOG, BOLD, 14));
    unitsLabel.setRadius(0.7);
    unitsLabel.setLabel(loggerData.getSelectedConvertor().getUnits());
    plot.addLayer(unitsLabel);

    DecimalFormat format = new DecimalFormat(loggerData.getSelectedConvertor().getFormat());

    DialValueIndicator dvi = new DialValueIndicator(0);
    dvi.setNumberFormat(format);
    plot.addLayer(dvi);

    EcuDataConvertor convertor = loggerData.getSelectedConvertor();
    GaugeMinMax minMax = convertor.getGaugeMinMax();
    StandardDialScale scale = new StandardDialScale(minMax.min, minMax.max, 225.0, -270.0, minMax.step, 5);
    scale.setTickRadius(0.88);
    scale.setTickLabelOffset(0.15);
    scale.setTickLabelFont(new Font(Font.DIALOG, PLAIN, 12));
    scale.setTickLabelFormatter(format);
    plot.addScale(0, scale);
    plot.addScale(1, scale);
    plot.addScale(2, scale);

    StandardDialRange range = new StandardDialRange(rangeLimit(minMax, 0.75), minMax.max, RED);
    range.setInnerRadius(0.52);
    range.setOuterRadius(0.55);
    plot.addLayer(range);

    StandardDialRange range2 = new StandardDialRange(rangeLimit(minMax, 0.5), rangeLimit(minMax, 0.75), ORANGE);
    range2.setInnerRadius(0.52);
    range2.setOuterRadius(0.55);
    plot.addLayer(range2);

    StandardDialRange range3 = new StandardDialRange(minMax.min, rangeLimit(minMax, 0.5), GREEN);
    range3.setInnerRadius(0.52);
    range3.setOuterRadius(0.55);
    plot.addLayer(range3);

    DialPointer needleCurrent = new DialPointer.Pointer(0);
    plot.addLayer(needleCurrent);

    DialPointer needleMax = new DialPointer.Pin(1);
    needleMax.setRadius(0.84);
    ((DialPointer.Pin) needleMax).setPaint(RED);
    ((DialPointer.Pin) needleMax).setStroke(new BasicStroke(1.5F));
    plot.addLayer(needleMax);

    DialPointer needleMin = new DialPointer.Pin(2);
    needleMin.setRadius(0.84);
    ((DialPointer.Pin) needleMin).setPaint(BLUE);
    ((DialPointer.Pin) needleMin).setStroke(new BasicStroke(1.5F));
    plot.addLayer(needleMin);

    DialCap cap = new DialCap();
    cap.setRadius(0.10);
    plot.setCap(cap);

    JFreeChart chart = new JFreeChart(plot);
    chart.setTitle(loggerData.getName());

    return chart;
}

From source file:weka.core.ChartUtils.java

/**
 * Create a pie chart from summary data (i.e. a list of values and their
 * corresponding frequencies).//  www  .  j av a2 s. c  o m
 * 
 * @param values a list of values for the chart
 * @param freqs a list of corresponding frequencies
 * @param showLabels true if the chart will show labels
 * @param showLegend true if the chart will show a legend
 * @param additionalArgs optional arguments to the renderer (may be null)
 * @return a pie chart
 * @throws Exception if a problem occurs
 */
protected static JFreeChart getPieChartFromSummaryData(List<String> values, List<Double> freqs,
        boolean showLabels, boolean showLegend, List<String> additionalArgs) throws Exception {

    if (values.size() != freqs.size()) {
        throw new Exception("Number of bins should be equal to number of frequencies!");
    }

    String plotTitle = "Pie Chart";
    String userTitle = getOption(additionalArgs, "-title");
    plotTitle = (userTitle != null) ? userTitle : plotTitle;
    String xLabel = getOption(additionalArgs, "-x-label");
    xLabel = xLabel == null ? "" : xLabel;
    String yLabel = getOption(additionalArgs, "-y-label");
    yLabel = yLabel == null ? "" : yLabel;

    DefaultPieDataset dataset = new DefaultPieDataset();

    for (int i = 0; i < values.size(); i++) {
        String binLabel = values.get(i);
        Number freq = freqs.get(i);

        dataset.setValue(binLabel, freq);
    }

    JFreeChart chart = ChartFactory.createPieChart(plotTitle, // chart title
            dataset, // data
            showLegend, // include legend
            false, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    if (!showLabels) {
        plot.setLabelGenerator(null);
    } else {
        plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
        plot.setNoDataMessage("No data available");
        // plot.setCircular(false);
        plot.setLabelGap(0.02);
    }

    chart.setBackgroundPaint(java.awt.Color.white);
    chart.setTitle(new TextTitle(plotTitle, new Font("SansSerif", Font.BOLD, 12)));

    return chart;
}