Search in sources :

Example 56 with XYPlot

use of org.jfree.chart.plot.XYPlot in project jgnash by ccavanaugh.

the class SecuritiesHistoryDialog method createChart.

private static JFreeChart createChart(final SecurityNode node) {
    Objects.requireNonNull(node);
    final List<SecurityHistoryNode> hNodes = node.getHistoryNodes();
    final Date max = DateUtils.asDate(hNodes.get(hNodes.size() - 1).getLocalDate());
    final Date min = DateUtils.asDate(hNodes.get(0).getLocalDate());
    final DateAxis timeAxis = new DateAxis(null);
    timeAxis.setVisible(false);
    timeAxis.setAutoRange(false);
    timeAxis.setRange(min, max);
    final NumberAxis valueAxis = new NumberAxis(null);
    valueAxis.setAutoRangeIncludesZero(false);
    valueAxis.setVisible(false);
    final XYAreaRenderer renderer = new XYAreaRenderer();
    renderer.setBaseToolTipGenerator(new SecurityItemLabelGenerator(node));
    renderer.setOutline(true);
    renderer.setSeriesPaint(0, new Color(225, 247, 223));
    final XYPlot plot = new XYPlot(null, timeAxis, valueAxis, renderer);
    final List<List<SecurityHistoryNode>> groups = node.getHistoryNodeGroupsBySplits();
    for (int i = 0; i < groups.size(); i++) {
        int size = groups.get(i).size();
        Date[] date = new Date[size];
        double[] high = new double[size];
        double[] low = new double[size];
        double[] open = new double[size];
        double[] close = new double[size];
        double[] volume = new double[size];
        for (int j = 0; j < size; j++) {
            final SecurityHistoryNode hNode = groups.get(i).get(j);
            date[j] = DateUtils.asDate(hNode.getLocalDate());
            high[j] = hNode.getAdjustedHigh().doubleValue();
            low[j] = hNode.getAdjustedLow().doubleValue();
            open[j] = hNode.getAdjustedPrice().doubleValue();
            close[j] = hNode.getAdjustedPrice().doubleValue();
            volume[j] = hNode.getVolume();
        }
        final AbstractXYDataset data = new DefaultHighLowDataset(node.getDescription() + i, date, high, low, open, close, volume);
        plot.setDataset(i, data);
    }
    plot.setInsets(new RectangleInsets(1, 1, 1, 1));
    final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(null);
    return chart;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) AbstractXYDataset(org.jfree.data.xy.AbstractXYDataset) DefaultHighLowDataset(org.jfree.data.xy.DefaultHighLowDataset) Color(java.awt.Color) Date(java.util.Date) LocalDate(java.time.LocalDate) JFreeChart(org.jfree.chart.JFreeChart) XYAreaRenderer(org.jfree.chart.renderer.xy.XYAreaRenderer) XYPlot(org.jfree.chart.plot.XYPlot) RectangleInsets(org.jfree.ui.RectangleInsets) SecurityHistoryNode(jgnash.engine.SecurityHistoryNode) List(java.util.List)

Example 57 with XYPlot

use of org.jfree.chart.plot.XYPlot in project jgnash by ccavanaugh.

the class SecuritiesHistoryDialog method initComponents.

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);
    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);
}
Also used : JIntegerField(jgnash.ui.components.JIntegerField) ChartPanel(org.jfree.chart.ChartPanel) JFloatField(jgnash.ui.components.JFloatField) XYPlot(org.jfree.chart.plot.XYPlot) DatePanel(jgnash.ui.components.DatePanel) JButton(javax.swing.JButton) SecurityComboBox(jgnash.ui.components.SecurityComboBox) Dimension(java.awt.Dimension) JFreeChart(org.jfree.chart.JFreeChart)

Example 58 with XYPlot

use of org.jfree.chart.plot.XYPlot in project processdash by dtuma.

the class XYChart method addTrendLine.

private void addTrendLine(JFreeChart chart, XYDataset dataset) {
    XYPlot plot = chart.getXYPlot();
    plot.setDataset(1, dataset);
    plot.setRenderer(1, new StandardXYItemRenderer(StandardXYItemRenderer.LINES));
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer)

Aggregations

XYPlot (org.jfree.chart.plot.XYPlot)58 JFreeChart (org.jfree.chart.JFreeChart)35 Color (java.awt.Color)19 DateAxis (org.jfree.chart.axis.DateAxis)18 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)14 CommonUITool.trimPaintColor (com.cubrid.common.ui.spi.util.CommonUITool.trimPaintColor)11 Map (java.util.Map)11 NumberAxis (org.jfree.chart.axis.NumberAxis)10 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)10 SimpleDateFormat (java.text.SimpleDateFormat)9 RectangleInsets (org.jfree.ui.RectangleInsets)9 TreeMap (java.util.TreeMap)8 XYDataset (org.jfree.data.xy.XYDataset)8 Font (java.awt.Font)7 ValueAxis (org.jfree.chart.axis.ValueAxis)7 ChartCompositePart (com.cubrid.cubridmanager.ui.monitoring.editor.internal.ChartCompositePart)6 ChartSettingDlg (com.cubrid.cubridmanager.ui.monitoring.editor.internal.ChartSettingDlg)6 HistoryComposite (com.cubrid.cubridmanager.ui.monitoring.editor.internal.HistoryComposite)6 ShowSetting (com.cubrid.cubridmanager.ui.monitoring.editor.internal.ShowSetting)6 BasicStroke (java.awt.BasicStroke)6