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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • JavaScript Temperature Anomaly Chart
  • Creating a Polar Chart to Measure Electromagnetic Field Strength
  • Create a JavaScript Scrolling and Sweeping Heatmap
  • JS Animated Radar Chart With TypeScript and NodeJS

Trending

  • Helm Dry Run: Guide and Best Practices
  • How To Aim for High GC Throughput
  • Protect Your Keys: Lessons from the Azure Key Breach
  • How to Prompt ChatGPT So It Writes Quality Tech Texts for Your Website

Stacked Area Charts and Mathematical Approximations

A review of the usefulness of communicating data via stacked area charts.

Josh Anderson user avatar by
Josh Anderson
·
Tim Brock user avatar by
Tim Brock
·
Apr. 18, 16 · Opinion
Like (2)
Save
Tweet
Share
3.12K Views

Join the DZone community and get the full member experience.

Join For Free

i've previously noted that i think stacked area charts are frequently used when a conventional line chart would be a better option. here is the (fictional) example i used previously and the conventional line chart alternative.

in short, if you want people to be able to make reasonably accurate judgments of the magnitudes of the individual components, and how they change depending on some other variable (such as time), the conventional line chart design is almost always going to be the best option. the lack of a steady baseline for all but the bottom component makes this task difficult for the stacked area chart.

stacked area charts can be useful if you want to illustrate an ordered sum of components that change with another variable. while previously i suggested how the cost of milk production from farm to shop might change with time might be suitable, here i'd like to consider something very different: selected mathematical series.

you're probably familiar with trigonometric functions like sine and cosine and you may also know about the exponential function and hyperbolic functions . it's fairly easy to draw graphs of these functions if you have a calculator of some sort. when tied up in complicated equations, these functions may become awkward to deal with. consequently, alternative ways of approximating these functions can come in very handy.

the functions mentioned above are all analytic functions . what this really means is quite complicated to attempt to explain so i won't try to do so here. instead, i'll just stick to the following: these functions can all be written as a sum of powers of their argument (typically denoted x ), that is, as a polynomial . being explicit helps, so here is a way of rewriting the exponential function:

in a similar manner, here is another way of expressing the cosine function:

and, here is the hyperbolic cosine function (typically written as cosh):

in general, to get an exact value for one of these functions using summation, we need to sum to infinity. this is not the case at the origin where all but the first term will equal 0. close to the origin we will also get a good approximation as x is small. but, how close and how good? we can plot the first few terms of, for example, the exponential function expression and see. the black line in the gif below shows the exact exponential function, the blue wedges show the result of adding more and more terms from the right-hand side of the equation (from the zeroth power of x up to the 8th) for the exponential function above. the translucent red wedge indicates the area not covered by the polynomial approximation.

below about x =1 we can see that the first three terms of the polynomial are a pretty good approximation for the exponential function. to get a good approximation around x =3 we need to go up to the sixth or seventh power of x (i.e. seven or eight terms of the polynomial). as the gif below shows, even going to the eighth power of x isn't sufficient around x =6.

we can look at the hyperbolic cosine function in a similar way, though there are no terms with odd powers of x .

as you might expect, when we look at large distances from the origin, we need more and more terms of the polynomial in order to closely match the exact function. at x =±6, adding up terms up to the 8th power of x is not sufficient to get a good approximation.

i think these are cases where stacked area charts can be of real use. we're genuinely interested in the progressive sums of components, not the individual parts and that's where stacked charts excel.

you probably noticed that i skipped over producing charts for the cosine function. that's because stacked charts fail. why? because successive terms have opposite signs. while including more and more terms in the polynomial approximation does get you closer and closer to the exact function, you can't show this as a simple stack because some terms add to the total while others subtract. this also a problem for the exponential function when x is negative: terms involving even powers of x will be positive while those involving odd powers of x will be negative. this is a purely visual issue that doesn't crop up when we plot lines instead of stacks.

hopefully, i've shown that stacked area charts can be useful when it is the ordered sums of components that are of interest and if the conditions are right. for the conditions to be right then all components of the stack must share the same sign (or be 0) at each (visible) point along the horizontal axis.

Chart

Published at DZone with permission of Josh Anderson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • JavaScript Temperature Anomaly Chart
  • Creating a Polar Chart to Measure Electromagnetic Field Strength
  • Create a JavaScript Scrolling and Sweeping Heatmap
  • JS Animated Radar Chart With TypeScript and NodeJS

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: