Search in sources :

Example 1 with LogarithmicAxis

use of org.jfree.chart.axis.LogarithmicAxis in project libresonic by Libresonic.

the class UserChartController method createChart.

private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);
    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    plot.setRangeAxis(rangeAxis);
    // Disable bar outlines.
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    renderer.setSeriesPaint(0, gp0);
    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);
    chart.setBackgroundPaint(bgColor);
    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);
    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);
    return chart;
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) LogarithmicAxis(org.jfree.chart.axis.LogarithmicAxis)

Example 2 with LogarithmicAxis

use of org.jfree.chart.axis.LogarithmicAxis in project Java-Matrix-Benchmark by lessthanoptimal.

the class OperationsVersusSizePlot method setLogScale.

public void setLogScale(boolean range, boolean domain) {
    if (domain) {
        NumberAxis axis = (NumberAxis) plot.getDomainAxis();
        axis = new LogarithmicAxis(axis.getLabel());
        plot.setDomainAxis(axis);
    }
    if (range) {
        NumberAxis axis = (NumberAxis) plot.getRangeAxis();
        axis = new LogarithmicAxis(axis.getLabel());
        plot.setRangeAxis(axis);
    }
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) LogarithmicAxis(org.jfree.chart.axis.LogarithmicAxis)

Example 3 with LogarithmicAxis

use of org.jfree.chart.axis.LogarithmicAxis in project polyGembler by c-zhou.

the class HMMSplitPanel method getChart.

public ChartPanel getChart() {
    Range range = this.updateRates();
    final JFreeChart chart = ChartFactory.createXYLineChart(null, // domain axis label
    null, // range axis label
    null, // data
    rates, PlotOrientation.VERTICAL, // include legend
    false, // tooltips?
    true, // URL generator? Not required...
    false);
    final NumberAxis domainAxis = new NumberAxis("Relative position");
    final LogarithmicAxis rangeAxis = new LogarithmicAxis("Trans-out probability");
    AxisSpace space = new AxisSpace();
    // reserved space on the left side of the plot
    space.setRight(115);
    space.setLeft(65);
    chart.getXYPlot().setFixedRangeAxisSpace(space);
    // double fixedDemension = HMMPanel.this.getX(0, false)-10;
    // rangeAxis.setFixedDimension(fixedDemension);
    domainAxis.setTickUnit(new NumberTickUnit(1));
    rangeAxis.setLog10TickLabelsFlag(true);
    rangeAxis.setRange(range);
    chart.getXYPlot().setDomainAxis(domainAxis);
    chart.getXYPlot().setRangeAxis(rangeAxis);
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < rates.getSeriesCount(); i++) {
        Color c = ca.getColor(i);
        renderer.setSeriesPaint(i, c);
        renderer.setSeriesShapesVisible(i, true);
    }
    chart.getXYPlot().setRenderer(renderer);
    // chart.getXYPlot().getRangeAxis().get
    // chart.getXYPlot().setRangeAxis(new LogarithmicAxis("rates"));
    final ChartPanel cp = new ChartPanel(chart, // width
    this.getWidth(), // height
    200, // mindrawWidth
    this.getWidth(), // mindrawHeight
    100, // maxDrawWith
    this.getWidth(), // maxDrawHeight
    400, ChartPanel.DEFAULT_BUFFER_USED, // properties
    true, // save
    true, // print
    true, // zoom
    true, // tooltips
    true);
    {
        Range r = chart.getXYPlot().getDomainAxis().getRange();
        chart.getXYPlot().getDomainAxis().setAutoRange(false);
        chart.getXYPlot().getDomainAxis().setRange(1, r.getUpperBound());
    }
    {
        Range r = chart.getXYPlot().getRangeAxis().getRange();
        if (r.getLowerBound() < range.getUpperBound()) {
            chart.getXYPlot().getRangeAxis().setAutoRange(false);
            chart.getXYPlot().getRangeAxis().setRange(r.getLowerBound(), range.getUpperBound());
        }
    }
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderPaint(Color.WHITE);
    cp.setBorder(null);
    return cp;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) ChartPanel(org.jfree.chart.ChartPanel) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) AxisSpace(org.jfree.chart.axis.AxisSpace) Range(org.jfree.data.Range) JFreeChart(org.jfree.chart.JFreeChart) LogarithmicAxis(org.jfree.chart.axis.LogarithmicAxis) NumberTickUnit(org.jfree.chart.axis.NumberTickUnit)

Example 4 with LogarithmicAxis

use of org.jfree.chart.axis.LogarithmicAxis 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 5 with LogarithmicAxis

use of org.jfree.chart.axis.LogarithmicAxis in project violations-plugin by jenkinsci.

the class AbstractViolationsBuildAction method createChart.

// FIXME this should be in a utility class
protected JFreeChart createChart(CategoryDataset dataset) {
    final JFreeChart chart = // chart
    ChartFactory.createLineChart(// chart
    null, // unused
    null, // range axis label
    "count", // data
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    true, // tooltips
    true, // urls
    false);
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    final LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = chart.getCategoryPlot();
    if (useLog) {
        final NumberAxis rangeAxis2 = new LogarithmicAxis("Log(y)");
        plot.setRangeAxis(rangeAxis2);
    }
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);
    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // rangeAxis.setUpperBound(100);
    if (Boolean.getBoolean(VIOLATIONS_PLUGIN_CHART_AUTORANGE_PROPERTY)) {
        rangeAxis.setAutoRange(true);
        rangeAxis.setAutoRangeIncludesZero(false);
        rangeAxis.setAutoRangeMinimumSize(50);
    } else {
        rangeAxis.setLowerBound(0);
    }
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setStroke(new BasicStroke(2.0f));
    ColorPalette.apply(renderer);
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(PADDING, 0, 0, PADDING));
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) RectangleInsets(org.jfree.ui.RectangleInsets) LegendTitle(org.jfree.chart.title.LegendTitle) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) LogarithmicAxis(org.jfree.chart.axis.LogarithmicAxis)

Aggregations

LogarithmicAxis (org.jfree.chart.axis.LogarithmicAxis)5 JFreeChart (org.jfree.chart.JFreeChart)4 NumberAxis (org.jfree.chart.axis.NumberAxis)3 CategoryAxis (org.jfree.chart.axis.CategoryAxis)2 CategoryPlot (org.jfree.chart.plot.CategoryPlot)2 ShiftedCategoryAxis (hudson.util.ShiftedCategoryAxis)1 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ChartPanel (org.jfree.chart.ChartPanel)1 AxisSpace (org.jfree.chart.axis.AxisSpace)1 NumberTickUnit (org.jfree.chart.axis.NumberTickUnit)1 ValueAxis (org.jfree.chart.axis.ValueAxis)1 XYPlot (org.jfree.chart.plot.XYPlot)1 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)1 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)1