Mountain Fill Chart - XYLine filled area underneath

Discussion about JFreeChart related to stockmarket charts.
Locked
philjhanna
Posts: 3
Joined: Thu Sep 15, 2005 4:52 pm

Mountain Fill Chart - XYLine filled area underneath

Post by philjhanna » Wed Dec 21, 2005 6:19 pm

Hi,
Does anyone know how to create an XY chart with a line one color and the area below semi transparent (alpha 50%) and gradient filled?

e.g. Like this http://studio.financialcontent.com/Char ... icker=JMAR

I've tried using XYAreaRenderer and XYAreaRenderer2 but can't get both the area colored and a seperate line. I also haven't seen how to make the area a gradient or give it an alpha transparency.

Any help on getting me closer to what I'm after would be very gratefully recieved.

Many Thanks,

Phil

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Dec 22, 2005 6:03 pm

You'll need a custom renderer. The following is a bit rough, but it will at least get you started:

Code: Select all

/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
 *
 * Project Info:  http://www.jfree.org/jfreechart/index.html
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 * USA.  
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 *
 * ---------------------
 * MyXYAreaRenderer.java
 * ---------------------
 * (C) Copyright 2005, by Object Refinery Limited.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited);
 * Contributor(s):   -;
 *
 * $Id: XYAreaRenderer.java,v 1.12.2.5 2005/12/22 15:53:05 mungady Exp $
 *
 * Changes:
 * --------
 * 22-Dec-2005 : Version 1 (DG);
 * 
 * 
 */

import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;

import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.entity.EntityCollection;

import org.jfree.chart.entity.XYItemEntity;
import org.jfree.chart.labels.XYToolTipGenerator;
import org.jfree.chart.plot.CrosshairState;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYAreaRenderer;
import org.jfree.chart.renderer.xy.XYItemRendererState;
import org.jfree.chart.urls.XYURLGenerator;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.GradientPaintTransformer;
import org.jfree.ui.StandardGradientPaintTransformer;
import org.jfree.util.ShapeUtilities;

/**
 * Custom renderer.
 */
public class MyXYAreaRenderer extends XYAreaRenderer {

    /**
     * A state object used by this renderer.
     */
    static class XYAreaRendererState extends XYItemRendererState {
        
        /** Working storage for the area under one series. */
        public Polygon area;
        
        /** Working line that can be recycled. */
        public Line2D line;
        
        /**
         * Creates a new state.
         * 
         * @param info  the plot rendering info.
         */
        public XYAreaRendererState(PlotRenderingInfo info) {
            super(info);
            this.area = new Polygon();
            this.line = new Line2D.Double();
        }
        
    }

    /**
     * Constructs a new renderer.
     */
    public MyXYAreaRenderer() {
        this(AREA);
    }

    /**
     * Constructs a new renderer.
     *
     * @param type  the type of the renderer.
     */
    public MyXYAreaRenderer(int type) {
        this(type, null, null);
    }

    /**
     * Constructs a new renderer.
     * <p>
     * To specify the type of renderer, use one of the constants: SHAPES, LINES,
     * SHAPES_AND_LINES, AREA or AREA_AND_SHAPES.
     *
     * @param type  the type of renderer.
     * @param toolTipGenerator  the tool tip generator to use 
     *                          (<code>null</code> permitted).
     * @param urlGenerator  the URL generator (<code>null</code> permitted).
     */
    public MyXYAreaRenderer(int type, XYToolTipGenerator toolTipGenerator, 
                            XYURLGenerator urlGenerator) {

        super(type, toolTipGenerator, urlGenerator);
    }

    /**
     * Initialises the renderer and returns a state object that should be 
     * passed to all subsequent calls to the drawItem() method.
     *
     * @param g2  the graphics device.
     * @param dataArea  the area inside the axes.
     * @param plot  the plot.
     * @param data  the data.
     * @param info  an optional info collection object to return data back to 
     *              the caller.
     *
     * @return A state object for use by the renderer.
     */
    public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea,
            XYPlot plot, XYDataset data, PlotRenderingInfo info) {
        XYAreaRendererState state = new XYAreaRendererState(info);
        return state;
    }

    /**
     * Draws the visual representation of a single data item.
     *
     * @param g2  the graphics device.
     * @param state  the renderer state.
     * @param dataArea  the area within which the data is being drawn.
     * @param info  collects information about the drawing.
     * @param plot  the plot (can be used to obtain standard color information 
     *              etc).
     * @param domainAxis  the domain axis.
     * @param rangeAxis  the range axis.
     * @param dataset  the dataset.
     * @param series  the series index (zero-based).
     * @param item  the item index (zero-based).
     * @param crosshairState  crosshair information for the plot 
     *                        (<code>null</code> permitted).
     * @param pass  the pass index.
     */
    public void drawItem(Graphics2D g2, XYItemRendererState state,
            Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
            ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
            int series, int item, CrosshairState crosshairState, int pass) {
        
        if (!getItemVisible(series, item)) {
            return;   
        }
        XYAreaRendererState areaState = (XYAreaRendererState) state;
        
        // get the data point...
        double x1 = dataset.getXValue(series, item);
        double y1 = dataset.getYValue(series, item);
        if (Double.isNaN(y1)) {
            y1 = 0.0;
        }
        double transX1 = domainAxis.valueToJava2D(x1, dataArea, 
                plot.getDomainAxisEdge());
        double transY1 = rangeAxis.valueToJava2D(y1, dataArea, 
                plot.getRangeAxisEdge());
        
        // get the previous point and the next point so we can calculate a 
        // "hot spot" for the area (used by the chart entity)...
        int itemCount = dataset.getItemCount(series);
        double x0 = dataset.getXValue(series, Math.max(item - 1, 0));
        double y0 = dataset.getYValue(series, Math.max(item - 1, 0));
        if (Double.isNaN(y0)) {
            y0 = 0.0;
        }
        double transX0 = domainAxis.valueToJava2D(x0, dataArea, 
                plot.getDomainAxisEdge());
        double transY0 = rangeAxis.valueToJava2D(y0, dataArea, 
                plot.getRangeAxisEdge());
        
        double x2 = dataset.getXValue(series, Math.min(item + 1, 
                itemCount - 1));
        double y2 = dataset.getYValue(series, Math.min(item + 1, 
                itemCount - 1));
        if (Double.isNaN(y2)) {
            y2 = 0.0;
        }
        double transX2 = domainAxis.valueToJava2D(x2, dataArea, 
                plot.getDomainAxisEdge());
        double transY2 = rangeAxis.valueToJava2D(y2, dataArea, 
                plot.getRangeAxisEdge());
        
        double transZero = rangeAxis.valueToJava2D(0.0, dataArea, 
                plot.getRangeAxisEdge());
        Polygon hotspot = null;
        if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
            hotspot = new Polygon();
            hotspot.addPoint((int) transZero, 
                    (int) ((transX0 + transX1) / 2.0));
            hotspot.addPoint((int) ((transY0 + transY1) / 2.0), 
                    (int) ((transX0 + transX1) / 2.0));
            hotspot.addPoint((int) transY1, (int) transX1);
            hotspot.addPoint((int) ((transY1 + transY2) / 2.0), 
                    (int) ((transX1 + transX2) / 2.0));
            hotspot.addPoint((int) transZero, 
                    (int) ((transX1 + transX2) / 2.0));
        }
        else {  // vertical orientation
            hotspot = new Polygon();
            hotspot.addPoint((int) ((transX0 + transX1) / 2.0), 
                    (int) transZero);
            hotspot.addPoint((int) ((transX0 + transX1) / 2.0), 
                    (int) ((transY0 + transY1) / 2.0));
            hotspot.addPoint((int) transX1, (int) transY1);
            hotspot.addPoint((int) ((transX1 + transX2) / 2.0), 
                    (int) ((transY1 + transY2) / 2.0));
            hotspot.addPoint((int) ((transX1 + transX2) / 2.0), 
                    (int) transZero);
        }
        
        if (item == 0) {  // create a new area polygon for the series
            areaState.area = new Polygon();
            // the first point is (x, 0)
            double zero = rangeAxis.valueToJava2D(0.0, dataArea, 
                    plot.getRangeAxisEdge());
            if (plot.getOrientation() == PlotOrientation.VERTICAL) {
                areaState.area.addPoint((int) transX1, (int) zero);
            }
            else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
                areaState.area.addPoint((int) zero, (int) transX1);
            }
        }

        // Add each point to Area (x, y)
        if (plot.getOrientation() == PlotOrientation.VERTICAL) {
            areaState.area.addPoint((int) transX1, (int) transY1);
        }
        else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
            areaState.area.addPoint((int) transY1, (int) transX1);
        }
        
        PlotOrientation orientation = plot.getOrientation();
        Paint paint = getItemPaint(series, item);
        Stroke stroke = getItemStroke(series, item);
        g2.setPaint(paint);
        g2.setStroke(stroke);
        
        Shape shape = null;
        if (getPlotShapes()) {
            shape = getItemShape(series, item);
            if (orientation == PlotOrientation.VERTICAL) {
                shape = ShapeUtilities.createTranslatedShape(shape, transX1, 
                        transY1);
            }
            else if (orientation == PlotOrientation.HORIZONTAL) {
                shape = ShapeUtilities.createTranslatedShape(shape, transY1, 
                        transX1);
            }
            g2.draw(shape);
        }

        if (getPlotLines()) {
            if (item > 0) {
                if (plot.getOrientation() == PlotOrientation.VERTICAL) {
                    areaState.line.setLine(transX0, transY0, transX1, transY1);
                }
                else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
                    areaState.line.setLine(transY0, transX0, transY1, transX1);
                }
                g2.draw(areaState.line);
            }
        }

        // Check if the item is the last item for the series.
        // and number of items > 0.  We can't draw an area for a single point.
        if (getPlotArea() && item > 0 && item == (itemCount - 1)) {

            if (orientation == PlotOrientation.VERTICAL) {
                // Add the last point (x,0)
                areaState.area.addPoint((int) transX1, (int) transZero);
            }
            else if (orientation == PlotOrientation.HORIZONTAL) {
                // Add the last point (x,0)
                areaState.area.addPoint((int) transZero, (int) transX1);
            }

            Paint fillPaint = getItemFillPaint(series, item);
            if (fillPaint instanceof GradientPaint) {
                GradientPaint gp = (GradientPaint) fillPaint;
                GradientPaintTransformer t = new StandardGradientPaintTransformer();
                fillPaint = t.transform(gp, areaState.area.getBounds());
            }
            g2.setPaint(fillPaint);
            g2.fill(areaState.area);

            // draw an outline around the Area.
            if (isOutline()) {
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.setPaint(getItemOutlinePaint(series, item));
                g2.draw(areaState.area);
            }
        }

        updateCrosshairValues(
            crosshairState, x1, y1, transX1, transY1, orientation
        );
        
        // collect entity and tool tip information...
        if (state.getInfo() != null) {
            EntityCollection entities = state.getEntityCollection();
            if (entities != null && hotspot != null) {
                String tip = null;
                XYToolTipGenerator generator 
                    = getToolTipGenerator(series, item);
                if (generator != null) {
                    tip = generator.generateToolTip(dataset, series, item);
                }
                String url = null;
                if (getURLGenerator() != null) {
                    url = getURLGenerator().generateURL(dataset, series, item);
                }
                XYItemEntity entity = new XYItemEntity(hotspot, dataset, 
                        series, item, tip, url);
                entities.add(entity);
            }
        }

    }

}
And a demo program:

Code: Select all

/* ---------------------
 * XYAreaChartDemo3.java
 * ---------------------
 * (C) Copyright 2005, by Object Refinery Limited.
 *
 * Changes
 * -------
 * 22-Dec-2005 : Version 1 (DG);
 *
 */

package demo;

import MyXYAreaRenderer;

import java.awt.Color;
import java.awt.GradientPaint;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;

import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/**
 * A simple demonstration application showing how to create an area chart with 
 * a date axis for the domain values.
 */
public class XYAreaChartDemo3 extends ApplicationFrame {

    /**
     * Creates a new demo.
     *
     * @param title  the frame title.
     */
    public XYAreaChartDemo3(String title) {
        super(title);
        JPanel chartPanel = createDemoPanel();
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);
    }
    
    private static XYDataset createDataset() {
        TimeSeries series1 = new TimeSeries("Random 1");
        double value = 0.0;
        Day day = new Day();
        for (int i = 0; i < 50; i++) {
            value = value + Math.random() - 0.5;
            series1.add(day, value);
            day = (Day) day.next();
        }
        TimeSeriesCollection dataset = new TimeSeriesCollection(series1);
        return dataset;    
    }
    
    /**
     * Creates a chart.
     * 
     * @param dataset  the dataset.
     * 
     * @return The chart.
     */
    private static JFreeChart createChart(XYDataset dataset) {
        JFreeChart chart = ChartFactory.createXYAreaChart(
            "XY Area Chart Demo 3",
            "Time", "Value",
            dataset,
            PlotOrientation.VERTICAL,
            false,  // legend
            false,  // tool tips
            false  // URLs
        );
        XYPlot plot = (XYPlot) chart.getPlot();
        MyXYAreaRenderer renderer = new MyXYAreaRenderer();
        plot.setRenderer(0, renderer);
        renderer.setSeriesFillPaint(0, new GradientPaint(0f, 0f, Color.green, 0f, 0f, Color.blue));
        renderer.setOutline(true);
        renderer.setSeriesOutlinePaint(0, Color.black);
        ValueAxis domainAxis = new DateAxis("Time");
        domainAxis.setLowerMargin(0.0);
        domainAxis.setUpperMargin(0.0);
        plot.setDomainAxis(domainAxis);
        plot.setForegroundAlpha(0.5f);  
        
        renderer.setToolTipGenerator(new StandardXYToolTipGenerator(
                StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                new SimpleDateFormat("d-MMM-yyyy"), 
                new DecimalFormat("#,##0.00")));
        return chart;      
    }
    
    /**
     * Creates a panel for the demo.
     *  
     * @return A panel.
     */
    public static JPanel createDemoPanel() {
        return new ChartPanel(createChart(createDataset()));
    }
    
    /**
     * Starting point for the demonstration application.
     *
     * @param args  ignored.
     */
    public static void main(String[] args) {
        XYAreaChartDemo3 demo = new XYAreaChartDemo3("XY Area Chart Demo 3");
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);
    }

}
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

philjhanna
Posts: 3
Joined: Thu Sep 15, 2005 4:52 pm

Post by philjhanna » Tue Jan 03, 2006 11:21 pm

My word thats absolutely perfect. Exactly what I wanted.

Thank you Dave.

Cheers,

Phil

Derek

Help

Post by Derek » Mon Jan 23, 2006 1:45 pm

Hi Phil,

I am a newie to Jfree. I encounter some problems when I try to compile XYAreaRenderer2 (note: it is not compliled when I downloaded the package).

Error as below:
-------------------------------------------------------------------------------------
C:\SourceCode\java\org\jfree\chart\renderer\xy\XYAreaRenderer2.java:410: cannot resolve symbol
symbol : method getEntityCollection ()
location: class org.jfree.chart.renderer.xy.XYItemRendererState
EntityCollection entities = state.getEntityCollection();
^
1 error

Tool completed with exit code 1
------------------------------------------------------------------------------

Can you tell me how to solve the above problem?

Could you please send me the XYAreaRenderer2.class file ?

Also the StackedXYAreaRenderer2.class file


Many Thanks
Derek

Derek

More Help

Post by Derek » Mon Jan 23, 2006 2:04 pm

Hi Phil,

My email is

zhengting11@yahoo.co.uk

Many Thanks
Derek

pelski
Posts: 16
Joined: Thu Feb 23, 2006 2:02 am

XYStepAreaChart different seriesOutlineColors to seriesFillC

Post by pelski » Thu Feb 23, 2006 2:36 am

Does anyone know how to do exactly the same, but instead to plot
an XYStepAreaChart ?

I have the same problem, in that using the current implementation of XYStepAreaRenderer, whenever I call setSeriesOutlinePaint() or setSeriesFillePaint(), the default colors are always used instead of those I set. It seems not possible to set the outline paint different to the fill paint for a specific series using a XYStepAreaRenderer.

Has anyone managed to do this?

igorlf
Posts: 14
Joined: Fri Mar 17, 2006 6:40 pm

Post by igorlf » Fri Mar 31, 2006 5:33 pm

David,
your example works fine for a linear graphic, but dosen't work when i use plot.setRangeAxis(new LogarithmicAxis("")); what i need to do???

this is the printstacktrace:
sun.dc.pr.PRException: endPath: bad path
at sun.dc.pr.Rasterizer.endPath(Unknown Source)
at sun.java2d.pipe.DuctusRenderer.createShapeRasterizer(Unknown Source)
at sun.java2d.pipe.DuctusShapeRenderer.renderPath(Unknown Source)
at sun.java2d.pipe.DuctusShapeRenderer.fill(Unknown Source)
at sun.java2d.pipe.ValidatePipe.fill(Unknown Source)
at sun.java2d.SunGraphics2D.fill(Unknown Source)
at MyXYAreaRenderer.drawItem(MyXYAreaRenderer.java:297)
at org.jfree.chart.plot.XYPlot.render(XYPlot.java:2640)
at org.jfree.chart.plot.XYPlot.draw(XYPlot.java:2218)
at org.jfree.chart.JFreeChart.draw(JFreeChart.java:1039)
at org.jfree.chart.ChartPanel.paintComponent(ChartPanel.java:1274)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

cobragtk
Posts: 11
Joined: Fri Jan 23, 2009 7:07 pm

Post by cobragtk » Mon Jan 26, 2009 8:24 am

Hi all,
I am interested in creating the same type of chart featured in the link from original post. I tried to repost the link but as a new user was not allowed. In any case the link is still active and can be found in the original post.

The chart that I want to create specifically has the following features:

- a stroked series line and the XY Area beneath the series line being filled with a 90 degree linear gradient.

I was able to create an XYAreaChart with a stroked series line but that's about as far as I got. I then came across David's sample code, MyXYAreaRenderer and XYAreaChartDemo3. However when I try to compile the code I get the following errors:

I am using JFREECHART: Version 1.0.12.

BIGMAC:~/Documents/workspace/MyJFreeChartApp cobragtk$ javac -Xlint -d bin src/com/bstonetech/chart/MyXYAreaRenderer.java
warning: [path] bad path element "/jfreechart-1.0.12/lib/iText-toolbox.jar": no such file or directory
warning: [path] bad path element "/jfreechart-1.0.12/lib/iText-toolbox-2.1.3.jar": no such file or directory
warning: [path] bad path element "/jfreechart-1.0.12/lib/bcmail-jdk14-138.jar": no such file or directory
warning: [path] bad path element "/jfreechart-1.0.12/lib/bcprov-jdk14-138.jar": no such file or directory
warning: [path] bad path element "jfreechart-1.0.12-experimental.jar": no such file or directory
src/com/bstonetech/chart/MyXYAreaRenderer.java:285: warning: [deprecation] updateCrosshairValues(org.jfree.chart.plot.CrosshairState,double,double,double,double,org.jfree.chart.plot.PlotOrientation) in org.jfree.chart.renderer.xy.AbstractXYItemRenderer has been deprecated
updateCrosshairValues(
^
src/com/bstonetech/chart/MyXYAreaRenderer.java:32: warning: [serial] serializable class com.bstonetech.chart.MyXYAreaRenderer has no definition of serialVersionUID
public class MyXYAreaRenderer extends XYAreaRenderer {
^
7 warnings

Any help that would enable me to create this type of chart would be greatly appreciated. Thank you in advance,

Simon

cobragtk
Posts: 11
Joined: Fri Jan 23, 2009 7:07 pm

Post by cobragtk » Mon Jan 26, 2009 8:38 pm

Hi everyone,
Ok, so a little effort and I fixed my problems and got David's code samples to work. The bad path element warnings through me off.

To run against JFreeChart Version 1.0.12, I did the following:

1) In both files, XYAreaChartDemo3 and MyXYAreaRenderer I added a static final serialVersionUID field of type long.

2) In MyXYAreaRenderer I updated the updateCrosshairValues method call with the one from the XYAreaRenderer class (JFreeChart Version 1.0.12).

3) In XYAreaChartDemo3 I changed the call to renderer.setToolTipGenerator to renderer.setBaseToolTipGenerator

And now voila, I see a wonderful area chart with gradient fill and outline stroke.

Thanks,
Simon

cobragtk
Posts: 11
Joined: Fri Jan 23, 2009 7:07 pm

Post by cobragtk » Tue Jan 27, 2009 2:27 am

Hi everyone,
I have 2 questions in regards to the image of my chart that I have posted below.
Image

1) If you look closely there is a white stroke on the series, I set this using:
- setSeriesOutlineStroke
It seems that this strokes the whole Shape area, as you will notice that on the right and left sides of the shape area there is a few pixels of white showing. This white area increases on both the left and right sides as I increase the weight of the stroke. Does anyone know how I can remove this?

2) In my Stroke object that I use for the series line, I am setting the join to BasicStroke.JOIN_ROUND. More specifically I do this:
- Stroke stroke = new BasicStroke(6, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND);

However I noticed that the chart image posted in the first post of this thread has really curved lines between each data point. Is there a way to achieve this?

Thank you in advance,
Simon

lourencohen
Posts: 1
Joined: Tue Feb 25, 2014 1:01 pm
antibot: No, of course not.

Re: Mountain Fill Chart - XYLine filled area underneath

Post by lourencohen » Tue Feb 25, 2014 1:14 pm

I was also using XYAreaRenderer earlier for the graph creation, but the second one XYAreaRenderer2 is more effcetive when we compared with the earlier one. So try using the XYAreaRenderer2 to build the graph with colors. Hope that helps.



Thanks
windows live mail tech

Locked