Make Your .NET Data More Useful with Treemap Visualization

Make Your .NET Data More Useful with Treemap Visualization

isualization is all about taking data and turning it into useful information. The technique is glaringly useful and widely used. Consider the following situation: you want to display the profiles of the population of a country, divided by age.

Age Group

Number of People

0-18

1,452,382

18-35

1,231,987

35-50

842,427

50+

692,120

This type of presentation requires more thinking to get a grip on the data than it should. This is the kind of processing that the computer should be doing for you. For instance, the computer could make this easier on the end user by changing the raw figures into percentages.

Age Group

Percentage of Population

0-18

42%

18-35

39%

35-50

11%

50+

8%

The percentages tell a better story. But understanding could be enhanced even further if it the data were drawn as a pie-chart, as in Figure 1.

 
Figure 1: This pie chart represents the data even more accessibly.

From the size of the slices on the pie, end users can more easily interpret the data and turn it into useful information.

But what happens when you’ve got a lot of data to visualize? Bar charts and scatter charts, while useful, are limited in the number of data points that they can render.

Making the Case for Advanced Visualization
What would happen if you wanted to view data from every country in the world, broken down in the same way? Would you have a page showing hundreds of pie charts? How would these pie charts relate to each other?

These are the problems that the treemap visualization has been designed to solve. The treemap allows you to render a complex, hierarchical dataset in a relational view. It is capable of plotting many data points and keeping it visually consistent. An example of a treemap in commercial use is SmartMoney.com’s Market Map, which takes the instruments that are in the S&P 500 index of stocks and creates a treemap.

On this treemap, the market is divided into sectors. Each sector has a number of stocks. The area of the sector is divided up into a number of rectangles with the size of the rectangle being directly proportional to the market cap of the company (the market cap is the number of shares available times the price of a share). The color of the rectangle shows the current change in price. Hovering over a rectangle shows more detail on the company in question.

As you can see, a vast amount of information is presented to the user:

  • Company placement by sector
  • Market cap of every company in the index
  • Current status of the stock (up/down) every company
  • Overall view of the market today
  • Overall view of every sector today

This is an incredibly useful tool. On any given day, you can easily see which sectors and companies are doing well, and which are doing badly.

In this article, you’ll use a similar visualization technique to build an application that renders whatever data you like.

The .NET Treemap Control
The Microsoft research site has an ongoing project called Netscan, which takes all the news stories in USENET and measures the groups in which they reside for size and frequency. A treemap visualization renders this information. They have made the control that they use available for download. You may download it from here.

To install the Treemap control, simply unzip the downloaded file. The file contains two DLL files?treemapcontrol.dll which contains the control and treemapgenerator.dll, a support library for the control. There’s a also a help file.

Please note that this control is licensed by Microsoft for non-commercial research, academic, or learning purposes only.

First, build a simple C# application using the treemap control. Later, you will build an application that maps data from a SQL Server database.

Build Your First Treemap Application
Start Microsoft Visual Studio.NET and start a new Windows Application called Treemap. For the purposes of this article you’ll be using C#, but you could easily change to your language of choice, say VB.NET or J#.

Select the General tab on the toolbox, right click and select Add/Remove Items. On the Customize Toolbox dialog that results, click “Browse…” and browse to the Treemapcontrol.dll file on your file system.

The TreemapControl is added to your toolbox, and references to TreemapControl and TreemapGenerator are added to the References section on your Solution Explorer.

Now, draw an instance of the control on the default form (Form1.cs) and call it tmc1. Add a button to the form.

To building the nodes for a treemap control, cut and paste the code below onto the code behind your form:

Void BuildTreemap(TreemapControl tmcMap){Nodes oNodes, oChildNodes, oGrandChildNodes;	Node oNode, oChildNode, oGrandChildNode;	oNodes = tmcMap.Nodes;            	// Add a top-level node to the collection. 	oNode = oNodes.Add("Europe", 25F, 100F);            	// Add child nodes to this node.	oChildNodes = oNode.Nodes;	oChildNode = oChildNodes.Add("England", 50F, 2.5F);	oChildNode = oChildNodes.Add("Ireland", 50F, -34.5F);            	// Add another top-level node. 	oNode = oNodes.Add("Americas", 50F, -40.1F);            	// Add child nodes to the this new node.	oChildNodes = oNode.Nodes;	oChildNode = oChildNodes.Add("Canada", 20F, 200F);      oChildNode = oChildNodes.Add("USA", 100F, 0F);				// Add a child node to one of the children	oGrandChildNodes = oChildNode.Nodes;	oGrandChildNode = oGrandChildNodes.Add("California", 60F, 0F);	oGrandChildNode = oGrandChildNodes.Add("Texas", 30F, 0F);	// Draw it	tmcMap.Draw();}

Make sure you are referencing the treemap by adding the following line at the top of your code listing.

using Microsoft.Research.CommunityTechnologies.Treemap;

Finally, call the treemap by placing the following line of code into the click event handler for the button.

	BuildTreemap(tmc1);

The entire application is available in the download. When you run this application, you should see the output shown in Figure 2.

 
Figure 2: Here's the sample Treemap application.

Building a treemap is very straightforward, and very similar to building a treeview, in that everything is a node, and every node has a number of children. In the above example, 'Americas' is a top level node, containing two child nodes 'Canada' and 'USA.' The 'USA' node itself contains two children 'California' and 'Texas.' The parameters to the Node.Add method are, respectively, the text describing the node, the size of the node, and the color of the node. The size of the node is purely arbritrary, and the control calculates the render size for the node based on this size and the total of all sizes at that level in the node tree. In the above example, 'California' is given a value of 60F and 'Texas' a value of 30F. Looking at the output, you can see that 'California' occupies two thirds of the real estate allocated by the control to the 'USA' node.

Since this way of building a tree is very code intensive, I used it only for demonstration purposes. The treemap control, however, has a neat function, which is the ability to load the nodes definitions from an XML file. Next, you'll use this capability as you build a treemap control to consume a Web service that exposes the contents of a database as a treemap control.

Variations on the Theme
The Microsoft Treemap control requires your XML to be formatted in a particular way in order to successfully parse and render the data. An example of this XML is seen in the following code:

                                                                  

The control also has a property NodesXML which, when set with a string containing valid XML, sets up the internal data structures for the treemap. Build your treemap in this way by using the following code:

XmlDocument xmlDoc = new XmlDocument();	xmlDoc.Load("c:\treemap.xml");	tmcMap.NodesXml = xmlDoc.InnerXml;	tmcMap.Draw();

You can also build a treemap from the output of a Web service. It's very simple to do in Visual Studio.NET. Simply have your Web method return XML in the above format as type XMLDocument. This XML can then be passed to the NodesXML property like in the XML example above.

Visualization Equals Data Simplification
This method is an incredibly useful way of looking at data. It allows for a much better overview of complex data than you get with traditional visualizations. The Microsoft Research treemap control provides an easy way to implement this technology. Use the basics you have gleaned here to explore the next level and add value to your data applications.

devx-admin

devx-admin

Share the Post:
USA Companies

Top Software Development Companies in USA

Navigating the tech landscape to find the right partner is crucial yet challenging. This article offers a comparative glimpse into the top software development companies

Software Development

Top Software Development Companies

Looking for the best in software development? Our list of Top Software Development Companies is your gateway to finding the right tech partner. Dive in

India Web Development

Top Web Development Companies in India

In the digital race, the right web development partner is your winning edge. Dive into our curated list of top web development companies in India,

USA Web Development

Top Web Development Companies in USA

Looking for the best web development companies in the USA? We’ve got you covered! Check out our top 10 picks to find the right partner

Clean Energy Adoption

Inside Michigan’s Clean Energy Revolution

Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the

Chips Act Revolution

European Chips Act: What is it?

In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor

USA Companies

Top Software Development Companies in USA

Navigating the tech landscape to find the right partner is crucial yet challenging. This article offers a comparative glimpse into the top software development companies in the USA. Through a

Software Development

Top Software Development Companies

Looking for the best in software development? Our list of Top Software Development Companies is your gateway to finding the right tech partner. Dive in and explore the leaders in

India Web Development

Top Web Development Companies in India

In the digital race, the right web development partner is your winning edge. Dive into our curated list of top web development companies in India, and kickstart your journey to

USA Web Development

Top Web Development Companies in USA

Looking for the best web development companies in the USA? We’ve got you covered! Check out our top 10 picks to find the right partner for your online project. Your

Clean Energy Adoption

Inside Michigan’s Clean Energy Revolution

Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the state. A Senate committee meeting

Chips Act Revolution

European Chips Act: What is it?

In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor supply chain and enhance its

Revolutionized Low-Code

You Should Use Low-Code Platforms for Apps

As the demand for rapid software development increases, low-code platforms have emerged as a popular choice among developers for their ability to build applications with minimal coding. These platforms not

Cybersecurity Strategy

Five Powerful Strategies to Bolster Your Cybersecurity

In today’s increasingly digital landscape, businesses of all sizes must prioritize cyber security measures to defend against potential dangers. Cyber security professionals suggest five simple technological strategies to help companies

Global Layoffs

Tech Layoffs Are Getting Worse Globally

Since the start of 2023, the global technology sector has experienced a significant rise in layoffs, with over 236,000 workers being let go by 1,019 tech firms, as per data

Huawei Electric Dazzle

Huawei Dazzles with Electric Vehicles and Wireless Earbuds

During a prominent unveiling event, Huawei, the Chinese telecommunications powerhouse, kept quiet about its enigmatic new 5G phone and alleged cutting-edge chip development. Instead, Huawei astounded the audience by presenting

Cybersecurity Banking Revolution

Digital Banking Needs Cybersecurity

The banking, financial, and insurance (BFSI) sectors are pioneers in digital transformation, using web applications and application programming interfaces (APIs) to provide seamless services to customers around the world. Rising

FinTech Leadership

Terry Clune’s Fintech Empire

Over the past 30 years, Terry Clune has built a remarkable business empire, with CluneTech at the helm. The CEO and Founder has successfully created eight fintech firms, attracting renowned

The Role Of AI Within A Web Design Agency?

In the digital age, the role of Artificial Intelligence (AI) in web design is rapidly evolving, transitioning from a futuristic concept to practical tools used in design, coding, content writing

Generative AI Revolution

Is Generative AI the Next Internet?

The increasing demand for Generative AI models has led to a surge in its adoption across diverse sectors, with healthcare, automotive, and financial services being among the top beneficiaries. These

Microsoft Laptop

The New Surface Laptop Studio 2 Is Nuts

The Surface Laptop Studio 2 is a dynamic and robust all-in-one laptop designed for creators and professionals alike. It features a 14.4″ touchscreen and a cutting-edge design that is over

5G Innovations

GPU-Accelerated 5G in Japan

NTT DOCOMO, a global telecommunications giant, is set to break new ground in the industry as it prepares to launch a GPU-accelerated 5G network in Japan. This innovative approach will

AI Ethics

AI Journalism: Balancing Integrity and Innovation

An op-ed, produced using Microsoft’s Bing Chat AI software, recently appeared in the St. Louis Post-Dispatch, discussing the potential concerns surrounding the employment of artificial intelligence (AI) in journalism. These

Savings Extravaganza

Big Deal Days Extravaganza

The highly awaited Big Deal Days event for October 2023 is nearly here, scheduled for the 10th and 11th. Similar to the previous year, this autumn sale has already created

Cisco Splunk Deal

Cisco Splunk Deal Sparks Tech Acquisition Frenzy

Cisco’s recent massive purchase of Splunk, an AI-powered cybersecurity firm, for $28 billion signals a potential boost in tech deals after a year of subdued mergers and acquisitions in the

Iran Drone Expansion

Iran’s Jet-Propelled Drone Reshapes Power Balance

Iran has recently unveiled a jet-propelled variant of its Shahed series drone, marking a significant advancement in the nation’s drone technology. The new drone is poised to reshape the regional

Solar Geoengineering

Did the Overshoot Commission Shoot Down Geoengineering?

The Overshoot Commission has recently released a comprehensive report that discusses the controversial topic of Solar Geoengineering, also known as Solar Radiation Modification (SRM). The Commission’s primary objective is to

Remote Learning

Revolutionizing Remote Learning for Success

School districts are preparing to reveal a substantial technological upgrade designed to significantly improve remote learning experiences for both educators and students amid the ongoing pandemic. This major investment, which

Revolutionary SABERS Transforming

SABERS Batteries Transforming Industries

Scientists John Connell and Yi Lin from NASA’s Solid-state Architecture Batteries for Enhanced Rechargeability and Safety (SABERS) project are working on experimental solid-state battery packs that could dramatically change the

Build a Website

How Much Does It Cost to Build a Website?

Are you wondering how much it costs to build a website? The approximated cost is based on several factors, including which add-ons and platforms you choose. For example, a self-hosted