Example usage for org.jfree.chart JFreeChart JFreeChart

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

Introduction

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

Prototype

public JFreeChart(Plot plot) 

Source Link

Document

Creates a new chart based on the supplied plot.

Usage

From source file:jgnash.ui.commodity.SecuritiesHistoryDialog.java

private void initComponents() {
    dateField = new DatePanel();
    closeField = new JFloatField();
    lowField = new JFloatField();
    highField = new JFloatField();
    securityCombo = new SecurityComboBox();
    volumeField = new JIntegerField();

    updateButton = new JButton(rb.getString("Button.UpdateOnline"),
            IconUtils.getIcon("/jgnash/resource/applications-internet.png"));

    deleteButton = new JButton(rb.getString("Button.Delete"));
    clearButton = new JButton(rb.getString("Button.Clear"));
    applyButton = new JButton(rb.getString("Button.Add"));
    closeButton = new JButton(rb.getString("Button.Close"));

    model = new HistoryModel();

    table = new HistoryTable();
    table.setModel(model);/*from   www . j ava  2 s. c o  m*/
    table.setPreferredScrollableViewportSize(new Dimension(150, 120));
    table.setCellSelectionEnabled(false);
    table.setColumnSelectionAllowed(false);
    table.setRowSelectionAllowed(true);
    table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setRowSorter(new TableRowSorter<>(model));
    table.setFillsViewportHeight(true);

    // create an empty chart for panel construction
    chartPanel = new ChartPanel(new JFreeChart(new XYPlot()));
    chartPanel.setPreferredSize(new Dimension(150, 90));

    applyButton.addActionListener(this);
    clearButton.addActionListener(this);
    deleteButton.addActionListener(this);
    updateButton.addActionListener(this);
    securityCombo.addActionListener(this);
    closeButton.addActionListener(this);
}

From source file:com.netsteadfast.greenstep.action.CommonMeterChartAction.java

private void fillChart(String title, float value, int lowerBound, int upperBound) throws Exception {
    DefaultValueDataset dataset = new DefaultValueDataset();

    dataset.setValue(value);//from   w w w. ja  v  a2  s.  c o  m

    DialPlot plot = new DialPlot();
    plot.setView(0.0d, 0.0d, 1.0d, 1.0d);
    plot.setDataset(0, dataset);

    StandardDialFrame frame = new StandardDialFrame();
    plot.setDialFrame(frame);
    DialBackground dialBackground = new DialBackground();
    dialBackground.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    plot.setBackground(dialBackground);
    DialTextAnnotation textAnnotation = new DialTextAnnotation(title);
    textAnnotation.setRadius(0.555555555555555555D);
    plot.addLayer(textAnnotation);

    DialValueIndicator valueIndicator = new DialValueIndicator(0);
    plot.addLayer(valueIndicator);

    StandardDialScale scale1 = new StandardDialScale();
    scale1.setLowerBound(lowerBound);
    scale1.setUpperBound(upperBound);
    scale1.setStartAngle(-140); // -120
    scale1.setExtent(-260D); // -300D 
    scale1.setTickRadius(0.88D);
    scale1.setTickLabelOffset(0.14999999999999999D);
    scale1.setTickLabelFont(new Font("", Font.TRUETYPE_FONT, 14));
    plot.addScale(0, scale1);

    StandardDialRange standarddialrange0 = new StandardDialRange(lowerBound, (upperBound * 0.6), Color.red);
    standarddialrange0.setInnerRadius(0.52000000000000002D);
    standarddialrange0.setOuterRadius(0.55000000000000004D);
    plot.addLayer(standarddialrange0);

    StandardDialRange standarddialrange1 = new StandardDialRange((upperBound * 0.6), (upperBound * 0.8),
            Color.orange);
    standarddialrange1.setInnerRadius(0.52000000000000002D);
    standarddialrange1.setOuterRadius(0.55000000000000004D);
    plot.addLayer(standarddialrange1);

    StandardDialRange standarddialrange2 = new StandardDialRange((upperBound * 0.8), upperBound, Color.green);
    standarddialrange2.setInnerRadius(0.52000000000000002D);
    standarddialrange2.setOuterRadius(0.55000000000000004D);
    plot.addLayer(standarddialrange2);

    Pointer pointer = new Pointer(0);
    pointer.setFillPaint(new Color(144, 196, 246));
    plot.addPointer(pointer);
    plot.mapDatasetToScale(0, 0);
    DialCap dialcap = new DialCap();
    dialcap.setRadius(0.0700000000000001D);
    plot.setCap(dialcap);

    this.chart = new JFreeChart(plot);
    //this.chart.setBackgroundPaint(new Color(234, 244, 253));
    this.chart.setBackgroundPaint(Color.white);
}

From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.Chromatogram1DHeatmapViewTopComponent.java

private Chromatogram1DHeatmapViewerPanel createPanel(ADataset2D<IChromatogram1D, IScan> ds) {
    XYPlot p = createPlot(ds);//ww w.  java2s.  c om
    final PaintScale ps = ((XYBlockRenderer) p.getRenderer()).getPaintScale();
    p.setDomainGridlinesVisible(false);
    p.setRangeGridlinesVisible(false);
    JFreeChart jfc = new JFreeChart(p);
    final ChartPanel cp = new ChartPanel(jfc, true);
    cp.setZoomFillPaint(new Color(192, 192, 192, 96));
    cp.setZoomOutlinePaint(new Color(220, 220, 220, 192));
    cp.setFillZoomRectangle(false);
    cp.getChart().getLegend().setVisible(true);
    Chromatogram1DHeatmapViewerPanel panel = new Chromatogram1DHeatmapViewerPanel(content, getLookup(), ds);
    if (panel.getBackgroundColor() == null) {
        panel.setBackgroundColor((Color) ps.getPaint(ps.getLowerBound()));
    }
    cp.addKeyListener(panel);
    cp.setFocusable(true);
    cp.setDisplayToolTips(true);
    cp.setDismissDelay(3000);
    cp.setInitialDelay(0);
    cp.setReshowDelay(0);
    cp.setVisible(true);
    cp.setRefreshBuffer(true);
    cp.setMouseWheelEnabled(true);
    //FIXME fix peak overlay
    //      if (project != null) {
    //         for (Peak1DContainer peaks : project.getPeaks(chromatogram)) {
    //            Peak1DHeatmapOverlay overlay = new Peak1DHeatmapOverlay(chromatogram, peaks.getName(), peaks.getDisplayName(), peaks.getShortDescription(), true, peaks);
    //            cp.addOverlay(overlay);
    //            content.add(overlay);
    //         }
    //      }
    panel.setChartPanel(cp);
    if (ps != null) {
        panel.setPaintScale(ps);
    }
    panel.setPlot(p);
    return panel;
}

From source file:org.rdv.viz.dial.DialPanel.java

/**
 * Creates the panel containing the dial.
 * //w  ww.j a  v  a 2  s  .  c o m
 * @return  the dial panel
 */
private JPanel createDialPanel() {
    plot = new DialPlot(dataset);

    plot.setDialFrame(new StandardDialFrame());

    engineeringFormat = new EngineeringFormat();
    engineeringFormatWithUnit = new EngineeringFormat();

    dialValueIndicator = new DialValueIndicator();
    dialValueIndicator.setOutlinePaint(Color.black);
    dialValueIndicator.setRadius(0.7);
    dialValueIndicator.setVisible(false);
    dialValueIndicator.setNumberFormat(engineeringFormatWithUnit);
    plot.addLayer(dialValueIndicator);

    dialTextAnnotation = new DialTextAnnotation("");
    dialTextAnnotation.setRadius(0.8);
    plot.addLayer(dialTextAnnotation);

    DialPointer dialPointer = new DialPointer.Pointer();
    dialPointer.setRadius(0.9);
    plot.addPointer(dialPointer);

    plot.setCap(new DialCap());

    dialScale = new BoundedDialScale();
    dialScale.setStartAngle(-120);
    dialScale.setExtent(-300);
    dialScale.setMinorTickCount(5);
    dialScale.setTickLabelFormatter(engineeringFormat);
    dialScale.setTickRadius(0.9);

    JFreeChart chart = new JFreeChart(plot);
    chart.removeLegend();

    return new ChartPanel(chart);
}

From source file:it.eng.spagobi.engines.kpi.bo.charttypes.trendcharts.LineChart.java

public JFreeChart createChart() {

    logger.debug("IN");
    CategoryPlot plot = new CategoryPlot();
    IMessageBuilder msgBuilder = MessageBuilderFactory.getMessageBuilder();
    String rangeAxisName = msgBuilder.getMessage("sbi.kpi.rangeAxisName");
    NumberAxis rangeAxis = new NumberAxis(rangeAxisName);
    rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12));
    Color colorLabel = Color.decode("#000000");
    rangeAxis.setLabelPaint(colorLabel);
    rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10));
    rangeAxis.setTickLabelPaint(colorLabel);
    plot.setRangeAxis(rangeAxis);/*from   ww w  .ja  va 2s  .  c  o  m*/

    CategoryAxis domainAxis = new CategoryAxis();
    domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10));
    domainAxis.setLabelPaint(colorLabel);
    domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10));
    domainAxis.setTickLabelPaint(colorLabel);
    plot.setDomainAxis(domainAxis);

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

    //I create a line renderer 
    MyStandardCategoryItemLabelGenerator generator = null;

    LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer();
    lineRenderer.setShapesFilled(true);
    lineRenderer.setBaseItemLabelGenerator(generator);
    lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12));
    lineRenderer.setBaseItemLabelPaint(colorLabel);
    lineRenderer.setBaseItemLabelsVisible(true);

    DefaultCategoryDataset datasetLine = (DefaultCategoryDataset) datasetMap.getDatasets().get("line");

    for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) {
        String serName = (String) iterator.next();
        String labelName = "";
        int index = -1;
        index = datasetLine.getRowIndex(serName);

        Color color = Color.decode("#990200");
        lineRenderer.setSeriesPaint(index, color);
    }

    plot.setDataset(0, datasetLine);
    plot.setRenderer(0, lineRenderer);

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    JFreeChart chart = new JFreeChart(plot);
    logger.debug("Chart created");
    TextTitle title = new TextTitle(name, new Font("Arial", Font.BOLD, 16), Color.decode("#990200"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.setTitle(title);
    TextTitle subTitle = new TextTitle(subName, new Font("Arial", Font.PLAIN, 12), Color.decode("#000000"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.addSubtitle(subTitle);
    TextTitle subTitle2 = new TextTitle(subName, new Font("Arial", Font.PLAIN, 8), Color.decode("#FFFFFF"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.addSubtitle(subTitle2);
    chart.removeLegend();

    chart.setBackgroundPaint(Color.white);
    logger.debug("OUT");
    return chart;
}

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

public void init(ChartDefinitionVO chartDefinition) {

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

    resetPopupMenu();//  w  w  w  . j a  va2s.  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:com.bdb.weather.display.day.DayXYPlotPane.java

private void createChartElements() {
    ////from w w w. j a va  2 s .com
    // Set up the Domain Axis (X)
    //
    plot = new XYPlot();
    dateAxis = new DateAxis("Time");
    dateAxis.setAutoRange(false);
    dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1, new SimpleDateFormat("h a")));
    dateAxis.setVerticalTickLabels(true);
    plot.setDomainAxis(dateAxis);
    plot.setRangeAxis(leftAxis);
    plot.setDataset(0, datasetLeft);
    if (rightAxis != null) {
        plot.setRangeAxis(1, rightAxis);
        plot.mapDatasetToRangeAxis(1, 1);
        plot.setDataset(1, datasetRight);
    }
    plot.setNoDataMessage("There is no data for the specified day");

    //
    // Set up the renderer to generate tool tips, not show shapes
    //
    XYLineAndShapeRenderer renderer = new XYLine3DRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    //renderer.setDefaultEntityRadius(1);
    plot.setRenderer(0, renderer);

    renderer = new XYLine3DRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    //renderer.setDefaultEntityRadius(1);
    plot.setRenderer(1, renderer);

    //
    // Setup the cross hairs that are displayed when the user clicks on the plot
    //
    plot.setRangeCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(true);
    plot.setDomainCrosshairVisible(true);

    //
    // Create the chart that contains the plot and the panel that contains the chart
    //
    chart = new JFreeChart(plot);
    ChartFactory.getChartTheme().apply(chart);
    chartViewer = new ChartViewer(chart);

    chartViewer.setMaxHeight(500);
    chartViewer.setMaxWidth(800);

    //
    // Add the Day/Night indicator option to the chart panels context menu
    //
    ContextMenu menu = chartViewer.getContextMenu();

    displayMenu = new Menu("Display");

    dayNightItem = new CheckMenuItem("Day/Night Indicators");
    dayNightItem.setSelected(true);
    displayMenu.getItems().add(dayNightItem);
    dayNightItem.setOnAction(this);
    menu.getItems().add(displayMenu);
}

From source file:com.xilinx.kintex7.PowerDial.java

public void createDial() {
    plot = new MeterPlot();
    dset = new DefaultValueDataset(0);
    plot.setUnits("Watts");
    plot.setRange(new Range(1, 10));
    plot.addInterval(new MeterInterval("Acceptable", new Range(1.0, 6.0), Color.lightGray,
            new BasicStroke(2.0f), Color.GREEN));
    plot.addInterval(new MeterInterval("Warning", new Range(6.0, 8.0), Color.lightGray, new BasicStroke(2.0f),
            Color.YELLOW));/*from w ww .  j av  a 2  s  . co  m*/
    plot.addInterval(new MeterInterval("Dangerous", new Range(8.0, 10.0), Color.lightGray,
            new BasicStroke(2.0f), Color.RED));

    //sets different marks
    for (int i = 0; i < 10; i += 1) {
        if (i == 0)
            plot.addInterval(
                    new MeterInterval("", new Range(1, 1), Color.lightGray, new BasicStroke(2.0f), null));
        else
            plot.addInterval(
                    new MeterInterval("", new Range(i, i), Color.lightGray, new BasicStroke(2.0f), null));
    }
    plot.setNeedlePaint(Color.darkGray);
    plot.setDialBackgroundPaint(Color.white);
    plot.setDialOutlinePaint(Color.gray);
    plot.setDialShape(DialShape.PIE);
    plot.setMeterAngle(180);
    plot.setTickLabelsVisible(true);
    plot.setTickLabelFont(new Font("Dialog", Font.BOLD, 10));
    plot.setTickLabelPaint(Color.DARK_GRAY);
    plot.setTickSize(10.0);
    plot.setTickPaint(Color.lightGray);
    plot.setValuePaint(Color.BLACK);
    plot.setDataset(dset);

    LegendItemCollection legendItemsOld = plot.getLegendItems();
    final LegendItemCollection legendItemsNew = new LegendItemCollection();

    for (int i = 0; i < 3; i++) {
        LegendItem item = legendItemsOld.get(i);
        item.setLabelPaint(Color.WHITE);
        legendItemsNew.add(item);
    }

    LegendItemSource source = new LegendItemSource() {
        LegendItemCollection lic = new LegendItemCollection();
        {
            lic.addAll(legendItemsNew);
        }

        @Override
        public LegendItemCollection getLegendItems() {
            return lic;
        }
    };

    chart = new JFreeChart(plot);
    chart.addLegend(new LegendTitle(source));
    chart.removeLegend();
    chart.setTitle("");
    //chart.setBackgroundPaint(new GradientPaint(0,0,new Color(139,137,137),0,height,Color.BLUE ));
    //
    chart.getTitle().setPaint(Color.white);
    plot.setValueFont(new Font("Dialog", Font.BOLD, 14));
    //chartpanel = new ChartPanel(chart);
}

From source file:edu.ucla.stat.SOCR.chart.SuperValueChart.java

/**
 * Creates a chart.// w w  w .j ava2 s  .co m
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(ValueDataset dataset) {
    // create the chart...
    // OPTIONAL CUSTOMISATION COMPLETED.
    CompassPlot plot = new CompassPlot(dataset);
    plot.setSeriesNeedle(7);
    plot.setSeriesPaint(0, Color.red);
    plot.setSeriesOutlinePaint(0, Color.red);
    plot.setRoseHighlightPaint(Color.CYAN);
    JFreeChart chart = new JFreeChart(plot);

    return chart;

}

From source file:net.sf.maltcms.chromaui.foldChangeViewer.ui.panel.FoldChangeViewPanel.java

public void setPlot(final XYPlot plot) {
    removeAxisListener();//from   w  w w  .j av a2 s .co m
    ADataset1D<?, FoldChangeElement> dataset = null;
    if (plot.getDataset() instanceof ADataset1D) {
        dataset = (ADataset1D<?, FoldChangeElement>) plot.getDataset();
    } else {
        throw new IllegalArgumentException("Requires a plot with ADataset1D!");
    }
    this.plot = plot;
    if (selectionOverlay != null) {
        content.remove(selectionOverlay);
        selectionOverlay = null;
    }
    if (selectionOverlay == null) {
        selectionOverlay = new SelectionOverlay(Color.BLUE, Color.RED, 1.75f, 1.75f, 0.66f);
        chartPanel.addOverlay(selectionOverlay);
        selectionOverlay.addChangeListener(chartPanel);
        content.add(selectionOverlay);
    } else {
        for (ISelection selection : selectionOverlay.getMouseClickSelection()) {
            selection.setDataset(dataset);
        }

        ISelection selection = selectionOverlay.getMouseHoverSelection();
        if (selection != null) {
            selection.setDataset(dataset);
        }
    }
    if (selectionHandler == null) {
        selectionHandler = new InstanceContentSelectionHandler(this.content, selectionOverlay,
                InstanceContentSelectionHandler.Mode.ON_CLICK, dataset, 1);
    } else {
        selectionHandler.setDataset(dataset);
    }
    if (mouseSelectionHandler == null) {
        mouseSelectionHandler = new XYMouseSelectionHandler<FoldChangeElement>(dataset);
        mouseSelectionHandler.addSelectionChangeListener(selectionOverlay);
        mouseSelectionHandler.addSelectionChangeListener(selectionHandler);
        chartPanel.addChartMouseListener(mouseSelectionHandler);
    } else {
        mouseSelectionHandler.setDataset(dataset);
    }

    AxisChangeListener listener = selectionOverlay;
    ValueAxis domain = this.plot.getDomainAxis();
    ValueAxis range = this.plot.getRangeAxis();
    if (domain != null) {
        domain.addChangeListener(listener);
    }
    if (range != null) {
        range.addChangeListener(listener);
    }

    if (dataset == null || dataset.getSeriesCount() == 0) {
        this.plot.setNoDataMessage("<No Data Available>");
    } else {
        this.plot.setNoDataMessage("Loading Data...");
    }
    this.plot.setDomainPannable(true);
    this.plot.setRangePannable(true);
    chart = new JFreeChart(this.plot);
    chartPanel.setChart(chart);
    XYItemRenderer r = this.plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        ((XYLineAndShapeRenderer) r).setDrawSeriesLineAsPath(false);
        ((XYLineAndShapeRenderer) r).setBaseShapesVisible(true);
        ((XYLineAndShapeRenderer) r).setBaseShapesFilled(true);
    } else if (r instanceof XYAreaRenderer) {
        ((XYAreaRenderer) r).setOutline(true);
    }
    ChartCustomizer.setSeriesColors(this.plot, 0.8f);
    ChartCustomizer.setSeriesStrokes(this.plot, 2.0f);
    dmkl = new DomainMarkerKeyListener(this.plot);
    dmkl.setPlot(this.plot);
    chartPanel.addKeyListener(dmkl);
    addAxisListener();
    //add available chart overlays
    List<Overlay> overlays = new ArrayList<Overlay>(getLookup().lookupAll(Overlay.class));
    Collections.sort(overlays, new Comparator<Overlay>() {

        @Override
        public int compare(Overlay o1, Overlay o2) {
            if (o1 instanceof ChartOverlay && o2 instanceof ChartOverlay) {
                ChartOverlay co1 = (ChartOverlay) o1;
                ChartOverlay co2 = (ChartOverlay) o2;
                return Integer.compare(co1.getLayerPosition(), co2.getLayerPosition());
            } else {
                return 0;
            }
        }
    });
    for (Overlay overlay : overlays) {
        if (!(overlay instanceof SelectionOverlay)) {
            chartPanel.removeOverlay(overlay);
            if (overlay instanceof AxisChangeListener) {
                AxisChangeListener axisChangeListener = (AxisChangeListener) overlay;
                if (domain != null) {
                    domain.addChangeListener(axisChangeListener);
                }
                if (range != null) {
                    range.addChangeListener(axisChangeListener);
                }
            }
            if (overlay instanceof ISelectionChangeListener) {
                ISelectionChangeListener isl = (ISelectionChangeListener) overlay;
                mouseSelectionHandler.addSelectionChangeListener(isl);
                mouseSelectionHandler.addSelectionChangeListener(selectionHandler);
                selectionOverlay.addChangeListener(chartPanel);
            }
            chartPanel.addOverlay(overlay);
            overlay.addChangeListener(chartPanel);
        }
    }
    //add selection overlay last
    chartPanel.removeOverlay(selectionOverlay);
    chartPanel.addOverlay(selectionOverlay);
}