{"id":23917,"date":"2023-06-27T11:47:28","date_gmt":"2023-06-27T11:47:28","guid":{"rendered":"https:\/\/www.highcharts.com\/blog\/?p=23917"},"modified":"2026-01-13T11:34:39","modified_gmt":"2026-01-13T11:34:39","slug":"deviation-chart-highcharts-angular","status":"publish","type":"post","link":"https:\/\/www.highcharts.com\/blog\/integration\/deviation-chart-highcharts-angular\/","title":{"rendered":"Deviation chart with Highcharts and Angular"},"content":{"rendered":"<p>In this article, I will show you how to create a deviation chart using Highcharts and Angular.<\/p>\n<p>If you are not familiar with a deviation chart, here is some information: The chart is designed with two or more aligned bar charts. A graph displays a deviation relationship to feature how one or more sets of quantitative values differ from a reference set of values. A deviation chart is mainly used for quality measures.<\/p>\n<p>To create a deviation chart using Angular and Highcharts, follow these step-by-step instructions:<br \/>\n<b>Step 1<\/b><br \/>\nMake sure you have <code>Node.js<\/code> installed. If not, download and install it from the following URL: https:\/\/nodejs.org\/en\/download.<br \/>\n<b>Step 2<\/b><br \/>\nCreate a new folder to store the code, and open it in the command prompt terminal.<br \/>\n<b>Step 3<\/b><br \/>\nNow, let&#8217;s create a new Angular app. Type the following command:<br \/>\n<code>npm install -g @angular\/cli<\/code>.<br \/>\nAfter the installation is complete, run the following command:<br \/>\n<code>ng new myHighchartApp<\/code><br \/>\n<code>cd myHighchartApp<\/code><br \/>\n<code>npm install highcharts-angular --save<\/code><br \/>\n<b>Step 4<\/b><br \/>\nCreate a new component for the deviation chart, to do that run the following command:<br \/>\n<code>ng generate component deviationchart<\/code><br \/>\n<b>Step 5<\/b><br \/>\nTo create a deviation chart, I am using a bell curve, so I need to install the required package. Run the following command:<br \/>\n<code>npm install highcharts-histogram-bellcurve --save<\/code><\/p>\n<p>The project is divided into three files:<\/p>\n<ol>\n<li><b>deviation-chart.component.ts<\/b>: This file contains the main logic and Highchart code.<\/li>\n<li><b>deviation-chart.component.html<\/b>: This file is used for the view to convert the chart in the browser.<\/li>\n<li><b>app.module.ts<\/b>: This one is for adding dependencies to the module.<\/li>\n<\/ol>\n<p>Before checking the code, let me walk you through some explanations:<br \/>\nIt is important to add the module <code>histogram-bellcurve.js<\/code>, as it is necessary for creating the range. Additionally, I declare the variable <code>Highcharts: typeof Highcharts = Highcharts<\/code>. This declaration is essential for the HTML page and the chartOptions. I specify the minimum and maximum range for the xAxis. In the series section, I define the chart type as a histogram, which allows to create step charts. To achieve the desired appearance of a step chart, you have to set the color as transparent. Finally, don\u2019t forget to define your data series as scatter.<\/p>\n<p>Now, feel free to explore the code below for each file (link to <a href=\"https:\/\/github.com\/sourabhmishranotes\/blog1\" target=\"_blank\" rel=\"noopener\">Github project<\/a>):<br \/>\n<b>deviation-chart.component.ts<\/b> code<\/p>\n<pre>import { Component, OnInit } from \"@angular\/core\";\r\nimport * as Highcharts from \"highcharts\/highcharts\";\r\nimport Bellcurve from \"highcharts\/modules\/histogram-bellcurve\";\r\nBellcurve(Highcharts);\r\n@Component({\r\n  selector: \"app-deviation-chart\",\r\n  templateUrl: \".\/deviation-chart.component.html\",\r\n  styleUrls: [\".\/deviation-chart.component.css\"]\r\n})\r\nexport class DeviationChartComponent {\r\n  title = \"myHighChartsApp\";\r\n  Highcharts: typeof Highcharts = Highcharts;\r\n  chartOptions: Highcharts.Options = {\r\n    title: {\r\n      text: \"Sample Count by Range\"\r\n    },\r\n    xAxis: {\r\n      min: 0,\r\n      max: 4,\r\n      tickInterval: 1\r\n    },\r\n    series: [\r\n      {\r\n        type: \"histogram\",\r\n        baseSeries: \"s1\",\r\n        zIndex: -1,\r\n        binsNumber: 5,\r\n        color: \"transparent\",\r\n        borderWidth: 2,\r\n        borderColor: \"green\"\r\n      },\r\n      {\r\n        type: \"scatter\",\r\n        data: [0.17, 0.17, 0.18, 0.22, 0.26, 0.67, 0.98, 2.8, 2.92, 3.3],\r\n        id: \"s1\",\r\n        visible: false,\r\n        showInLegend: false\r\n      }\r\n    ]\r\n  };\r\n}\r\n<\/pre>\n<p><b>app.module.ts<\/b> code:<\/p>\n<pre>import { NgModule } from \"@angular\/core\";\r\nimport { BrowserModule } from \"@angular\/platform-browser\";\r\nimport { HighchartsChartModule } from \"highcharts-angular\";\r\nimport { AppRoutingModule } from \".\/app-routing.module\";\r\nimport { AppComponent } from \".\/app.component\";\r\nimport { DeviationchartComponent } from \".\/deviationchart\/deviationchart.component\";\r\n\r\n@NgModule({\r\n  declarations: [AppComponent, DeviationchartComponent],\r\n  imports: [BrowserModule, HighchartsChartModule, AppRoutingModule],\r\n  providers: [],\r\n  bootstrap: [AppComponent]\r\n})\r\nexport class AppModule {}\r\n<\/pre>\n<p><b>deviation-chart.component.html<\/b> code<\/p>\n<pre>&lt;div class=\"content\" role=\"main\"&gt;\r\n  &lt;highcharts-chart [Highcharts]=\"Highcharts\" [options]=\"chartOptions\" style=\"width: 100%; height: 400px; display: block;\"&gt;\r\n  &lt;\/highcharts-chart&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>To use this application, you need to <code>run ng-Serve<\/code>. Once you do that, you will see the following result displayed (see below).<br \/>\nThe code shows that the xAxis ranges from 0 to 4, with the chart type being a histogram. Additionally, the base series is connected to s1,<br \/>\nwhich in turn connects to a scatter data series. Finally, the chart is made visible, but the <code>legend<\/code> is set not to show using<br \/>\n <code>showInLegend<\/code> as <code>false<\/code>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-23791 aligncenter\" src=\"https:\/\/wp-assets.highcharts.com\/svg\/gifcountbyrange.gif\" alt=\"A gif to show a deviation chart using Highcharts and Angular\" width=\"560\" height=\"280\" \/><\/p>\n<p>Highcharts is a great tool for building interactive real time dashboard, with angular you can build faster applications. For more learning regarding Highcharts with angular you can read <a href=\"https:\/\/link.springer.com\/book\/10.1007\/978-1-4842-9181-8\" target=\"_blank\" rel=\"noopener\">Practical Highcharts with angular book<\/a>. <\/p>\n<p>\u00a0<\/p>\n<h2><strong>Related posts<\/strong><\/h2>\n<ul>\n<li style=\"margin-left: 20px; margin-bottom: 20px;\"><a href=\"https:\/\/www.highcharts.com\/blog\/tutorials\/line-chart-vs-bar-chart-choosing-the-right-one-for-your-objectives-and-data\/\">Line chart vs bar chart: choosing the right one for your objectives and data<\/a><\/li>\n<li style=\"margin-left: 20px; margin-bottom: 20px;\"><a href=\"https:\/\/www.highcharts.com\/blog\/tutorials\/pareto-chart-what-is-it-and-what-does-it-suggest\/\">Pareto chart: what is it and what does it suggest<\/a><\/li>\n<li style=\"margin-left: 20px; margin-bottom: 20px;\"><a href=\"https:\/\/www.highcharts.com\/blog\/tutorials\/real-time-data-visualization-using-highcharts\/\">Real-time data visualization using Highcharts<\/a><\/li>\n<li style=\"margin-left: 20px; margin-bottom: 20px;\"><a href=\"https:\/\/www.highcharts.com\/blog\/tutorials\/big-data-visualization-using-highcharts\/\">Big data visualization using Highcharts<\/a><\/li>\n<li style=\"margin-left: 20px; margin-bottom: 20px;\"><a href=\"https:\/\/www.highcharts.com\/blog\/tutorials\/maps-with-latitude-longitude-using-highcharts\/\">Maps with latitude longitude using Highcharts<\/a><\/li>\n<li style=\"margin-left: 20px; margin-bottom: 20px;\"><a href=\"https:\/\/www.highcharts.com\/blog\/tutorials\/visualizing-geospatial-data-with-highcharts-maps\/\">Visualizing geospatial data with Highcharts Maps<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to create a Deviation chart with Highcharts and Angular.<\/p>\n","protected":false},"author":276,"featured_media":23930,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"meta_title":"","meta_description":"","hc_selected_options":[],"footnotes":""},"categories":[1105],"tags":[822,1094,1031],"coauthors":[1000,699],"class_list":["post-23917","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-integration","tag-angular","tag-highcharts-core","tag-javascript"],"_links":{"self":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/23917","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/users\/276"}],"replies":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/comments?post=23917"}],"version-history":[{"count":4,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/23917\/revisions"}],"predecessor-version":[{"id":26020,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/23917\/revisions\/26020"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/media\/23930"}],"wp:attachment":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/media?parent=23917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/categories?post=23917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/tags?post=23917"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/coauthors?post=23917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}