Example usage for org.jfree.chart.renderer.xy XYItemRenderer setBaseStroke

List of usage examples for org.jfree.chart.renderer.xy XYItemRenderer setBaseStroke

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYItemRenderer setBaseStroke.

Prototype

public void setBaseStroke(Stroke stroke);

Source Link

Document

Sets the base stroke and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:scrum.server.common.BurndownChart.java

private static JFreeChart createSprintBurndownChart(List<BurndownSnapshot> snapshots, Date firstDay,
        Date lastDay, Date originallyLastDay, WeekdaySelector freeDays, int dateMarkTickUnit,
        float widthPerDay) {
    DefaultXYDataset data = createSprintBurndownChartDataset(snapshots, firstDay, lastDay, originallyLastDay,
            freeDays);/*  w ww.j  a v a  2s  .  c  o m*/

    double tick = 1.0;
    double max = BurndownChart.getMaximum(data);

    while (max / tick > 25) {
        tick *= 2;
        if (max / tick <= 25)
            break;
        tick *= 2.5;
        if (max / tick <= 25)
            break;
        tick *= 2;
    }
    double valueLabelTickUnit = tick;
    double upperBoundary = Math.min(max * 1.1f, max + 3);

    if (!Sys.isHeadless())
        LOG.warn("GraphicsEnvironment is not headless");
    JFreeChart chart = ChartFactory.createXYLineChart("", "", "", data, PlotOrientation.VERTICAL, false, true,
            false);

    chart.setBackgroundPaint(Color.WHITE);

    XYPlot plot = chart.getXYPlot();
    // plot.setInsets(new RectangleInsets(0, 0, 0, 0));
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    // plot.setOutlineVisible(false);

    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.lightGray);
    // plot.setRangeCrosshairPaint(Color.lightGray);
    // plot.setRangeMinorGridlinePaint(Color.lightGray);
    // plot.setDomainCrosshairPaint(Color.blue);
    // plot.setDomainMinorGridlinePaint(Color.green);
    // plot.setDomainTickBandPaint(Color.green);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(2f));

    renderer.setSeriesPaint(0, COLOR_PAST_LINE);
    renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer.setSeriesPaint(1, COLOR_PROJECTION_LINE);
    renderer.setSeriesStroke(1,
            new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL, 1.0f, new float[] { 3f }, 0));
    renderer.setSeriesPaint(2, COLOR_OPTIMUM_LINE);
    renderer.setSeriesStroke(2, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));

    DateAxis domainAxis1 = new DateAxis();
    String dateFormat = "d.";
    widthPerDay -= 5;
    if (widthPerDay > 40) {
        dateFormat = "EE " + dateFormat;
    }
    if (widthPerDay > 10) {
        float spaces = widthPerDay / 2.7f;
        dateFormat = Str.multiply(" ", (int) spaces) + dateFormat;
    }
    domainAxis1.setDateFormatOverride(new SimpleDateFormat(dateFormat, Locale.US));
    domainAxis1.setTickUnit(new DateTickUnit(DateTickUnit.DAY, dateMarkTickUnit));
    domainAxis1.setAxisLineVisible(false);
    Range range = new Range(firstDay.toMillis(), lastDay.nextDay().toMillis());
    domainAxis1.setRange(range);

    DateAxis domainAxis2 = new DateAxis();
    domainAxis2.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1));
    domainAxis2.setTickMarksVisible(false);
    domainAxis2.setTickLabelsVisible(false);
    domainAxis2.setRange(range);

    plot.setDomainAxis(0, domainAxis2);
    plot.setDomainAxis(1, domainAxis1);
    plot.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setNumberFormatOverride(NumberFormat.getIntegerInstance());
    rangeAxis.setTickUnit(new NumberTickUnit(valueLabelTickUnit));

    rangeAxis.setLowerBound(0);
    rangeAxis.setUpperBound(upperBoundary);

    plot.setRangeAxis(rangeAxis);

    return chart;
}

From source file:org.xapagy.ui.tempdyn.GraphEvolution.java

/**
 * Creates a chart the style we like./*from w w  w .j ava 2 s. com*/
 * 
 * @param chart
 */
public static void setChartProperties(JFreeChart chart, List<SimpleEntry<Color, Stroke>> lineStyles) {
    // set the background and title font
    chart.setBackgroundPaint(Color.white);
    chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 14));
    // set the background and the grid all white
    XYPlot plot = chart.getXYPlot();
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setBackgroundPaint(Color.white);
    // now
    plot.setOutlineStroke(null);

    XYItemRenderer rend = plot.getRenderer();
    Stroke stroke = new BasicStroke(2.0f);
    rend.setBaseStroke(stroke);
    // rend.setDrawSeriesLineAsPath(true);

    // stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND,
    // BasicStroke.JOIN_ROUND, 10, new float[] {10, 10}, 0);
    // strokes.add(stroke);
    // stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND,
    // BasicStroke.JOIN_ROUND, 10, new float[] {2, 4}, 0);
    // strokes.add(stroke);
    int seriesCount = plot.getSeriesCount();
    for (int i = 0; i != seriesCount; i++) {
        SimpleEntry<Color, Stroke> lineStyle = lineStyles.get(i % lineStyles.size());
        rend.setSeriesStroke(i, lineStyle.getValue());
        rend.setSeriesPaint(i, lineStyle.getKey());
    }
}

From source file:mediamatrix.gui.JVMMemoryProfilerPanel.java

public JVMMemoryProfilerPanel() {
    initComponents();//from ww w.jav  a 2  s  .co m
    profiler = new JVMMemoryProfiler(frequency);
    profiler.addListener(new JVMMemoryProfilerListener() {

        @Override
        public void addScore(long t, long f) {
            total.add(new Millisecond(), t);
            free.add(new Millisecond(), f);
        }
    });

    total = new TimeSeries("Total Memory");
    total.setMaximumItemCount(historyCount);
    free = new TimeSeries("Free Memory");
    free.setMaximumItemCount(historyCount);

    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(total);
    dataset.addSeries(free);

    final DateAxis domain = new DateAxis("Time");
    final NumberAxis range = new NumberAxis("Memory");
    domain.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    domain.setLabelFont(new Font("SansSerif", Font.PLAIN, 14));
    range.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    range.setLabelFont(new Font("SansSerif", Font.PLAIN, 14));
    range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final XYItemRenderer renderer = new DefaultXYItemRenderer();
    renderer.setSeriesPaint(0, Color.red);
    renderer.setSeriesPaint(1, Color.green);
    renderer.setBaseStroke(new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));

    final XYPlot plot = new XYPlot(dataset, domain, range, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    domain.setAutoRange(true);
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setTickLabelsVisible(true);

    final JFreeChart chart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", Font.BOLD, 24), plot,
            true);
    chart.setBackgroundPaint(Color.white);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(Color.black)));
    chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 12));

    add(chartPanel, BorderLayout.CENTER);
}

From source file:charts.Chart.java

public static JFreeChart MultipleStepChartOverlayed(XYDataset[] datasets1, XYDataset[] datasets2, String title,
        String x_axis_label, String y_axis_label, boolean showlegend, float maxvalue, float minvalue,
        boolean showchart) {

    ValueAxis domainAxis = new NumberAxis(x_axis_label);
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ValueAxis rangeAxis = new NumberAxis(y_axis_label);
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    if (minvalue == 0 && maxvalue == 0) {
        rangeAxis.setAutoRange(true);//  ww  w.ja v a 2s .co m
    } else {
        rangeAxis.setRange(minvalue, maxvalue);
    }

    //define o grafo combinado, determinando o label do eixo x.
    CombinedDomainXYPlot parent = new CombinedDomainXYPlot(domainAxis);

    for (int i = 0; i < datasets1.length; i++) {
        XYItemRenderer renderer1 = new XYStepRenderer();
        renderer1.setBaseStroke(new BasicStroke(2.0f));
        renderer1.setBaseSeriesVisibleInLegend(showlegend);
        XYPlot subplot = new XYPlot(datasets1[i], domainAxis, rangeAxis, renderer1);
        subplot.setBackgroundPaint(Color.white);
        subplot.setRangeGridlinePaint(Color.black);
        subplot.setDomainGridlinesVisible(true);

        XYSplineRenderer renderer2 = new XYSplineRenderer();
        renderer2.setSeriesPaint(0, Color.LIGHT_GRAY);
        renderer2.setBaseStroke(new BasicStroke(2.0f));
        renderer2.setShapesVisible(true);
        renderer2.setBaseSeriesVisibleInLegend(false);
        subplot.setDataset(1, datasets2[i]);
        subplot.setRenderer(1, renderer2);
        parent.add(subplot, 1);
    }
    JFreeChart jfreechart = new JFreeChart(title, parent);
    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));

    if (showchart) {
        JFrame chartwindow = new JFrame(title);
        chartwindow.setContentPane(jpanel);
        chartwindow.pack();
        RefineryUtilities.centerFrameOnScreen(chartwindow);
        chartwindow.setVisible(true);
    }
    return jfreechart;
}

From source file:org.moeaframework.analysis.plot.Plot.java

/**
 * Modifies the line thickness or point size in the last dataset.  The
 * size is applied to all series in the dataset.
 * //from w  w w  . j  ava2 s  .  com
 * @param size the size
 * @return a reference to this {@code Plot} instance
 */
public Plot withSize(float size) {
    if (chart.getPlot() instanceof XYPlot) {
        XYPlot plot = chart.getXYPlot();
        XYItemRenderer renderer = plot.getRenderer(currentDataset);

        if (renderer instanceof XYDotRenderer) {
            ((XYDotRenderer) renderer).setDotWidth((int) (size * 2));
            ((XYDotRenderer) renderer).setDotHeight((int) (size * 2));
        } else if (renderer.getBaseStroke() instanceof BasicStroke) {
            BasicStroke oldStroke = (BasicStroke) renderer.getBaseStroke();

            BasicStroke newStroke = new BasicStroke(size, oldStroke.getEndCap(), oldStroke.getLineJoin(),
                    oldStroke.getMiterLimit(), oldStroke.getDashArray(), oldStroke.getDashPhase());

            renderer.setBaseStroke(newStroke);
        } else {
            renderer.setBaseStroke(new BasicStroke(size, 1, 1));
        }
    }

    return this;
}