Search in sources :

Example 66 with JFreeChart

use of org.jfree.chart.JFreeChart in project cubrid-manager by CUBRID.

the class CombinedBarTimeSeriesChart method createSeriesChart.

/**
	 * Create the series chart
	 * 
	 * @return an instance of series chart
	 */
private JFreeChart createSeriesChart() {
    if (isAreaRender) {
        seriesdataset = createTableSeriesDataset();
    } else {
        seriesdataset = createTimeSeriesDataset();
    }
    JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", seriesdataset, false, false, false);
    chart.setBorderVisible(false);
    chart.setBorderStroke(new BasicStroke(0.0f));
    //plot
    XYPlot xyplot = (XYPlot) chart.getPlot();
    xyplot.setOutlineVisible(false);
    RectangleInsets rectangleInsets = new RectangleInsets();
    xyplot.setAxisOffset(rectangleInsets);
    xyplot.setDomainGridlineStroke(new BasicStroke(0.4f));
    xyplot.setRangeGridlineStroke(new BasicStroke(0.4f));
    xyplot.setBackgroundPaint(Color.BLACK);
    xyplot.setDomainGridlinePaint(new Color(0, 128, 64));
    xyplot.setRangeGridlinePaint(new Color(0, 128, 64));
    if (isAreaRender) {
        XYAreaRenderer2 render = new StackedXYAreaRenderer2();
        render.setSeriesPaint(0, Color.GREEN);
        render.setSeriesPaint(1, Color.RED);
        xyplot.setRenderer(render);
    } else {
        XYLineAndShapeRenderer render = (XYLineAndShapeRenderer) xyplot.getRenderer();
        render.setSeriesPaint(0, Color.GREEN);
        render.setSeriesPaint(1, Color.RED);
    }
    //dateAxis
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setFixedAutoRange(300000d);
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    dateaxis.setVisible(isShowSeriesAxis);
    numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setVisible(isShowSeriesAxis);
    numberaxis.setRange(0 - 0.5, barMax + 0.5);
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) StackedXYAreaRenderer2(org.jfree.chart.renderer.xy.StackedXYAreaRenderer2) DateAxis(org.jfree.chart.axis.DateAxis) XYPlot(org.jfree.chart.plot.XYPlot) Color(java.awt.Color) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) RectangleInsets(org.jfree.ui.RectangleInsets) JFreeChart(org.jfree.chart.JFreeChart) XYAreaRenderer2(org.jfree.chart.renderer.xy.XYAreaRenderer2) StackedXYAreaRenderer2(org.jfree.chart.renderer.xy.StackedXYAreaRenderer2)

Example 67 with JFreeChart

use of org.jfree.chart.JFreeChart in project cubrid-manager by CUBRID.

the class DbSystemMonitorCompositePart method fireChartSetting.

/**
	 * This method is responsible for preparing data for ChartSettingDlg and
	 * dealing with the results of chartSettingDlg
	 *
	 */
public void fireChartSetting() {
    ChartSettingDlg chartSettingDlg = new ChartSettingDlg(composite.getShell());
    chartSettingDlg.setHasTitlSetting(false);
    chartSettingDlg.setHasHistoryPath(true);
    chartSettingDlg.setHasAxisSetting(false);
    chartSettingDlg.setHasSeriesItemSetting(false);
    chartSettingDlg.setHasChartSelection(true);
    // plot appearance
    XYPlot dbStatplot = cpuChart.getSeriesChart().getXYPlot();
    String plotBgColor = trimPaintColor(dbStatplot.getBackgroundPaint().toString());
    String plotDomainGridColor = trimPaintColor(dbStatplot.getDomainGridlinePaint().toString());
    String plotRangGridColor = trimPaintColor(dbStatplot.getRangeGridlinePaint().toString());
    chartSettingDlg.setPlotBgColor(plotBgColor);
    chartSettingDlg.setPlotDomainGridColor(plotDomainGridColor);
    chartSettingDlg.setPlotRangGridColor(plotRangGridColor);
    //history setting
    chartSettingDlg.setHistoryFileName(historyFileName);
    chartSettingDlg.setHistoryPath(historyPath);
    // chart selection
    chartSettingDlg.setChartSelectionLst(getSelectedCharts());
    if (chartSettingDlg.open() == Dialog.OK) {
        // plot appearance
        plotBgColor = chartSettingDlg.getPlotBgColor();
        plotDomainGridColor = chartSettingDlg.getPlotDomainGridColor();
        plotRangGridColor = chartSettingDlg.getPlotRangGridColor();
        JFreeChart cpuBarChart = cpuChart.getBarChart();
        Plot cpuBarPlot = cpuBarChart.getPlot();
        XYPlot cpuSeriesPlot = (XYPlot) cpuChart.getSeriesChart().getPlot();
        JFreeChart memoryBarChart = memoryChart.getBarChart();
        Plot memoryBarPlot = memoryBarChart.getPlot();
        XYPlot memorySeriesPlot = (XYPlot) memoryChart.getSeriesChart().getPlot();
        // history path
        String newHistoryPath = chartSettingDlg.getHistoryPath();
        boolean isChangedHistoryPath = historyPath.equals(newHistoryPath) ? false : true;
        if (isChangedHistoryPath) {
            historyPath = newHistoryPath;
            historyFileHelp.setHistoryPath(historyPath);
            historyFileHelp.setChangedHistoryPath(true);
        }
        int red = 0;
        int green = 0;
        int blue = 0;
        //background
        red = getColorElem(plotBgColor, 0);
        green = getColorElem(plotBgColor, 1);
        blue = getColorElem(plotBgColor, 2);
        Color bgColor = new Color(red, green, blue);
        dbStatplot.setBackgroundPaint(bgColor);
        //cpu chart
        cpuBarChart.setBackgroundPaint(bgColor);
        cpuBarPlot.setBackgroundPaint(bgColor);
        cpuSeriesPlot.setBackgroundPaint(bgColor);
        //memoryChart
        memoryBarPlot.setBackgroundPaint(bgColor);
        memoryBarChart.setBackgroundPaint(bgColor);
        memorySeriesPlot.setBackgroundPaint(bgColor);
        //DomainGridColor
        //db Chart
        red = getColorElem(plotDomainGridColor, 0);
        green = getColorElem(plotDomainGridColor, 1);
        blue = getColorElem(plotDomainGridColor, 2);
        Color domainGridlineColor = new Color(red, green, blue);
        dbStatplot.setDomainGridlinePaint(domainGridlineColor);
        //cpu chart
        cpuSeriesPlot.setDomainGridlinePaint(domainGridlineColor);
        //memoryChart
        memorySeriesPlot.setDomainGridlinePaint(domainGridlineColor);
        //RangeGridColor
        red = getColorElem(plotRangGridColor, 0);
        green = getColorElem(plotRangGridColor, 1);
        blue = getColorElem(plotRangGridColor, 2);
        Color rangeGridColor = new Color(red, green, blue);
        dbStatplot.setRangeGridlinePaint(rangeGridColor);
        //cpu chart
        cpuSeriesPlot.setRangeGridlinePaint(rangeGridColor);
        //memoryChart
        memorySeriesPlot.setRangeGridlinePaint(rangeGridColor);
        //chart Selection
        fireChartSelection(chartSettingDlg.getChartSelectionLst());
    }
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) XYPlot(org.jfree.chart.plot.XYPlot) Plot(org.jfree.chart.plot.Plot) Color(java.awt.Color) CommonUITool.trimPaintColor(com.cubrid.common.ui.spi.util.CommonUITool.trimPaintColor) JFreeChart(org.jfree.chart.JFreeChart)

Example 68 with JFreeChart

use of org.jfree.chart.JFreeChart in project processdash by dtuma.

the class ScheduleBalancingDialog method addChartToPanel.

private void addChartToPanel(JPanel panel, int gridY) {
    // create a dataset for displaying schedule data
    chartData = new ChartData();
    updateChart();
    // customize a renderer for displaying schedules
    XYBarRenderer renderer = new XYBarRenderer();
    renderer.setUseYInterval(true);
    renderer.setBaseToolTipGenerator(chartData);
    renderer.setDrawBarOutline(true);
    // use an inverted, unadorned numeric Y-axis
    NumberAxis yAxis = new NumberAxis();
    yAxis.setInverted(true);
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setUpperMargin(0);
    // use a Date-based X-axis
    DateAxis xAxis = new DateAxis();
    // create an XY plot to display the data
    XYPlot plot = new XYPlot(chartData, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(false);
    plot.setNoDataMessage(TaskScheduleDialog.resources.getString("Chart.No_Data_Message"));
    // create a chart and a chart panel
    JFreeChart chart = new JFreeChart(plot);
    chart.removeLegend();
    ChartPanel chartPanel = new ChartPanel(chart, false);
    chartPanel.setInitialDelay(50);
    chartPanel.setDismissDelay(60000);
    chartPanel.setMinimumDrawHeight(40);
    chartPanel.setMinimumDrawWidth(40);
    chartPanel.setMaximumDrawHeight(3000);
    chartPanel.setMaximumDrawWidth(3000);
    chartPanel.setPreferredSize(new Dimension(300, gridY * 25));
    // add the chart to the dialog content pane
    GridBagConstraints c = new GridBagConstraints();
    c.gridy = gridY;
    c.gridwidth = 4;
    c.weightx = 2;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(10, 0, 0, 0);
    panel.add(chartPanel, c);
    // colors with the schedule rows so they can act as a legend
    for (int i = scheduleRows.size(); i-- > 0; ) {
        ScheduleTableRow oneRow = scheduleRows.get(i);
        oneRow.addColoredIcon(renderer.lookupSeriesPaint(i));
    }
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) GridBagConstraints(java.awt.GridBagConstraints) NumberAxis(org.jfree.chart.axis.NumberAxis) ChartPanel(org.jfree.chart.ChartPanel) Insets(java.awt.Insets) XYPlot(org.jfree.chart.plot.XYPlot) Dimension(java.awt.Dimension) XYBarRenderer(org.jfree.chart.renderer.xy.XYBarRenderer) JFreeChart(org.jfree.chart.JFreeChart) Paint(java.awt.Paint)

Example 69 with JFreeChart

use of org.jfree.chart.JFreeChart in project dhis2-core by dhis2.

the class DefaultChartService method getRadarChart.

private JFreeChart getRadarChart(BaseChart chart, CategoryDataset dataSet) {
    SpiderWebPlot plot = new SpiderWebPlot(dataSet, TableOrder.BY_ROW);
    plot.setLabelFont(LABEL_FONT);
    JFreeChart radarChart = new JFreeChart(chart.getName(), TITLE_FONT, plot, !chart.isHideLegend());
    setBasicConfig(radarChart, chart);
    return radarChart;
}
Also used : JFreeChart(org.jfree.chart.JFreeChart)

Example 70 with JFreeChart

use of org.jfree.chart.JFreeChart in project dhis2-core by dhis2.

the class DefaultChartService method getMultiplePieChart.

private JFreeChart getMultiplePieChart(BaseChart chart, CategoryDataset[] dataSets) {
    JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart(chart.getName(), dataSets[0], TableOrder.BY_ROW, !chart.isHideLegend(), false, false);
    setBasicConfig(multiplePieChart, chart);
    if (multiplePieChart.getLegend() != null) {
        multiplePieChart.getLegend().setItemFont(SUB_TITLE_FONT);
    }
    MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot();
    JFreeChart pieChart = multiplePiePlot.getPieChart();
    pieChart.setBackgroundPaint(COLOR_TRANSPARENT);
    pieChart.getTitle().setFont(SUB_TITLE_FONT);
    PiePlot piePlot = (PiePlot) pieChart.getPlot();
    piePlot.setBackgroundPaint(COLOR_TRANSPARENT);
    piePlot.setOutlinePaint(COLOR_TRANSPARENT);
    piePlot.setLabelFont(LABEL_FONT);
    piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}"));
    piePlot.setSimpleLabels(true);
    piePlot.setIgnoreZeroValues(true);
    piePlot.setIgnoreNullValues(true);
    piePlot.setShadowXOffset(0d);
    piePlot.setShadowYOffset(0d);
    for (int i = 0; i < dataSets[0].getColumnCount(); i++) {
        piePlot.setSectionPaint(dataSets[0].getColumnKey(i), COLORS[(i % COLORS.length)]);
    }
    return multiplePieChart;
}
Also used : StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

JFreeChart (org.jfree.chart.JFreeChart)178 XYPlot (org.jfree.chart.plot.XYPlot)40 NumberAxis (org.jfree.chart.axis.NumberAxis)26 Color (java.awt.Color)22 DateAxis (org.jfree.chart.axis.DateAxis)21 DecimalFormat (java.text.DecimalFormat)18 ChartPanel (org.jfree.chart.ChartPanel)17 XYSeries (org.jfree.data.xy.XYSeries)17 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)17 RectangleInsets (org.jfree.ui.RectangleInsets)17 NumberFormat (java.text.NumberFormat)16 CategoryAxis (org.jfree.chart.axis.CategoryAxis)16 CategoryPlot (org.jfree.chart.plot.CategoryPlot)16 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)13 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)13 HashMap (java.util.HashMap)12 ValueAxis (org.jfree.chart.axis.ValueAxis)12 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)11 CategoryDataset (org.jfree.data.category.CategoryDataset)11 Paint (java.awt.Paint)10