Search in sources :

Example 31 with ChartPanel

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

the class DashboardRendererTimeseries method createDashboard.

@Override
public DashboardChartComposite createDashboard(Composite composite, DashboardContainer container, DashboardViewContainer viewContainer, Point preferredSize) {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    // generateSampleSeries(container, dataset);
    DashboardItemViewConfiguration viewConfig = viewContainer.getViewConfiguration().getDashboardConfig(container.getDashboardId());
    Color gridColor = AWTUtils.makeAWTColor(UIStyles.getDefaultTextForeground());
    JFreeChart histogramChart = ChartFactory.createXYLineChart(null, UIDashboardMessages.histogram_timeseries_x_axis_label, UIDashboardMessages.histogram_timeseries_y_axis_label, dataset, PlotOrientation.VERTICAL, true, true, false);
    histogramChart.setBorderVisible(false);
    histogramChart.setPadding(new RectangleInsets(0, 0, 0, 0));
    histogramChart.setTextAntiAlias(true);
    histogramChart.setBackgroundPaint(AWTUtils.makeAWTColor(UIStyles.getDefaultTextBackground()));
    createDefaultLegend(viewConfig, histogramChart);
    ChartPanel chartPanel = new ChartPanel(histogramChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(preferredSize.x, preferredSize.y));
    final XYPlot plot = histogramChart.getXYPlot();
    // Remove border
    plot.setOutlinePaint(null);
    // Remove background
    plot.setShadowGenerator(null);
    plot.setDrawingSupplier(new BaseChartDrawingSupplier());
    // XYItemRenderer renderer = new XYLine3DRenderer();
    // plot.setRenderer(renderer);
    // renderer.setSeriesOutlinePaint(0, Color.black);
    // renderer.setSeriesOutlineStroke(0, new BasicStroke(0.5f));
    {
        DateAxis domainAxis = new DateAxis(UIDashboardMessages.histogram_timeseries_date_axis_label);
        domainAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
        domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
        domainAxis.setAutoRange(true);
        domainAxis.setLabel(null);
        domainAxis.setLowerMargin(0);
        domainAxis.setUpperMargin(0);
        domainAxis.setTickLabelPaint(gridColor);
        domainAxis.setTickLabelFont(DEFAULT_TICK_LABEL_FONT);
        domainAxis.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
        DateTickUnitType unitType;
        switch(container.getDashboardInterval()) {
            case minute:
                unitType = DateTickUnitType.MINUTE;
                break;
            case hour:
                unitType = DateTickUnitType.HOUR;
                break;
            case day:
            case week:
                unitType = DateTickUnitType.DAY;
                break;
            case month:
                unitType = DateTickUnitType.MONTH;
                break;
            case year:
                unitType = DateTickUnitType.YEAR;
                break;
            default:
                unitType = DateTickUnitType.SECOND;
                break;
        }
        int tickCount = container.getDashboardMaxItems();
        if (tickCount > 40) {
            tickCount = container.getDashboardMaxItems() / 5;
        }
        if (tickCount <= 1) {
            tickCount = 10;
        }
        domainAxis.setTickUnit(new DateTickUnit(unitType, Math.min(MAX_TIMESERIES_RANGE_LABELS, tickCount)));
        if (viewConfig != null && !viewConfig.isDomainTicksVisible()) {
            domainAxis.setVisible(false);
        }
        plot.setDomainAxis(domainAxis);
    }
    {
        ValueAxis rangeAxis = plot.getRangeAxis();
        rangeAxis.setLabel(null);
        rangeAxis.setTickLabelPaint(gridColor);
        rangeAxis.setTickLabelFont(DEFAULT_TICK_LABEL_FONT);
        rangeAxis.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
        rangeAxis.setStandardTickUnits(DashboardUtils.getTickUnitsSource(container.getDashboardValueType()));
        if (container.getDashboardValueType() == DashboardValueType.percent) {
            rangeAxis.setLowerBound(0);
            rangeAxis.setUpperBound(100);
        }
        if (viewConfig != null && !viewConfig.isRangeTicksVisible()) {
            rangeAxis.setVisible(false);
        }
    // rangeAxis.setLowerMargin(0.2);
    // rangeAxis.setLowerBound(.1);
    }
    XYItemRenderer plotRenderer = plot.getRenderer();
    plotRenderer.setBaseItemLabelPaint(gridColor);
    BasicStroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 10.0f, null, 0.0f);
    plot.getRenderer().setBaseStroke(stroke);
    // Set background
    plot.setBackgroundPaint(histogramChart.getBackgroundPaint());
    /*
        Stroke gridStroke = new BasicStroke(0.1f,
            BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 1.0f,
            new float[] {1.0f, 1.0f}, 0.0f);
*/
    plot.setDomainGridlinePaint(gridColor);
    // plot.setDomainGridlineStroke(gridStroke);
    plot.setDomainGridlinesVisible(viewConfig == null || viewConfig.isGridVisible());
    plot.setRangeGridlinePaint(gridColor);
    // plot.setRangeGridlineStroke(gridStroke);
    plot.setRangeGridlinesVisible(viewConfig == null || viewConfig.isGridVisible());
    DashboardChartComposite chartComposite = createChartComposite(composite, container, viewContainer, preferredSize);
    chartComposite.setChart(histogramChart);
    return chartComposite;
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) BaseChartDrawingSupplier(org.jkiss.dbeaver.ui.charts.BaseChartDrawingSupplier) JFreeChart(org.jfree.chart.JFreeChart) XYPlot(org.jfree.chart.plot.XYPlot) DashboardChartComposite(org.jkiss.dbeaver.ui.dashboard.control.DashboardChartComposite) RectangleInsets(org.jfree.ui.RectangleInsets) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) SimpleDateFormat(java.text.SimpleDateFormat) java.awt(java.awt)

Example 32 with ChartPanel

use of org.jfree.chart.ChartPanel in project Stock-Ticker-Project by IsaiahL12.

the class DynamicDataDemo method graph1.

public JPanel graph1(String title, Vector<Double> avgV) {
    final XYSeries high = new XYSeries("High");
    final XYSeries average = new XYSeries("Price");
    final XYSeries low = new XYSeries("Low");
    double hold = 0;
    double hold1 = -1;
    double hold2 = 100000000;
    int spacing = 20;
    for (int i = 0; i < avgV.size(); i++) {
        if (avgV.get(i) != -1 && avgV.get(i) != 0) {
            if (hold1 < avgV.get(i)) {
                hold1 = avgV.get(i);
            }
            if (hold2 > avgV.get(i)) {
                hold2 = avgV.get(i);
            // System.out.println(hold2);
            }
            // Date day = new SimpleDateFormat("HH:MM").parse("9:30");
            hold = avgV.get(i);
            average.add(spacing * i, round(hold, 2));
            high.add(spacing * i, round(hold1, 2));
            low.add(spacing * i, round(hold2, 2));
        }
    }
    XYSeriesCollection dataset = new XYSeriesCollection(high);
    dataset.addSeries(low);
    dataset.addSeries(average);
    JFreeChart chart;
    chart = createChart1(dataset, title);
    chart.getPlot().setBackgroundPaint(Color.BLACK);
    ChartPanel chartPanel = new ChartPanel(chart);
    // chartPanel.overlayChanged(event);
    JPanel content = new JPanel(new BorderLayout());
    content.add(chartPanel);
    // content.add(button, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(375, 320));
    // this.add(content);
    return content;
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) JPanel(javax.swing.JPanel) ChartPanel(org.jfree.chart.ChartPanel) BorderLayout(java.awt.BorderLayout) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) JFreeChart(org.jfree.chart.JFreeChart)

Example 33 with ChartPanel

use of org.jfree.chart.ChartPanel in project spf4j by zolyfarkas.

the class TSDBViewJInternalFrame method addChartToPanel.

private void addChartToPanel(final String tableName, final JPanel content) throws IOException {
    TSTable info = tsDb.getTSTable(tableName);
    long startTime = ((Date) startDate.getValue()).getTime();
    long endTime = ((Date) endDate.getValue()).getTime();
    if (TimeSeriesDatabase.canGenerateHeatChart(info)) {
        JFreeChart chart = tsDb.createHeatJFreeChart(info.getTableName(), startTime, endTime);
        ChartPanel pannel = new ChartPanel(chart);
        pannel.setPreferredSize(new Dimension(600, 800));
        pannel.setDomainZoomable(false);
        pannel.setMouseZoomable(false);
        pannel.setRangeZoomable(false);
        pannel.setZoomAroundAnchor(false);
        pannel.setZoomInFactor(1);
        pannel.setZoomOutFactor(1);
        content.add(pannel);
    }
    if (TimeSeriesDatabase.canGenerateMinMaxAvgCount(info)) {
        JFreeChart chart = tsDb.createMinMaxAvgJFreeChart(info.getTableName(), startTime, endTime);
        ChartPanel pannel = new ChartPanel(chart);
        pannel.setPreferredSize(new Dimension(600, 600));
        content.add(pannel);
    }
    if (TimeSeriesDatabase.canGenerateCount(info)) {
        JFreeChart chart = tsDb.createCountJFreeChart(info.getTableName(), startTime, endTime);
        ChartPanel pannel = new ChartPanel(chart);
        pannel.setPreferredSize(new Dimension(600, 600));
        content.add(pannel);
    } else {
        List<JFreeChart> createJFreeCharts = tsDb.createJFreeCharts(info.getTableName(), startTime, endTime);
        for (JFreeChart chart : createJFreeCharts) {
            ChartPanel pannel = new ChartPanel(chart);
            pannel.setPreferredSize(new Dimension(600, 600));
            content.add(pannel);
        }
    }
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) TSTable(org.spf4j.perf.tsdb.TSTable) Dimension(java.awt.Dimension) Date(java.util.Date) JFreeChart(org.jfree.chart.JFreeChart)

Example 34 with ChartPanel

use of org.jfree.chart.ChartPanel in project spf4j by zolyfarkas.

the class TSDB2ViewJInternalFrame method addChartToPanel.

private void addChartToPanel(final String tableName, final JPanel content) throws IOException {
    List<TableDef> info = TSDBQuery.getTableDef(tsDb, tableName);
    long startTime = ((Date) startDate.getValue()).getTime();
    long endTime = ((Date) endDate.getValue()).getTime();
    if (Charts.canGenerateHeatChart(info.get(0))) {
        JFreeChart chart = Charts.createHeatJFreeChart(tsDb, info, startTime, endTime);
        ChartPanel pannel = new ChartPanel(chart);
        pannel.setPreferredSize(new Dimension(600, 800));
        pannel.setDomainZoomable(false);
        pannel.setMouseZoomable(false);
        pannel.setRangeZoomable(false);
        pannel.setZoomAroundAnchor(false);
        pannel.setZoomInFactor(1);
        pannel.setZoomOutFactor(1);
        content.add(pannel);
    }
    if (Charts.canGenerateMinMaxAvgCount(info.get(0))) {
        JFreeChart chart = Charts.createMinMaxAvgJFreeChart(tsDb, info, startTime, endTime);
        ChartPanel pannel = new ChartPanel(chart);
        pannel.setPreferredSize(new Dimension(600, 600));
        content.add(pannel);
    }
    if (Charts.canGenerateCount(info.get(0))) {
        JFreeChart chart = Charts.createCountJFreeChart(tsDb, info, startTime, endTime);
        ChartPanel pannel = new ChartPanel(chart);
        pannel.setPreferredSize(new Dimension(600, 600));
        content.add(pannel);
    } else {
        List<JFreeChart> createJFreeCharts = Charts.createJFreeCharts(tsDb, info, startTime, endTime);
        for (JFreeChart chart : createJFreeCharts) {
            ChartPanel pannel = new ChartPanel(chart);
            pannel.setPreferredSize(new Dimension(600, 600));
            content.add(pannel);
        }
    }
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) Dimension(java.awt.Dimension) TableDef(org.spf4j.tsdb2.avro.TableDef) Date(java.util.Date) JFreeChart(org.jfree.chart.JFreeChart)

Example 35 with ChartPanel

use of org.jfree.chart.ChartPanel in project BachelorPraktikum by lucasbuschlinger.

the class Plotter method viewPlot.

/**
 * Views the plot with the plotted data.
 */
public void viewPlot() {
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(WINDOW_WIDTH, WINDOW_HEIGHT));
    setContentPane(chartPanel);
    this.pack();
    RefineryUtilities.centerFrameOnScreen(this);
    this.setVisible(true);
}
Also used : ChartPanel(org.jfree.chart.ChartPanel)

Aggregations

ChartPanel (org.jfree.chart.ChartPanel)84 JFreeChart (org.jfree.chart.JFreeChart)50 XYPlot (org.jfree.chart.plot.XYPlot)20 Dimension (java.awt.Dimension)18 JPanel (javax.swing.JPanel)17 Color (java.awt.Color)16 NumberAxis (org.jfree.chart.axis.NumberAxis)16 ChartEntity (org.jfree.chart.entity.ChartEntity)15 XYSeries (org.jfree.data.xy.XYSeries)15 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)15 XYDataset (org.jfree.data.xy.XYDataset)12 BasicStroke (java.awt.BasicStroke)11 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)11 ChartGesture (net.sf.mzmine.chartbasics.gestures.ChartGesture)8 Button (net.sf.mzmine.chartbasics.gestures.ChartGesture.Button)8 Entity (net.sf.mzmine.chartbasics.gestures.ChartGesture.Entity)8 ChartGestureEvent (net.sf.mzmine.chartbasics.gestures.ChartGestureEvent)8 DecimalFormat (java.text.DecimalFormat)7 JButton (javax.swing.JButton)7 JLabel (javax.swing.JLabel)7