new chart type "geographical chart"

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
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 Mar 08, 2007 6:00 pm

david.gilbert wrote:I'm not sure what I'd use it for, so if you could put together a realistic demo, that would be helpful.
Scrub that - I see at the top of this thread you already showed something useful.
David Gilbert
JFreeChart Project Leader

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

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Post by matinh » Fri Mar 09, 2007 10:16 am

david.gilbert wrote:I tried the renderer. By accident, I noticed that it doesn't work when the plot orientation is horizontal. Otherwise it seems fine.
Ok, I'll try to fix this.
david.gilbert wrote:I think there may be a problem in the clone() method in XYBlockRenderer (the paint scale needs to be cloned too) which you've carried across to the XYShapeRenderer. That's easy to fix though.
Did you fix this already in XYBlockRenderer? If you did we probably just need to copy the clone() method from there. Or even better, share this code via some abstract base class.

- martin

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Post by matinh » Fri Mar 09, 2007 1:38 pm

Hi!

Fixed the PlotOrientation problem in XYShapeRenderer. Didn't fix the clone() bug. The thing that changed to the version posted earlier is only the drawItem() method. Here is the fixed version:

Code: Select all

    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)
    {
        Shape entityArea = null;
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }

        if (dataset.getX(series, item) == null || dataset.getY(series, item) == null)
            // cannot draw anything.
            return;
        
        double x = dataset.getXValue(series, item);
        double y = dataset.getYValue(series, item);
        double z = 0.0;
        if (dataset instanceof XYZDataset) {
            z = ((XYZDataset) dataset).getZValue(series, item);
        }
        Paint p = this.paintScale.getPaint(z);

        Double xx0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
        Double yy0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());

        Shape drawShape;
        Rectangle2D bounds = getSeriesShape(series).getBounds2D();
        if (plot.getOrientation().equals(PlotOrientation.HORIZONTAL)) {
            drawShape = ShapeUtilities.createTranslatedShape(getSeriesShape(series), yy0 - bounds.getWidth() / 2, xx0 - bounds.getHeight() / 2);
            drawShape = ShapeUtilities.rotateShape(drawShape, Math.PI / 2, yy0.floatValue(), xx0.floatValue());
        }
        else {
            drawShape = ShapeUtilities.createTranslatedShape(getSeriesShape(series), xx0 - bounds.getWidth() / 2, yy0 - bounds.getHeight() / 2);
        }
        entityArea = drawShape;

        g2.setPaint(p);
        g2.fill(drawShape);

        g2.setStroke(new BasicStroke());
        g2.setPaint(Color.gray);
        g2.draw(drawShape);

        // add an entity for the item...
        if (entities != null) {
            addEntity(entities, entityArea, dataset, series, item, xx0, yy0);
        }
    }

carlgoebel
Posts: 3
Joined: Tue Sep 11, 2007 10:18 pm
Location: Portland, OR
Contact:

Has anyone tried this out?

Post by carlgoebel » Tue Sep 11, 2007 10:23 pm

I recently implemented a historical flight performance reporting tool using Jasper, JFreeChart, and OpenReports. I would like to add a new Geographic chart type which will display flight delays at airports around the globe. I have latitude/longitude for all the airports that I want to map. From reading this thread, it sounds like this is all still very new. I am wondering if anyone has tried it for a similar need and how it worked?

Thanks!
-Carl

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Post by matinh » Wed Sep 12, 2007 8:46 am

Some time ago I posted some code to this forum but it seems it didn't make into JFreeChart till now :-(

You can have a look at what we achieved with JFreeChart and the new geo-charts at http://www.numbis.at/messwerte/ (sorry, the page is only available in German).

If you are interessted I can make the latest version of our added JFreeChart classes available. Let me know.

hth,
- martin

carlgoebel
Posts: 3
Joined: Tue Sep 11, 2007 10:18 pm
Location: Portland, OR
Contact:

Yes...

Post by carlgoebel » Wed Sep 12, 2007 6:01 pm

Please make available your latest code - I would like to spend a day or two giving it a try. I wonder how well it will work with a much larger map (i.e. all of North America, or all of Europe). Thanks Martin!

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Geochart Extension 0.2 available

Post by matinh » Thu Sep 13, 2007 8:38 am

Hi all!

The source code and a packaged version of the geochart extension are available for download at http://www.xss.co.at/~martin/jfreechart/
(use the 0.2 version!)

For a simple test call

Code: Select all

java at.co.xss.jfree.sample.Example
and make sure the following JARs are in your classpath:
  • jfreechart-1.0.4.jar
    jfreechart-experimental-1.0.4.jar
    jcommon-1.0.8.jar
    jfree-geo-0.2.jar
Note: The old version 1.0.4 of JFreeChart is still required! It should be no problem, though, to port it to 1.0.6. It's just that some classes moved from experimental to the normal package and I didn't find some time to adapt this.

Feedback is welcome!

hth,
- martin

carlgoebel
Posts: 3
Joined: Tue Sep 11, 2007 10:18 pm
Location: Portland, OR
Contact:

Implemented with large-scale maps

Post by carlgoebel » Fri Oct 19, 2007 1:59 am

Thanks Martin, Dave, and all who contributed!
I would like to share with you the charts I have created using this code, modified slightly to accomodate large-scale maps.

As expected, the linear calculations of 2D points in XYShapeRenderer.drawItem() did not work well with a map of the entire United States. Latitude and longitude are 3-dimensional coordinates (earth is round), and 2D maps are stretched flat using complex mathematical equations known as "projections". The most common projection is the Mercator Projection. These 2D maps tend to exaggerate the size of objects closer to the poles. As a result, the linear calculations caused my plotted points to become increasingly distorted as they got further away from the equator (in this case North).

I found a way to correct this problem by using JH Labs' Java Map Projection Library (a partial java port of the PROJ.4 library). It can be found here: http://www.jhlabs.com/java/maps/proj/

Once I hooked up the code to call the Mercator projection transformation in PROJ.4, everything worked great. I transformed the top left & bottom right boundaries as well as all the points I wished to plot. Then ran the original linear calculations to get the exact plot coordinates.

Here is a snippet from my modified XYShapeRenderer.java -> drawItem():
double minLat = 22.86;
double maxLat = 50.8;
double minLong = -128.4;
double maxLong = -59.7;

Projection proj = new MercatorProjection();
proj.setMinLatitude(minLat);
proj.setMaxLatitude(maxLat);
proj.setMinLongitude(minLong);
proj.setMaxLongitude(maxLong);
proj.setEllipsoid(Ellipsoid.WGS_1984);
proj.initialize();

Point2D.Double t = new Point2D.Double();
t = proj.transform(new Point2D.Double(x, y), t);

Double xx0 = domainAxis.valueToJava2D(t.getX(), dataArea,
plot.getDomainAxisEdge());
Double yy0 = rangeAxis.valueToJava2D(t.getY(), dataArea,
plot.getRangeAxisEdge());



I have 2 images I would like to post here to show you my results. One is before I ran the PROJ.4 conversions and one is after. I don't have a web server to throw these up on. If someone could let me know the best way to post these images here that would be great.

Thanks again for everyone's contributions. I think this would make a great addition to a future version of JFreeChart.

-Carl Goebel
Portland, OR


[/img]

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 » Fri Oct 19, 2007 2:47 pm

If you e-mail me the images (david.gilbert@object-refinery.com) I'll upload them to jfree.org and display them here.
David Gilbert
JFreeChart Project Leader

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

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 » Fri Oct 19, 2007 5:18 pm

Here's the images:

BEFORE PROJECTION:
Image

AFTER PROJECTION:
Image
David Gilbert
JFreeChart Project Leader

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

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 » Fri Oct 19, 2007 5:19 pm

Nice charts, by the way! I'm trying really hard to get 1.0.7 out the door, but lets try to schedule this stuff for inclusion in 1.0.8 before the end of the year.
David Gilbert
JFreeChart Project Leader

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

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Post by matinh » Mon Oct 22, 2007 12:30 pm

Hi David!

This sounds cool! Let me know when you're ready for this and you need any help. I'd really like to see this included in JFreeChart!

- martin

Andrew Foss
Posts: 36
Joined: Thu Apr 12, 2007 6:54 am

Geo plotting

Post by Andrew Foss » Mon Nov 05, 2007 2:07 pm

Martin,

have you continued progress on this? I started a simliar tack, extending an XYDataset, I really only need 2D for starters to do lat/longs, as either decimal or minutes/seconds and draw a simple XYPlot over a chart image background w/ an anchor value lat/long. The plot has no axes and I was using the XYLineAndShapeRenderer and XYImageAnnotations to put up icons, shapes or lines at various locations.

If this is similar to what you've already done, maybe we could put it together?

thanks,
andrew

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Post by matinh » Mon Nov 05, 2007 2:32 pm

Hi Andrew!

What I've done so far on this topic is documented in this thread and the code is available for download. You can also see some charts at http://www.numbis.at/. See previous posts for more details.

David wrote in a post that he has plans to integrate some of this work after the release of 1.0.7. If help is needed for this I'll do what I can. But for the moment my enhancement fulfills my requirements and I don't have the time to investigate any further, sorry.

best regards and good luck,
- martin

vidyacho
Posts: 1
Joined: Tue Nov 06, 2007 12:35 pm

jfree-geo-0.2.jar

Post by vidyacho » Tue Nov 06, 2007 12:36 pm

I cant find jfree-geo-0.2.jar

where do i download it from

Locked