DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How To Create a Network Graph Using JavaScript
  • How To Create a Resource Chart in JavaScript
  • How to Build a Treemap Using JavaScript
  • How to Create a Mosaic Chart Using JavaScript

Trending

  • When Feature Flags Become Workflows: Configuring Multi-Tenant State Machines
  • Searching Kafka Without an Index: Lessons From Building Message Search for Kafdrop
  • How to Keep AI Agents From Going Rogue Using Docker Sandbox
  • A Reference Architecture for Constrained AI-Assisted Design

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Data
  4. Data Visualization Tutorial: How to Create a Parliament Chart

Data Visualization Tutorial: How to Create a Parliament Chart

In this post, we quickly go over the JavaScript and CSS necessary to create really interesting data visualizations for this chart type.

By 
Mustapha Mekhatria
·
Jun. 17, 19 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
17.6K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

While reading the newspaper or watching TV, you will quickly learn that where there is politics, there is statistics. Countless polls and election results have been brought to life with pie, column, line, maps, and other common chart types offered by Highcharts.

But Highcharts also provides publishers with a specialized chart type for displaying the composition of a legislative body, such as Parliament, the Senate, or the House of Representatives.

Here is a quick tutorial on how to use the Parliament chart, also known as item chart or Arc-shaped Parliament Diagram. Like all Highcharts, it is dynamic, responsive, and interactive.

The demo below displays the House of Commons of the United Kingdom:

It is very straight forward to set up a parliament chart; all you have to do is to structure the data and to create the shape.

Data Structure

To structure the data just use the following format:

['name of the party', 'Number of seats', 'color', 'label']

Here is the data used for the demo above:

        ['Conservative', 313, '#0087DC', 'Conservative'],
        ['Labour', 256, '#DC241f', 'Labour'],
        ['Scottish National Party', 35, '#FDF38E', 'Scottish National Party'],
        ['The Independent Group', 11, '#009EE0', 'The Independent Group'],
        ['Liberal Democrat', 11, '#FAA61A', 'Liberal Democrat'],
        ['Democratic Unionist Party', 10, '#D46A4C', 'Democratic Unionist Party'],
        ['Independent', 10, '#DDDDDD', 'Independent'],
        ['Sinn Féin', 7, '#326760', 'Sinn Féin'],
        ['Plaid Cymru', 4, '#008142', 'Plaid Cymru'],
        ['Green Party', 1, '#6AB023', 'Green Party'],
        ['Speaker', 1, '#000000', 'Speaker'],
        ['Vacant', 1, '#888888', 'Vacant']

To the extent possible, it is advisable to organize your data so that parties are ordered based on their political leanings, from left to center to right. This way, it is also easy to see whether the composition is heavily right, center or left, or a balanced mix.

Shape

You can create and control the shape, the position, and the size of the chart using only four parameters: startAngle, endAngle, center, and size. Let’s say, that you would like to have:

  • An arc that goes from -90° to +90°.
  • A relatively centered position with a medium size chart.

To get the chart’s angles, use


;startAngle: -90, endAngle: 90

When it comes to position and size, your design skills will play a major role. In my case, after some adjustments, the best combination was:

center: ['50%', '90%'], size: '160%';

The chart looks centered to the user, with the right size that allows the tooltip and the legend to be clearly read.

The arc shape is one way of representing data using the parliament chart. There is also a rectangular shape to visualize and compare the data with multiple series.

The following demo represents the same data of the House of Commons of the United Kingdom election in a rectangular shape instead of an arch shape:

To get the rectangular result, I just removed the arc parameters startAngle, endAngle, center, and size.

Another interesting organizational chart to create is by using a different shape than the circle. For example, an individual icon shape, as displayed in this demo:

The individual shape is an SVG wrapped into the Highcharts.SVGRenderer method. Here is the code behind it:

(function(H) {
  Highcharts.SVGRenderer.prototype.symbols.individual = function(x, y, w, h, r) {
    return [
      'M', x + w * (2 / 5), y + h / 2,
      'A', w/3, w/3, 0, 1, 1, x + (w * 3 / 5), y + h / 2,
      'L', x + (w * 4 / 5), y + h,
      x + (w * 1 / 5), y + h
    ];
  };
}(Highcharts));

The SVG code is also availble at this link.

To use the individual shape into the chart, I change the symbol option in the marker feature from the standard round symbol to the individual shape:

marker: {
  symbol: 'individual'
}

That is it, now the chart displays many little individuals for each party.

Feel free to use the organizational chart with its variants, and don’t forget to be creative!

Chart Data visualization

Opinions expressed by DZone contributors are their own.

Related

  • How To Create a Network Graph Using JavaScript
  • How To Create a Resource Chart in JavaScript
  • How to Build a Treemap Using JavaScript
  • How to Create a Mosaic Chart Using JavaScript

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook