QlikView for Developers Cookbook
上QQ阅读APP看书,第一时间看更新

Brushing parallel coordinates

Parallel coordinates is a long established method of visualizing multivariate data. QlikView will display a parallel coordinate chart and a user can interact with the data, but sometimes it is useful to allow the user to "brush" the data, selecting different values and seeing those values versus the whole of the data.

We can do this by using two almost identical charts with one being transparent and sitting over the other.

Getting ready

We need to download some data for this from the United States Census QuickFacts website. Go to http://quickfacts.census.gov/qfd/download_data.html and download the first three files on offer:

Load the following script:

// Cross table the raw data into a temp table
Temp_Data:
CrossTable(MetricCode, Value)
LOAD *
FROM
DataSet.txt
(txt, codepage is 1252, embedded labels, delimiter is ',', msq);

// Load the temp table into our data table.
// Only load county information.
// Only load RHI data (Resident Population).
Data:
NoConcatenate
Load
  fips,
  MetricCode,
  Value
Resident Temp_Data
Where Mod(fips, 1000) <> 0  // Only County
And MetricCode Like 'RHI*'; // Only RHI

// Drop the temporary table
Drop Table Temp_Data;

// Load the location information.
// Use LEFT to only load locations that match Data.
Location:
Left Keep (Data)
LOAD @1:5 as fips, 
     @6:n as Location
FROM
FIPS_CountyName.txt
(fix, codepage is 1252);

// Load the Metric information
// Use LEFT to only load metrics that match Data.
Metrics:
Left Keep (Data)
LOAD @1:10 As MetricCode, 
     Trim(SubField(SubField(@11:115, ':', 2), ',', 1)) as Metric, 
     @116:119 as Unit, 
     @120:128 as Decimal, 
     @129:140 as US_Total, 
     @141:152 as Minimum, 
     @153:164 as Maximum, 
     @165:n as Source
FROM
DataDict.txt
(fix, codepage is 1252, embedded labels);

How to do it…

To create a parallel coordinates chart with brushing, perform the following steps:

  1. Add a list box for Location onto the layout.
  2. Create a new line chart. Add Metric and Location as dimensions.
  3. Add the following expression:
    Avg({<Location={*}>} Value)
  4. Label the expression as %.
  5. Click on the + sign beside the expression and enter the following expression for Background Color:
    LightGray()
  6. On the Sort tab, set the sort for the Metric dimension to Load Order and Original as shown in the following screenshot:
  7. On the Presentation tab, turn off the Suppress Zero-Values and Suppress Missing options. Also, turn off the Show Legend option:
  8. On the Axes tab, turn on the Static Max option and set it to 101. Set the Primary Dimension Labels option to /. Turn on the Show Grid option under Dimension Axis:
  9. Click on Finish.
  10. Right-click on the chart and select Clone from the menu. Position the new chart so it exactly overlaps the first. Edit the properties.
  11. On the Expressions tab, modify the expression:
    Avg(Value)
  12. Click on the + sign beside the expression and change the Background Color property to:
    Blue()
  13. On the Colors tab, set the Transparency option to 100%.
  14. On the Layout tab, set the Layer option to Top. Set the Show option to Conditional and enter the following expression:
    GetSelectedCount(Location)>0
  15. Click on OK.
    Note

    Note that when you make a selection on the chart or in the list box, the selection is highlighted or "brushed".

How it works…

The transparent chart with the slightly different color and expression is the trick here. When a selection is made, our chart overlays the first chart and displays the "brush". The underlying chart will remain the same as we have a set that excludes selections in the Location field.

As far as the user is concerned, there is only one chart being displayed.

There's more…

Using transparent charts to overlay another chart is a great technique to use when the particular visualization is just not available in QlikView.

See also

  • The Creating a "Stephen Few" bullet chart recipe