Search in sources :

Example 61 with ChartPanel

use of org.jfree.chart.ChartPanel in project MtgDesktopCompanion by nicho92.

the class RarityRepartitionPanel method refresh.

private void refresh() {
    this.removeAll();
    JFreeChart chart = ChartFactory.createPieChart3D(// chart title
    "Rarity repartition", // data
    getRarityRepartitionDataSet(), // include legend
    false, true, true);
    pane = new ChartPanel(chart);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionPaint("Uncommon", Color.GRAY);
    plot.setSectionPaint("Common", Color.WHITE);
    plot.setSectionPaint("Rare", Color.YELLOW);
    plot.setSectionPaint("Mythic Rare", Color.ORANGE);
    PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{0} = {1}", new DecimalFormat("0"), new DecimalFormat("0.00%"));
    plot.setLabelGenerator(generator);
    this.add(pane, BorderLayout.CENTER);
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) PieSectionLabelGenerator(org.jfree.chart.labels.PieSectionLabelGenerator) DecimalFormat(java.text.DecimalFormat) PiePlot(org.jfree.chart.plot.PiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) JFreeChart(org.jfree.chart.JFreeChart)

Example 62 with ChartPanel

use of org.jfree.chart.ChartPanel in project MtgDesktopCompanion by nicho92.

the class TypeRepartitionPanel method refresh.

private void refresh() {
    this.removeAll();
    JFreeChart chart = ChartFactory.createPieChart3D(// chart title
    "Type repartition", // data
    getTypeRepartitionDataSet(), // include legend
    false, true, true);
    pane = new ChartPanel(chart);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionPaint("B", Color.BLACK);
    plot.setSectionPaint("W", Color.WHITE);
    plot.setSectionPaint("U", Color.BLUE);
    plot.setSectionPaint("G", Color.GREEN);
    plot.setSectionPaint("R", Color.RED);
    plot.setSectionPaint("multi", Color.YELLOW);
    plot.setSectionPaint("uncolor", Color.GRAY);
    PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{0} = {1}", new DecimalFormat("0"), new DecimalFormat("0.00%"));
    plot.setLabelGenerator(generator);
    this.add(pane, BorderLayout.CENTER);
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) PieSectionLabelGenerator(org.jfree.chart.labels.PieSectionLabelGenerator) DecimalFormat(java.text.DecimalFormat) PiePlot(org.jfree.chart.plot.PiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) JFreeChart(org.jfree.chart.JFreeChart)

Example 63 with ChartPanel

use of org.jfree.chart.ChartPanel in project mylizzie by aerisnju.

the class WinrateHistogramDialog method initCustomComponents.

private void initCustomComponents() {
    WinrateHistogramTableModel winrateHistogramTableModel = new WinrateHistogramTableModel();
    tableWinrateHistory.setModel(winrateHistogramTableModel);
    XYSeries blackSeries = new XYSeries("Black");
    XYSeries whiteSeries = new XYSeries("White");
    XYSeries standardSeries = new XYSeries("50%");
    for (int i = 0; i <= 50; ++i) {
        standardSeries.add(i, 50);
    }
    dataSet = new XYSeriesCollection();
    dataSet.addSeries(blackSeries);
    dataSet.addSeries(whiteSeries);
    dataSet.addSeries(standardSeries);
    JFreeChart chart = ChartFactory.createXYLineChart(// chart title
    "", // x axis label
    "", // y axis label
    "Win%", // data
    dataSet, PlotOrientation.VERTICAL, // include legend
    true, // tooltips
    true, // urls
    false);
    chart.setBackgroundPaint(Color.WHITE);
    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setRange(0.0, 100.0);
    histogramChartPanel = new ChartPanel(chart);
    panelWinrateHistogram.add(histogramChartPanel);
    winrateHistogramTableModel.setRefreshObserver(new Consumer<WinrateHistogramTableModel>() {

        private long lastRefreshTime = System.currentTimeMillis();

        @Override
        public void accept(WinrateHistogramTableModel model) {
            long currentTime = System.currentTimeMillis();
            if (currentTime - lastRefreshTime < 500L) {
                return;
            }
            lastRefreshTime = currentTime;
            blackSeries.clear();
            whiteSeries.clear();
            standardSeries.clear();
            for (int i = 0; i < model.getHistogramEntryList().size(); ++i) {
                WinrateHistogramEntry entry = model.getHistogramEntryList().get(i);
                standardSeries.add(entry.getMoveNumber(), 50);
                if (checkBoxHistogramShowBlack.isSelected()) {
                    blackSeries.add(entry.getMoveNumber(), entry.getBlackWinrate());
                }
                if (checkBoxHistogramShowWhite.isSelected()) {
                    whiteSeries.add(entry.getMoveNumber(), entry.getWhiteWinrate());
                }
            }
            if (model.getHistogramEntryList().size() < 50) {
                for (int i = model.getHistogramEntryList().size() - 1; i <= 50; ++i) {
                    standardSeries.add(i, 50);
                }
            }
            histogramChartPanel.repaint();
        }
    });
    if (Lizzie.optionSetting.getWinrateHistogramWindowWidth() >= 10 && Lizzie.optionSetting.getWinrateHistogramWindowHeight() >= 10) {
        setPreferredSize(new Dimension(Lizzie.optionSetting.getWinrateHistogramWindowWidth(), Lizzie.optionSetting.getWinrateHistogramWindowHeight()));
    }
    splitPaneHistogram.setDividerLocation(0.3);
    pack();
    histogramChartPanel.setPreferredSize(new Dimension(panelWinrateHistogram.getWidth(), panelWinrateHistogram.getHeight()));
    histogramChartPanel.setSize(panelWinrateHistogram.getWidth(), panelWinrateHistogram.getHeight());
    pack();
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) ChartPanel(org.jfree.chart.ChartPanel) JFreeChart(org.jfree.chart.JFreeChart) XYPlot(org.jfree.chart.plot.XYPlot) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection)

Example 64 with ChartPanel

use of org.jfree.chart.ChartPanel in project FRC2018 by first95.

the class AdjustedTalonTester method runVoltageTest.

public void runVoltageTest() {
    // Create dataset
    XYDataset dataset = new XYSeriesCollection();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    int seriesNum = 0;
    for (double throttle = -1.0; throttle <= 1.0; throttle += 0.25) {
        // Prime the UUT with normal voltages for a while
        double voltage = 13;
        for (int i = 0; i < AdjustedTalon.NUM_RECENT_SAMPLES; ++i) {
            pdp.setVoltage(13);
            uut.set(ControlMode.PercentOutput, 0.0);
        }
        XYSeries series = new XYSeries("Throttle at " + throttle, false);
        for (; voltage >= 5.0; voltage -= 0.01) {
            pdp.setVoltage(voltage);
            uut.set(ControlMode.PercentOutput, throttle);
            series.add(voltage, lastCommandedThrottle);
        }
        ((XYSeriesCollection) dataset).addSeries(series);
        renderer.setSeriesLinesVisible(seriesNum, true);
        renderer.setSeriesShapesVisible(seriesNum, false);
        seriesNum++;
    }
    // Create chart
    JFreeChart chart = ChartFactory.createScatterPlot("Adjusted throttle vs battery voltage", "voltage", "Adjusted throttle", dataset);
    // Changes background color
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(200, 200, 200));
    plot.setRenderer(renderer);
    // Create Panel
    ChartPanel panel = new ChartPanel(chart);
    setContentPane(panel);
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) ChartPanel(org.jfree.chart.ChartPanel) XYPlot(org.jfree.chart.plot.XYPlot) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) XYDataset(org.jfree.data.xy.XYDataset) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) JFreeChart(org.jfree.chart.JFreeChart)

Example 65 with ChartPanel

use of org.jfree.chart.ChartPanel in project ta4j by ta4j.

the class IndicatorsToChart method displayChart.

/**
 * Displays a chart in a frame.
 * @param chart the chart to be displayed
 */
private static void displayChart(JFreeChart chart) {
    // Chart panel
    ChartPanel panel = new ChartPanel(chart);
    panel.setFillZoomRectangle(true);
    panel.setMouseWheelEnabled(true);
    panel.setPreferredSize(new java.awt.Dimension(500, 270));
    // Application frame
    ApplicationFrame frame = new ApplicationFrame("Ta4j example - Indicators to chart");
    frame.setContentPane(panel);
    frame.pack();
    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setVisible(true);
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) ApplicationFrame(org.jfree.ui.ApplicationFrame)

Aggregations

ChartPanel (org.jfree.chart.ChartPanel)66 JFreeChart (org.jfree.chart.JFreeChart)42 XYPlot (org.jfree.chart.plot.XYPlot)19 Color (java.awt.Color)16 Dimension (java.awt.Dimension)16 NumberAxis (org.jfree.chart.axis.NumberAxis)16 JPanel (javax.swing.JPanel)15 XYSeries (org.jfree.data.xy.XYSeries)14 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)14 XYDataset (org.jfree.data.xy.XYDataset)12 BasicStroke (java.awt.BasicStroke)11 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)11 DecimalFormat (java.text.DecimalFormat)7 JButton (javax.swing.JButton)7 JLabel (javax.swing.JLabel)7 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)7 DefaultFormBuilder (com.jgoodies.forms.builder.DefaultFormBuilder)6 FormLayout (com.jgoodies.forms.layout.FormLayout)6 Font (java.awt.Font)6 GridBagLayout (java.awt.GridBagLayout)6