Search in sources :

Example 26 with ChartPanel

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

the class ScanProgressDialog method initialize.

private void initialize() {
    JTabbedPane tabbedPane = new JTabbedPane();
    JPanel tab1 = new JPanel();
    tab1.setLayout(new GridBagLayout());
    JPanel hostPanel = new JPanel();
    hostPanel.setLayout(new GridBagLayout());
    hostPanel.add(new JLabel(Constant.messages.getString("ascan.progress.label.host")), LayoutHelper.getGBC(0, 0, 1, 0.4D));
    hostPanel.add(getHostSelect(), LayoutHelper.getGBC(1, 0, 1, 0.6D));
    tab1.add(hostPanel, LayoutHelper.getGBC(0, 0, 3, 1.0D, 0.0D));
    tab1.add(getJScrollPane(), LayoutHelper.getGBC(0, 1, 3, 1.0D, 1.0D));
    JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
    buttonsPanel.add(getCopyToClipboardButton());
    buttonsPanel.add(getCloseButton());
    tab1.add(buttonsPanel, LayoutHelper.getGBC(0, 2, 3, 1.0D));
    tabbedPane.insertTab(Constant.messages.getString("ascan.progress.tab.progress"), null, tab1, null, 0);
    this.add(tabbedPane);
    int mins = extension.getScannerParam().getMaxChartTimeInMins();
    if (mins > 0) {
        // Treat zero mins as disabled
        JPanel tab2 = new JPanel();
        tab2.setLayout(new GridBagLayout());
        this.seriesTotal = // Name not shown, so no need to i18n
        new TimeSeries("TotalResponses");
        final TimeSeriesCollection dataset = new TimeSeriesCollection(this.seriesTotal);
        this.series100 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.1xx"));
        this.series200 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.2xx"));
        this.series300 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.3xx"));
        this.series400 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.4xx"));
        this.series500 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.5xx"));
        long maxAge = mins * 60L;
        this.seriesTotal.setMaximumItemAge(maxAge);
        this.series100.setMaximumItemAge(maxAge);
        this.series200.setMaximumItemAge(maxAge);
        this.series300.setMaximumItemAge(maxAge);
        this.series400.setMaximumItemAge(maxAge);
        this.series500.setMaximumItemAge(maxAge);
        dataset.addSeries(series100);
        dataset.addSeries(series200);
        dataset.addSeries(series300);
        dataset.addSeries(series400);
        dataset.addSeries(series500);
        chart = createChart(dataset);
        // Set up some vaguely sensible colours
        // Totals
        chart.getXYPlot().getRenderer(0).setSeriesPaint(0, Color.BLACK);
        // 100: Info
        chart.getXYPlot().getRenderer(0).setSeriesPaint(1, Color.GRAY);
        // 200: OK
        chart.getXYPlot().getRenderer(0).setSeriesPaint(2, Color.GREEN);
        // 300: Info
        chart.getXYPlot().getRenderer(0).setSeriesPaint(3, Color.BLUE);
        // 400: Bad req
        chart.getXYPlot().getRenderer(0).setSeriesPaint(4, Color.MAGENTA);
        // 500: Internal error
        chart.getXYPlot().getRenderer(0).setSeriesPaint(5, Color.RED);
        final ChartPanel chartPanel = new ChartPanel(chart);
        tab2.add(chartPanel, LayoutHelper.getGBC(0, 0, 1, 1.0D, 1.0D));
        tabbedPane.insertTab(Constant.messages.getString("ascan.progress.tab.chart"), null, tab2, null, 1);
    }
    // Stop the updating thread when the window is closed
    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            stopThread = true;
        }
    });
    pack();
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) TimeSeries(org.jfree.data.time.TimeSeries) ChartPanel(org.jfree.chart.ChartPanel) GridBagLayout(java.awt.GridBagLayout) JTabbedPane(javax.swing.JTabbedPane) JLabel(javax.swing.JLabel) WindowAdapter(java.awt.event.WindowAdapter) Point(java.awt.Point) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) WindowEvent(java.awt.event.WindowEvent)

Example 27 with ChartPanel

use of org.jfree.chart.ChartPanel in project dbeaver by serge-rider.

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 28 with ChartPanel

use of org.jfree.chart.ChartPanel in project vcell by virtualcell.

the class NikitaTest method run.

@Override
public void run() {
    try {
        // Find the port that a separately running VCell client is listening on
        System.out.println("vcell service port=" + vcellHelper.findVCellApiServerPort());
    } catch (Exception e) {
        uiService.showDialog("Activate VCell client ImageJ service\nTools->'Start Fiji (ImageJ) service'\n" + e.getMessage(), "Couldn't contact VCell client", MessageType.ERROR_MESSAGE);
        return;
    }
    String theCacheKey = null;
    VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.valueOf(modelType), vCellUser, vCellModel, application, simulation, null, null);
    try {
        ArrayList<VCellModelSearchResults> vcmsr = vcellHelper.getSearchedModelSimCacheKey(false, vcms, null);
        if (vcmsr.size() == 0) {
            throw new Exception("No Results for search found");
        }
        theCacheKey = vcmsr.get(0).getCacheKey();
        System.out.println("theCacheKey=" + theCacheKey);
    } catch (Exception e) {
        uiService.showDialog(modelType + ", " + vCellUser + ", " + vCellModel + ", " + application + ", " + simulation + ", null, null\n" + e.getMessage(), "Search failed", MessageType.ERROR_MESSAGE);
        return;
    }
    IJDataList timePointData = null;
    // there is 1 timePoint
    int[] timePointIndexes = new int[1];
    int theTimePointIndex = 0;
    timePointIndexes[theTimePointIndex] = timePoint;
    try {
        timePointData = vcellHelper.getTimePointData(theCacheKey, variable, VARTYPE_POSTPROC.NotPostProcess, timePointIndexes, 0);
    } catch (Exception e) {
        uiService.showDialog(modelType + ", " + vCellUser + ", " + vCellModel + ", " + application + ", " + simulation + ", " + variable + ", " + timePoint + "\n" + e.getMessage(), "Get Data failed", MessageType.ERROR_MESSAGE);
        return;
    }
    double[] theTimePointData = timePointData.ijData[theTimePointIndex].getDoubleData();
    Range xAxisRange = null;
    int[] dataIndexes = new int[endIndex - startIndex + 1];
    // This is just for JFreeChart
    double[] dataIndexesDouble = new double[dataIndexes.length];
    for (int i = startIndex; i <= endIndex; i++) {
        dataIndexes[i - startIndex] = i;
        dataIndexesDouble[i - startIndex] = i;
        xAxisRange = Range.expandToInclude(xAxisRange, dataIndexesDouble[i - startIndex]);
    }
    Range yAxisRange = null;
    double[] chartTheseDataPoints = new double[dataIndexes.length];
    for (int i = 0; i < dataIndexes.length; i++) {
        chartTheseDataPoints[i] = theTimePointData[dataIndexes[i]];
        yAxisRange = Range.expandToInclude(yAxisRange, chartTheseDataPoints[i]);
    // ijTimeSeriesJobResults.data[0/*index of "r"*/][i+1/*data, skip 0 because it holds copy of times*/][0/*0 always because we had only 1 timePoint=22.0*/]
    }
    try {
        // LINE plot of data at 1 timePoint along defined indexes
        // Create JFreechart x,y axis arrays for plotting x=data indexes, y=dataPoint values
        double[][] data = new double[][] { dataIndexesDouble, chartTheseDataPoints };
        String title = "LINE Plot at time=" + timePoint;
        String xAxisLabel = "distance";
        String yAxisLabel = "val";
        DefaultXYDataset xyDataset = new DefaultXYDataset();
        xyDataset.addSeries("data1", data);
        JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, xyDataset, PlotOrientation.VERTICAL, false, false, false);
        // Y
        chart.getXYPlot().getDomainAxis().setRange(xAxisRange);
        // X
        chart.getXYPlot().getRangeAxis().setRange(yAxisRange);
        ChartPanel chartPanel = new ChartPanel(chart);
        JFrame frame = new JFrame("Chart");
        // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(chartPanel);
        // Display the window.
        frame.pack();
        frame.setVisible(true);
    } catch (Exception e) {
        uiService.showDialog("LINE PlotGet Data failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
    IJTimeSeriesJobResults timeSeries = null;
    try {
        IJVarInfos simulationInfo = vcellHelper.getSimulationInfo(theCacheKey);
        double[] times = simulationInfo.getTimes();
        timeSeries = vcellHelper.getTimeSeries(new String[] { variable }, new int[] { dataIndexes[0] }, times[0], 1, times[times.length - 1], false, false, 0, Integer.parseInt(theCacheKey));
    } catch (Exception e) {
        uiService.showDialog("TIME Plot Get Data failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
    try {
        // TIME plot of data at 1 timePoint along defined indexes
        // Create JFreechart x,y axis arrays for plotting x=data indexes, y=dataPoint values
        double[][] data = new double[][] { timeSeries.data[0][0], timeSeries.data[0][1] };
        String title = "TIME Plot at dataIndex=" + dataIndexes[0];
        String xAxisLabel = "time";
        String yAxisLabel = "val";
        DefaultXYDataset xyDataset = new DefaultXYDataset();
        xyDataset.addSeries("data1", data);
        JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, xyDataset, PlotOrientation.VERTICAL, false, false, false);
        // chart.getXYPlot().getDomainAxis().setRange(yAxisRange);//Y
        // chart.getXYPlot().getRangeAxis().setRange(xAxisRange);//X
        ChartPanel chartPanel = new ChartPanel(chart);
        JFrame frame = new JFrame("Chart");
        // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(chartPanel);
        // Display the window.
        frame.pack();
        frame.setVisible(true);
    } catch (Exception e) {
        uiService.showDialog("TIME Plot show chart failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) IJVarInfos(org.vcell.imagej.helper.VCellHelper.IJVarInfos) DefaultXYDataset(org.jfree.data.xy.DefaultXYDataset) VCellModelSearchResults(org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults) Range(org.jfree.data.Range) VCellHelper(org.vcell.imagej.helper.VCellHelper) JFreeChart(org.jfree.chart.JFreeChart) JFrame(javax.swing.JFrame) IJDataList(org.vcell.imagej.helper.VCellHelper.IJDataList) IJTimeSeriesJobResults(org.vcell.imagej.helper.VCellHelper.IJTimeSeriesJobResults)

Example 29 with ChartPanel

use of org.jfree.chart.ChartPanel in project SIMVA-SoS by SESoS.

the class NewJFrame method drawBarGraph.

/**
 * @param dataset Creates bar graph
 */
public void drawBarGraph(DefaultCategoryDataset dataset) {
    CategoryPlot plot = (CategoryPlot) barChart.getPlot();
    plot.getRenderer().setSeriesPaint(0, Color.BLUE);
    plot.getRenderer().setSeriesPaint(1, Color.RED);
    ChartPanel chartpanel = new ChartPanel(barChart);
    graph_panel.removeAll();
    graph_panel.add(chartpanel, BorderLayout.CENTER);
    graph_panel.revalidate();
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 30 with ChartPanel

use of org.jfree.chart.ChartPanel in project SIMVA-SoS by SESoS.

the class TimeSeriesChartDemo1 method createDemoPanel.

/**
 * Creates a panel for the demo (used by SuperDemo.java).
 *
 * @return A panel.
 */
public static JPanel createDemoPanel() {
    JFreeChart chart = createChart(createDataset());
    ChartPanel panel = new ChartPanel(chart);
    panel.setFillZoomRectangle(true);
    panel.setMouseWheelEnabled(true);
    return panel;
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) JFreeChart(org.jfree.chart.JFreeChart)

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