Search in sources :

Example 51 with XYPlot

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

the class ChartCompositePart method createChart.

/**
	 * Create the chart
	 *
	 * @return the instance of JFreeChart
	 */
private JFreeChart createChart() {
    timeseriescollection = new TimeSeriesCollection();
    seriesMap = new TreeMap<String, TimeSeries>();
    xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
    int number = 0;
    for (Map.Entry<String, String> entry : valueMap.entrySet()) {
        String key = entry.getKey();
        TimeSeries series = new TimeSeries(key);
        seriesMap.put(key, series);
        if (settingMap.get(key).isChecked()) {
            timeseriescollection.addSeries(series);
            RGB seriesRgb = settingMap.get(key).getSeriesRgb();
            float width = settingMap.get(key).getWidth();
            Color color = new Color(seriesRgb.red, seriesRgb.green, seriesRgb.blue);
            xylineandshaperenderer.setSeriesPaint(number, color);
            xylineandshaperenderer.setSeriesStroke(number, new BasicStroke(width, 0, 2));
            number++;
        }
    }
    DateAxis dateaxis = new DateAxis("");
    NumberAxis numberaxis = new NumberAxis("");
    dateaxis.setTickLabelFont(new Font("SansSerif", 0, 10));
    dateaxis.setLabelFont(new Font("SansSerif", 0, 7));
    XYPlot xyplot = new XYPlot(timeseriescollection, dateaxis, numberaxis, xylineandshaperenderer);
    RectangleInsets rectangleInsets = new RectangleInsets();
    xyplot.setAxisOffset(rectangleInsets);
    xyplot.setDomainGridlineStroke(new BasicStroke(0.4f));
    xyplot.setRangeGridlineStroke(new BasicStroke(0.4f));
    xyplot.setOutlineVisible(false);
    xyplot.setBackgroundPaint(Color.BLACK);
    xyplot.setDomainGridlinePaint(new Color(0, 128, 64));
    xyplot.setRangeGridlinePaint(new Color(0, 128, 64));
    dateaxis.setFixedAutoRange(300000d);
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    dateaxis.setTickLabelsVisible(true);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setLowerMargin(0.01D);
    numberaxis.setUpperMargin(0.01D);
    JFreeChart chart = new JFreeChart(chartTitle, new Font("SansSerif", 1, 15), xyplot, false);
    chart.setBorderVisible(false);
    chart.setBorderStroke(new BasicStroke(0.0f));
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) DateAxis(org.jfree.chart.axis.DateAxis) TimeSeries(org.jfree.data.time.TimeSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) CommonUITool.trimPaintColor(com.cubrid.common.ui.spi.util.CommonUITool.trimPaintColor) RGB(org.eclipse.swt.graphics.RGB) Font(java.awt.Font) JFreeChart(org.jfree.chart.JFreeChart) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) RectangleInsets(org.jfree.ui.RectangleInsets) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 52 with XYPlot

use of org.jfree.chart.plot.XYPlot in project zm-mailbox by Zimbra.

the class ChartUtil method hasData.

private boolean hasData(JFreeChart chart) {
    if (chart == null) {
        return false;
    }
    XYPlot plot = chart.getXYPlot();
    XYDataset data = plot.getDataset();
    int numPoints = 0;
    for (int i = 0; i < data.getSeriesCount(); i++) {
        numPoints += data.getItemCount(i);
    }
    if (numPoints == 0) {
        return false;
    }
    return true;
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) XYDataset(org.jfree.data.xy.XYDataset)

Example 53 with XYPlot

use of org.jfree.chart.plot.XYPlot in project zm-mailbox by Zimbra.

the class ChartUtil method createJFReeChart.

private List<JFreeChart> createJFReeChart(ChartSettings cs) {
    double minValue = Double.MAX_VALUE;
    double maxValue = Double.MIN_VALUE;
    double d = 0;
    double count = 0;
    double total = 0;
    TimeSeriesCollection data = new TimeSeriesCollection();
    ArrayList<ChartSettings> syntheticSettings = new ArrayList<ChartSettings>();
    for (GroupPlotSettings gps : cs.getGroupPlots()) {
        String groupBy = gps.getGroupBy();
        DataColumn dc = new DataColumn(gps.getInfile(), groupBy);
        StringSeries groupBySeries = mStringSeries.get(dc);
        dc = new DataColumn(gps.getInfile(), gps.getDataColumn());
        DataSeries ds = mDataSeries.get(dc);
        int idx = 0;
        Map<String, List<Integer>> groups = new HashMap<String, List<Integer>>();
        for (StringEntry e : groupBySeries.dataCollection) {
            String g = e.getVal();
            List<Integer> indices = groups.get(g);
            if (indices == null) {
                indices = new ArrayList<Integer>();
                groups.put(g, indices);
            }
            indices.add(idx);
            idx++;
        }
        for (Map.Entry<String, List<Integer>> g : groups.entrySet()) {
            String groupByValue = g.getKey();
            if (gps.getIgnoreSet().contains(groupByValue))
                continue;
            List<Integer> indices = g.getValue();
            DataSeries syntheticDS = new DataSeries();
            DataColumn c = new DataColumn(gps.getInfile(), GROUP_PLOT_SYNTHETIC + groupByValue + ":" + gps.getDataColumn());
            for (int i : indices) {
                Entry e = ds.get(i);
                syntheticDS.AddEntry(e.getTimestamp(), e.getVal());
            }
            mDataSeries.put(c, syntheticDS);
            PlotSettings syntheticPlot = new PlotSettings(groupByValue, c.getInfile(), c.getColumn(), gps.getShowRaw(), gps.getShowMovingAvg(), gps.getMovingAvgPoints(), gps.getMultiplier(), gps.getDivisor(), gps.getNonNegative(), gps.getPercentTime(), gps.getDataFunction(), gps.getAggregateFunction(), gps.getOptional(), null, null);
            cs.addPlot(syntheticPlot);
            if (cs.getOutDocument() != null) {
                ChartSettings s = new ChartSettings(String.format(cs.getTitle(), groupByValue), cs.getCategory(), String.format(cs.getOutfile(), groupByValue), cs.getXAxis(), cs.getYAxis(), cs.getAllowLogScale(), cs.getPlotZero(), cs.getWidth(), cs.getHeight(), null, cs.getTopPlots(), cs.getTopPlotsType());
                s.addPlot(syntheticPlot);
                syntheticSettings.add(s);
            }
        }
    }
    if (cs.getOutDocument() != null && cs.getGroupPlots().size() != 0) {
        ArrayList<JFreeChart> charts = new ArrayList<JFreeChart>();
        for (ChartSettings c : syntheticSettings) {
            charts.addAll(createJFReeChart(c));
            c.setOutDocument(cs.getOutDocument());
        }
        mSyntheticChartSettings.addAll(syntheticSettings);
        return charts;
    }
    List<PlotSettings> plots = cs.getPlots();
    if (cs.getTopPlots() > 0 && plots.size() > cs.getTopPlots()) {
        String aggregateFunction = cs.getTopPlotsType().name().toLowerCase();
        System.out.println(String.format("Reducing %d to %d plots for chart '%s'", plots.size(), cs.getTopPlots(), cs.getTitle()));
        ArrayList<PlotAggregatePair> aggregates = new ArrayList<PlotAggregatePair>();
        for (PlotSettings ps : plots) {
            DataColumn dc = new DataColumn(ps.getInfile(), ps.getDataColumn());
            String key = ps.getInfile() + ":" + ps.getDataColumn() + ":" + ps.getAggregateFunction();
            PlotDataIterator pdIter = new PlotDataIterator(ps, mDataSeries.get(dc));
            double aggregate = mAggregator.compute(pdIter, aggregateFunction, mAggregateStartAt, mAggregateEndAt, key);
            aggregates.add(new PlotAggregatePair(ps, aggregate));
        }
        Collections.sort(aggregates);
        while (aggregates.size() > cs.getTopPlots()) {
            PlotAggregatePair pair = aggregates.remove(0);
            plots.remove(pair.ps);
        }
    }
    for (PlotSettings ps : plots) {
        String columnName = ps.getDataColumn();
        if (columnName == null) {
            columnName = RATIO_PLOT_SYNTHETIC + ps.getRatioTop() + "/" + ps.getRatioBottom();
            String infile = ps.getInfile();
            String[] top = ps.getRatioTop().split("\\+");
            String[] bottom = ps.getRatioBottom().split("\\+");
            DataColumn[] ratioTop = new DataColumn[top.length];
            DataColumn[] ratioBottom = new DataColumn[bottom.length];
            for (int i = 0, j = top.length; i < j; i++) ratioTop[i] = new DataColumn(infile, top[i]);
            for (int i = 0, j = bottom.length; i < j; i++) ratioBottom[i] = new DataColumn(infile, bottom[i]);
            DataSeries[] topData = new DataSeries[ratioTop.length];
            DataSeries[] bottomData = new DataSeries[ratioBottom.length];
            for (int i = 0, j = ratioTop.length; i < j; i++) topData[i] = mDataSeries.get(ratioTop[i]);
            for (int i = 0, j = ratioBottom.length; i < j; i++) bottomData[i] = mDataSeries.get(ratioBottom[i]);
            DataSeries ds = new DataSeries();
            for (int i = 0, j = topData[0].size(); i < j; i++) {
                double topValue = 0.0;
                double bottomValue = 0.0;
                double ratio = 0.0;
                Entry lastEntry = null;
                for (int m = 0, n = topData.length; m < n; m++) {
                    Entry e = topData[m].get(i);
                    topValue += e.getVal();
                }
                for (int m = 0, n = bottomData.length; m < n; m++) {
                    Entry e = bottomData[m].get(i);
                    bottomValue += e.getVal();
                    lastEntry = e;
                }
                if (bottomValue != 0.0) {
                    ratio = topValue / bottomValue;
                }
                // should never be null
                assert lastEntry != null;
                ds.AddEntry(lastEntry.getTimestamp(), ratio);
            }
            mDataSeries.put(new DataColumn(infile, columnName), ds);
            ps.setDataColumn(columnName);
        }
        DataColumn dc = new DataColumn(ps.getInfile(), ps.getDataColumn());
        DataSeries ds = mDataSeries.get(dc);
        TimeSeries ts = new TimeSeries(ps.getLegend(), FixedMillisecond.class);
        int numSamples = 0;
        for (PlotDataIterator pdIter = new PlotDataIterator(ps, ds); pdIter.hasNext(); numSamples++) {
            Pair<Date, Double> entry = pdIter.next();
            Date tstamp = entry.getFirst();
            double val = entry.getSecond().doubleValue();
            if (val != 0 || cs.getPlotZero()) {
                if (d < minValue)
                    minValue = val;
                if (d > maxValue)
                    maxValue = val;
                count++;
                total += val;
                try {
                    ts.addOrUpdate(new FixedMillisecond(tstamp), val);
                } catch (SeriesException e) {
                    e.printStackTrace(System.out);
                }
            }
        }
        if (numSamples == 0 && ps.getOptional()) {
            System.out.format("Skipping optional plot %s (no data sample found)\n\n", ps.getLegend());
            continue;
        }
        System.out.format("Adding %d %s points to %s.\n\n", ds.size(), ps.getLegend(), cs.getOutfile());
        if (ps.getShowRaw()) {
            data.addSeries(ts);
        }
        if (ps.getShowMovingAvg()) {
            int numPoints = ps.getMovingAvgPoints();
            if (numPoints == PlotSettings.DEFAULT_PLOT_MOVING_AVG_POINTS) {
                // Display 200 points for moving average.
                // Divide the total number of points by 200 to
                // determine the number of samples to average
                // for each point.
                numPoints = ts.getItemCount() / 200;
            }
            if (numPoints >= 2) {
                TimeSeries ma = MovingAverage.createPointMovingAverage(ts, ps.getLegend() + " (moving avg)", numPoints);
                data.addSeries(ma);
            } else {
                System.out.println("Not enough data to display moving average for " + ps.getLegend());
                data.addSeries(ts);
            }
        }
    }
    // Create chart
    boolean legend = (data.getSeriesCount() > 1);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, cs.getXAxis(), cs.getYAxis(), data, legend, false, false);
    // Make Y-axis logarithmic if a spike was detected
    if (cs.getAllowLogScale() && (minValue > 0) && (maxValue > 0) && (maxValue > 20 * (total / count))) {
        if (maxValue / minValue > 100) {
            XYPlot plot = (XYPlot) chart.getPlot();
            ValueAxis oldAxis = plot.getRangeAxis();
            LogarithmicAxis newAxis = new LogarithmicAxis(oldAxis.getLabel());
            plot.setRangeAxis(newAxis);
        }
    }
    mChartMap.put(cs, chart);
    return Arrays.asList(chart);
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FixedMillisecond(org.jfree.data.time.FixedMillisecond) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) ValueAxis(org.jfree.chart.axis.ValueAxis) ArrayList(java.util.ArrayList) List(java.util.List) SeriesException(org.jfree.data.general.SeriesException) JFreeChart(org.jfree.chart.JFreeChart) Date(java.util.Date) LogarithmicAxis(org.jfree.chart.axis.LogarithmicAxis) XYPlot(org.jfree.chart.plot.XYPlot) HashMap(java.util.HashMap) Map(java.util.Map)

Example 54 with XYPlot

use of org.jfree.chart.plot.XYPlot in project zm-mailbox by Zimbra.

the class ChartUtil method lineUpAxes.

/**
     * Updates axes for all charts so that they display the same time interval.
     */
private void lineUpAxes() {
    for (JFreeChart chart : mCharts) {
        XYPlot plot = (XYPlot) chart.getPlot();
        DateAxis axis = (DateAxis) plot.getDomainAxis();
        Date chartMinDate = axis.getMinimumDate();
        Date chartMaxDate = axis.getMaximumDate();
        if (chartMinDate != null && mMinDate < chartMinDate.getTime()) {
            axis.setMinimumDate(new Date(mMinDate));
        }
        if (chartMaxDate != null && mMaxDate > chartMaxDate.getTime()) {
            axis.setMaximumDate(new Date(mMaxDate));
        }
    }
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) XYPlot(org.jfree.chart.plot.XYPlot) JFreeChart(org.jfree.chart.JFreeChart) Date(java.util.Date)

Example 55 with XYPlot

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

the class ReplicationMonitorViewPart method createChart.

/**
	 * Create chart unit
	 * 
	 * @return chart
	 */
private JFreeChart createChart() {
    //create data set
    replTimeSeries = new TimeSeries(Messages.msgDelayValue + "    ");
    replTimeSeries.setMaximumItemAge(2592000);
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    timeseriescollection.addSeries(replTimeSeries);
    //create X axis
    DateAxis dateaxis = new DateAxis(Messages.msgSlaveTimes);
    dateaxis.setTickLabelFont(new Font("SansSerif", 0, 10));
    dateaxis.setLabelFont(new Font("SansSerif", 0, 7));
    dateaxis.setFixedAutoRange(300000d);
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    dateaxis.setTickLabelsVisible(true);
    //create Y axis
    NumberAxis numberaxis = new NumberAxis(Messages.msgDelayValue);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    //create display model
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, true);
    xylineandshaperenderer.setSeriesPaint(0, new Color(146, 208, 80));
    xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(2F, 0, 2));
    XYPlot xyplot = new XYPlot(timeseriescollection, dateaxis, numberaxis, xylineandshaperenderer);
    //set backcolor of grid
    xyplot.setBackgroundPaint(Color.BLACK);
    //set vertical line color of grid
    xyplot.setDomainGridlinePaint(new Color(130, 130, 130));
    //set horizontal line color of grid
    xyplot.setRangeGridlinePaint(new Color(130, 130, 130));
    xyplot.setAxisOffset(new RectangleInsets(0D, 0D, 0D, 10D));
    JFreeChart chart = new JFreeChart(Messages.titlePerformancePart, new Font("SansSerif", 1, 15), xyplot, true);
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) DateAxis(org.jfree.chart.axis.DateAxis) TimeSeries(org.jfree.data.time.TimeSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) RectangleInsets(org.jfree.ui.RectangleInsets) Font(java.awt.Font) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

XYPlot (org.jfree.chart.plot.XYPlot)60 JFreeChart (org.jfree.chart.JFreeChart)37 Color (java.awt.Color)19 DateAxis (org.jfree.chart.axis.DateAxis)18 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)15 NumberAxis (org.jfree.chart.axis.NumberAxis)12 CommonUITool.trimPaintColor (com.cubrid.common.ui.spi.util.CommonUITool.trimPaintColor)11 Map (java.util.Map)11 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)10 SimpleDateFormat (java.text.SimpleDateFormat)9 ValueAxis (org.jfree.chart.axis.ValueAxis)9 XYDataset (org.jfree.data.xy.XYDataset)9 RectangleInsets (org.jfree.ui.RectangleInsets)9 TreeMap (java.util.TreeMap)8 Font (java.awt.Font)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