Creating a map chart

A new type of chart available in Application Express 4.0 is the map chart. This allows users to present data on a geographical map. APEX 4.0 offers many maps from a world overview to maps of single countries.

Map charts allow applications a new way to visualize location-related data without much programming.

In this recipe, we will show you how to create a map that lists all contacts in the United States by state.

Getting ready

First we need to have a structure ready in our database tables that holds at least one geographical related column (for example, country, state, or province names). This will be the pointer for our chart to which it can relate its map.

For this recipe, we will reuse the APP_VW_CONTACTS view. This view holds a column called STATE that we can use in our chart.

How to do it...

Our starting point is again an empty page. The first thing to do is to add a new region.

  1. Right-click on Regions and select Create.
  2. Select Map as the Region Type.

    This will bring up a window with a couple of main categories of maps. Selecting one of these categories will bring up a list of sub-categories that can be drilled-down even further.

  3. Select United States of America and click Next.
    How to do it...
  4. In the following list select States:
    How to do it...
  5. Enter Contacts by State for the title and leave the rest on default and click Next.
  6. Enter the same text as the Map Title.
  7. Enter the following query in the appropriate SQL Query area:
    select null link
    , STATE label
    , COUNT(CONTACT_ID) value
    from APP_VW_CONTACTS
    group by STATE
    [1346_01_06.txt]
    
  8. Click Create Region.
  9. Run the page to see the result.
How to do it...

As we can see, each state that contains one or more contacts is highlighted. APEX also generates labels containing the state name and number of contacts if there is room for it. The other labels can be viewed by hovering over the state with the mouse pointer.

How it works...

Application Express uses AnyChart 5 for displaying its charts. This is different from earlier versions of APEX, so migrating applications that make use of charts from version 3.x to 4.0 is a little more complicated than migrating other functionality.

When using a Map chart it is important that a column for the label is used that contains the name of the geographical region that you want highlighted on the map. For the standard maps provided by APEX, it's not allowed to use abbreviations, but it has to be the full name (for example, New York instead of NY and Virginia instead of VA).

There's more...

Just like any other chart type it is possible to create links to other pages. This can be used to create, for instance, a drill down type of structure. We could create a series of pages from a world map, to a continent map, to a country map, and so forth.

How such a link can be created is explained in the chart recipe before this one.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.246.223