Example usage for org.jfree.chart JFreeChart getTitle

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

Introduction

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

Prototype

public TextTitle getTitle() 

Source Link

Document

Returns the main chart title.

Usage

From source file:userInterface.doctor.ReportingPatientVitalHistJPanel.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:

    TimeSeriesCollection ts = new TimeSeriesCollection();
    TimeSeries object1 = new TimeSeries("RespiratoryRate");
    TimeSeries object2 = new TimeSeries("HeartRate");
    TimeSeries object3 = new TimeSeries("SystolicPressure");
    TimeSeries object4 = new TimeSeries("Weight");

    for (VitalSignInfo vitalsign : patient.getVitalHistory().getVitalHistory()) {

        int rr = (int) vitalsign.getRespRate();
        int hr = (int) vitalsign.getHeartRate();
        int sp = (int) vitalsign.getSystolicBP();
        int wt = (int) vitalsign.getWeight();

        try {/*from   ww w .jav  a 2s.c o  m*/
            object1.add(new Second(vitalsign.getTimeStamp()), rr);
            object2.add(new Second(vitalsign.getTimeStamp()), hr);
            object3.add(new Second(vitalsign.getTimeStamp()), sp);
            object4.add(new Second(vitalsign.getTimeStamp()), wt);
        } catch (ParseException ex) {
            //  Logger.getLogger(ReportingPatientVitalHistJPanel.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    ts.addSeries(object1);
    ts.addSeries(object2);
    ts.addSeries(object3);
    ts.addSeries(object4);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Vital Signs", "TimeStamp", "Vital Sign Values", ts,
            true, true, true);

    chart.setBackgroundPaint(Color.GRAY);
    chart.getTitle().setPaint(Color.red);

    XYPlot xy = (XYPlot) chart.getPlot();
    DateAxis da = (DateAxis) xy.getDomainAxis();
    da.setDateFormatOverride(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"));

    ChartFrame frame = new ChartFrame("Chart for Vital Signs", chart);
    frame.setVisible(true);
    frame.setSize(450, 350);

}

From source file:net.bioclipse.plugins.views.ChartView.java

/**
 * Displays a chart in ChartView and sets up its mouse listener
 * @param chart/*from   w w w.j a v a 2 s  .c  o m*/
 */
public void display(JFreeChart chart) {
    final ChartDescriptor cd = ChartUtils.getChartDescriptor(chart);

    JFreeChartTab chartTab = new JFreeChartTab(tabFolder, SWT.CLOSE);
    chartTab.setText(chart.getTitle().getText());
    chartTab.setChart(chart);

    Composite composite = new Composite(tabFolder, SWT.EMBEDDED | SWT.NO_BACKGROUND);
    chartTab.setControl(composite);

    frame = SWT_AWT.new_Frame(composite);

    final ChartPanel chartPanel = new ChartPanel(chart);

    //Since methods are called on a java.awt.Frame it has to be called on the swing/awt thread 
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            frame.removeAll();
            frame.add(chartPanel);
            frame.setVisible(true);

            if (cd.getPlotType() == ChartConstants.SCATTER_PLOT) {
                //Listens for mouseclicks on points
                XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
                plot.setRenderer(new ScatterPlotRenderer(false, true));

                if (ChartView.IS_MACOS) {
                    frame.addMouseListener(pmh);
                    frame.addMouseMotionListener(pmh);
                } else {
                    chartPanel.addMouseListener(pmh);
                    frame.addMouseMotionListener(pmh);
                }
            }
        }
    });
    tabFolder.setSelection(chartTab);
    tabFolder.forceFocus();
    tabFolder.layout();
    ChartUtils.setActiveChart(chart);

    //Make sure actions are enabled when the chart has been created
    saveImageActionJPG.setEnabled(true);
    saveImageActionPNG.setEnabled(true);
    saveImageActionSVG.setEnabled(true);
}

From source file:userInterface.doctor.ReportingPatientVitalHistJPanel.java

private void weightJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_weightJButtonActionPerformed
    // TODO add your handling code here:
    // TODO add your handling code here:
    DefaultTableModel dtm = (DefaultTableModel) vitalJTable.getModel();
    DefaultCategoryDataset weightbarChartSet = new DefaultCategoryDataset();
    for (VitalSignInfo vhl : patient.getVitalHistory().getVitalHistory()) {
        weightbarChartSet.setValue(vhl.getWeight(), "Weight", vhl.getCurrentTime());
    }//from   ww  w  .ja va  2 s. c  o m
    JFreeChart respChart = ChartFactory.createBarChart3D("Vital History", "Time", "Weight", weightbarChartSet,
            PlotOrientation.VERTICAL, false, true, false);
    respChart.setBackgroundPaint(Color.WHITE);
    respChart.getTitle().setPaint(Color.BLACK);
    CategoryPlot p = respChart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.BLUE);
    ChartFrame frame = new ChartFrame("Bar Chart for Vital Information: Weight", respChart);
    frame.setVisible(true);
    frame.setSize(450, 350);
}

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);/*w w  w  . j  a va 2  s  .  com*/
    title.setPaint(Color.darkGray);
    XYPlot plot = chart.getXYPlot();
    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:com.manydesigns.portofino.chart.Chart1DGenerator.java

public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    java.util.List<Object[]> result;
    String query = chartDefinition.getQuery();
    logger.info(query);//from w  w w.jav a  2s . c  o m
    Session session = persistence.getSession(chartDefinition.getDatabase());
    result = QueryUtils.runSql(session, query);
    for (Object[] current : result) {
        ComparableWrapper key = new ComparableWrapper((Comparable) current[0]);
        dataset.setValue(key, (Number) current[1]);
        if (current.length > 2) {
            key.setLabel(current[2].toString());
        }
    }

    JFreeChart chart = createChart(chartDefinition, dataset);

    chart.setAntiAlias(isAntiAlias());

    // impostiamo il bordo invisibile
    // eventualmente e' il css a fornirne uno
    // eventualmente e' il css a fornirne uno
    chart.setBorderVisible(isBorderVisible());

    // impostiamo il titolo
    TextTitle title = chart.getTitle();
    title.setFont(titleFont);
    title.setMargin(10.0, 0.0, 0.0, 0.0);

    // ottieni il Plot
    PiePlot plot = (PiePlot) chart.getPlot();

    String urlExpression = chartDefinition.getUrlExpression();
    if (!StringUtils.isBlank(urlExpression)) {
        PieURLGenerator urlGenerator = new ChartPieUrlGenerator(urlExpression);
        plot.setURLGenerator(urlGenerator);
    } else {
        plot.setURLGenerator(null);
    }

    // il plot ha sfondo e bordo trasparente
    // (quindi si vede il colore del chart)
    plot.setBackgroundPaint(transparentColor);
    plot.setOutlinePaint(transparentColor);

    // Modifico il toolTip
    // hongliangpan add
    // :?{0}  {1}  {2} ? ,???
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})",
            NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
    // {0}={1}({2})
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));
    // ?(0.0-1.0)
    // plot.setForegroundAlpha(1.0f);
    // imposta la distanza delle etichette dal plot
    plot.setLabelGap(0.03);
    // plot.setLabelGenerator(new MyPieSectionLabelGenerator());

    // imposta il messaggio se non ci sono dati
    plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available"));

    plot.setCircular(true);

    plot.setBaseSectionOutlinePaint(Color.BLACK);

    DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier());
    plot.setDrawingSupplier(supplier);
    // ?
    plot.setForegroundAlpha(1.0f);
    // impostiamo il titolo della legenda
    String legendString = chartDefinition.getLegend();
    Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM,
            HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0));
    subtitle.setMargin(0, 0, 5, 0);
    chart.addSubtitle(subtitle);

    // impostiamo la legenda
    LegendTitle legend = chart.getLegend();
    legend.setBorder(0, 0, 0, 0);
    legend.setItemFont(legendItemFont);
    int legendMargin = 10;
    legend.setMargin(0.0, legendMargin, legendMargin, legendMargin);
    legend.setBackgroundPaint(transparentColor);

    // impostiamo un gradiente orizzontale
    Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, getHeight(), Color.WHITE);
    chart.setBackgroundPaint(chartBgPaint);
    return chart;
}

From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java

protected void maybeAdjustTitleFontSize(JFreeChart chart, Graphics2D g, int width) {
    // if the chart has no title, do nothing.
    if (chart.getTitle() == null)
        return;// w  w w.  j  a v  a 2 s.  co m
    String title = chart.getTitle().getText();
    if (title == null || title.length() == 0)
        return;

    // compute the width needed to draw the title.
    Font f = chart.getTitle().getFont();
    Font sf = getFontSizeToFit(g, f, title, (int) (width * 0.85));
    if (f != sf)
        chart.getTitle().setFont(sf);
}

From source file:org.esa.beam.pixex.output.ScatterPlotDecoratingStrategyTest.java

@Test
public void testCreateScatterPlotsForSingleProduct() throws Exception {
    Measurement[] productMeasurements = new Measurement[] {
            new Measurement(0, "someName", PRODUCT_ID_0, -1, -1, null, null, new Object[] { 7, 4.0 }, true),
            new Measurement(1, "someOtherName", PRODUCT_ID_0, -1, -1, null, null, new Object[] { 9, 3.0 },
                    true) };//  w w  w  .j av  a 2 s.  co m

    assertTrue(strategy.plotMaps.isEmpty());

    final Product product = createProduct("newProduct");
    strategy.writeHeader(null, product);
    strategy.writeMeasurements(product, null, productMeasurements);

    assertEquals(1, strategy.plotMaps.size());
    final int scatterPlotCountForProduct = strategy.plotMaps.get(PRODUCT_ID_0).size();
    assertEquals(2, scatterPlotCountForProduct);

    JFreeChart sstPlot = strategy.plotMaps.get(PRODUCT_ID_0).get(variableCombinations[0]);
    assertEquals("original_sst", sstPlot.getXYPlot().getDomainAxis().getLabel());
    assertEquals("product_sst", sstPlot.getXYPlot().getRangeAxis().getLabel());
    assertEquals("Scatter plot of 'original_sst' and 'product_sst' for product 'newProduct'",
            sstPlot.getTitle().getText());

    XYDataset sstDataset = sstPlot.getXYPlot().getDataset();
    assertNotNull(sstDataset);
    assertEquals(1, sstDataset.getSeriesCount());

    int seriesIndex = 0;

    assertEquals(2, sstDataset.getItemCount(0));

    assertEquals(6, sstDataset.getX(seriesIndex, 0));
    assertEquals(7, sstDataset.getY(seriesIndex, 0));

    assertEquals(8, sstDataset.getX(seriesIndex, 1));
    assertEquals(9, sstDataset.getY(seriesIndex, 1));

    JFreeChart tsmPlot = strategy.plotMaps.get(PRODUCT_ID_0).get(variableCombinations[1]);
    assertEquals("original_tsm", tsmPlot.getXYPlot().getDomainAxis().getLabel());
    assertEquals("product_tsm", tsmPlot.getXYPlot().getRangeAxis().getLabel());
    assertEquals("Scatter plot of 'original_tsm' and 'product_tsm' for product 'newProduct'",
            tsmPlot.getTitle().getText());

    XYDataset tsmDataset = tsmPlot.getXYPlot().getDataset();
    assertNotNull(tsmDataset);
    assertEquals(1, tsmDataset.getSeriesCount());

    assertEquals(2, tsmDataset.getItemCount(0));

    assertEquals(2.0, tsmDataset.getX(seriesIndex, 0));
    assertEquals(3.0, tsmDataset.getY(seriesIndex, 0));

    assertEquals(3.0, tsmDataset.getX(seriesIndex, 1));
    assertEquals(4.0, tsmDataset.getY(seriesIndex, 1));
}

From source file:loansystem.visual.panel.StartPage.java

private void dibujarGrafico(DefaultCategoryDataset datos, int tipoGrafico, String titulo, String ejeX,
        String ejeY, PlotOrientation orientacion, JPanel contenedor) {
    JFreeChart grafica = null;

    switch (tipoGrafico) {
    case BAR:/*from   w w w  .  j a v a  2  s . c  om*/
        grafica = ChartFactory.createBarChart3D(titulo, ejeX, ejeY, datos, orientacion, true, true, false);
        break;
    case LINE:

        break;

    case PIE:

        break;
    }

    grafica.getTitle().setPaint(Color.black);

    CategoryPlot p = grafica.getCategoryPlot();
    p.setRangeGridlinePaint(Color.black);

    CategoryItemRenderer renderer = ((CategoryPlot) grafica.getPlot()).getRenderer();
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER);
    renderer.setBasePositiveItemLabelPosition(position);

    int style = Font.BOLD;
    Font font = new Font("Tahoma", style, 12);
    renderer.setItemLabelFont(font);

    ChartPanel panel = new ChartPanel(grafica);
    contenedor.add(panel);
    contenedor.revalidate();
    contenedor.repaint();
}

From source file:userinterface.CountryNetworkAdminRole.CountryReportsJPanel.java

private JFreeChart createDonorsByStateReportsChart(CategoryDataset dataset) {
    JFreeChart barChart = ChartFactory.createBarChart("No Of Registered Donors by State", "State",
            " No Of Registered Donors", dataset, PlotOrientation.VERTICAL, true, true, false);
    barChart.setBackgroundPaint(Color.white);
    // Set the background color of the chart
    barChart.getTitle().setPaint(Color.DARK_GRAY);
    barChart.setBorderVisible(true);/*  w  ww  .ja  va2 s . c o  m*/
    // Adjust the color of the title
    CategoryPlot plot = barChart.getCategoryPlot();
    plot.getRangeAxis().setLowerBound(0.0);
    // Get the Plot object for a bar graph
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.blue);
    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.decode("#00008B"));
    //return chart;
    return barChart;
}

From source file:org.talend.dataprofiler.chart.ChartDecorator.java

/**
 * DOC bZhou Comment method "decorateXYPlot".
 * //from   w ww  .ja va  2s  . c  o  m
 * @param chart
 */
private static void decorateXYPlot(JFreeChart chart) {

    Font font = null;
    XYPlot plot = chart.getXYPlot();
    XYItemRenderer render = plot.getRenderer();
    ValueAxis domainAxis = plot.getDomainAxis();
    ValueAxis valueAxis = plot.getRangeAxis();

    font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE);//$NON-NLS-1$

    render.setBaseItemLabelFont(font);

    font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$
    domainAxis.setLabelFont(font);

    font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$
    valueAxis.setLabelFont(font);

    font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE);//$NON-NLS-1$
    domainAxis.setTickLabelFont(font);
    valueAxis.setTickLabelFont(font);

    setLegendFont(chart);

    font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);//$NON-NLS-1$
    TextTitle title = chart.getTitle();
    if (title != null) {
        title.setFont(font);
    }

    font = null;
}