{"id":2158,"date":"2019-09-23T08:57:16","date_gmt":"2019-09-23T08:57:16","guid":{"rendered":"https:\/\/mindfusion.eu\/blog\/?p=2158"},"modified":"2021-01-23T16:14:23","modified_gmt":"2021-01-23T16:14:23","slug":"combination-chart-in-javascript","status":"publish","type":"post","link":"https:\/\/mindfusion.dev\/blog\/combination-chart-in-javascript\/","title":{"rendered":"Combination Chart in JavaScript"},"content":{"rendered":"<p>In this blog post we will use the Charting for JavaScript library to create the chart that you see below:<\/p>\n<p><a href=\"https:\/\/mindfusion.dev\/javascript-demo.html?sample=CombinationChart\"><img decoding=\"async\" title=\"Combination Chart in JavaScript\" src=\"http:\/\/mindfusion.dev\/product_images\/javascript\/library\/chart\/combination_chart.png\" \/><\/a><\/p>\n<p>This is a combination chart has one line series and two bar series drawn in stacks. We will use the <a title=\"Charting for JavaScript API Reference: Dashboard\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Controls_Dashboard.htm\">Dashboard<\/a> control to combine the building elements of the chart: data series, legend, axes, title and plot.<\/p>\n<p><strong>I. HTML Setup<\/strong><\/p>\n<p>We need an HTML Canvas element for the chart to draw itsself onto. It is important that we give it an id. The Canvas element will render the chart and its position and size will determine where and how big the chart will be drawn.<\/p>\n<pre id=\"line1\">&lt;<span class=\"start-tag\">canvas<\/span> <span class=\"attribute-name\">id<\/span>=\"<a class=\"attribute-value\">dashboard<\/a>\" <span class=\"attribute-name\">style<\/span>=\"<a class=\"attribute-value\">width: 100%; height: 100%; display: block;<\/a>\"&gt;&lt;\/<span class=\"end-tag\">canvas<\/span>&gt;<\/pre>\n<p>The <a title=\"Charting for JavaScript API Reference: Dashboard\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Controls_Dashboard_Members.htm\">Dashboard<\/a> control needs the MindFusion.Charting.js library. We also need the MindFusion.Drawing module for presentation classes like brushes, pens etc. We include reference to these files at the end of the web page, before the closing BODY tag:<\/p>\n<pre id=\"line1\">&lt;<span class=\"start-tag\">a<\/span> <span class=\"attribute-name\">href<\/span>=\"<a class=\"attribute-value\" href=\"view-source:http:\/\/scripts\/MindFusion.Common.js\">http:\/\/Scripts\/MindFusion.Common.js<\/a>\"&gt;http:\/\/Scripts\/MindFusion.Common.js&lt;\/<span class=\"end-tag\">a<\/span>&gt;\n<span id=\"line324\"><\/span>&lt;<span class=\"start-tag\">a<\/span> <span class=\"attribute-name\">href<\/span>=\"<a class=\"attribute-value\" href=\"view-source:http:\/\/scripts\/MindFusion.Charting.js\">http:\/\/Scripts\/MindFusion.Charting.js<\/a>\"&gt;http:\/\/Scripts\/MindFusion.Charting.js&lt;\/<span class=\"end-tag\">a<\/span>&gt;<\/pre>\n<p>The two library JavaScript files are in a subfolder called Scripts. We prefer to keep the JavaScript code for the combination chart separate from the web page and we include one final JS reference:<\/p>\n<pre id=\"line1\">&lt;<span class=\"start-tag\">a<\/span> <span class=\"attribute-name\">href<\/span>=\"<a class=\"attribute-value\" href=\"view-source:http:\/\/combinationchart.js\/\">http:\/\/CombinationChart.js<\/a>\"&gt;http:\/\/CombinationChart.js&lt;\/<span class=\"end-tag\">a<\/span>&gt;<\/pre>\n<p>This is the code-behind file where we will write all code that creates and customizes the combination chart.<\/p>\n<p><strong>II. Creating the Dashboard and General Chart Settings<\/strong><\/p>\n<p>We add mappings to the chart and drawing namespaces that we want to use. If your IDE supports Intellisense you can also add a reference to the Intellisense file.<\/p>\n<pre>\/\/\/ \nvar Charting = MindFusion.Charting;\n\nvar Controls = Charting.Controls;\nvar Collections = Charting.Collections;\nvar Drawing = Charting.Drawing;\nvar Components = Charting.Components;<\/pre>\n<p>The <a title=\"Charting for JavaScript API Reference: Dashboard\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Controls_Dashboard_Members.htm\">Dashboard<\/a> class requires and HTML element in the constructor. We get the Canvas from the web page with the help of its id:<\/p>\n<pre>\/\/ create the dashboard\nvar dashboardEl = document.getElementById('dashboard');\ndashboardEl.width = dashboardEl.offsetParent.clientWidth;\ndashboardEl.height = dashboardEl.offsetParent.clientHeight;\nvar dashboard = new Controls.Dashboard(dashboardEl);<\/pre>\n<p>The <a title=\"Charting for JavaScript API Reference: Dashboard\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Controls_Dashboard_Members.htm\">Dashboard<\/a> control is a container for all elements of a dashboard. In order to render a chart, we need a <a title=\"Charting for JavaScript API Reference: Plot\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Plot_0.htm\">Plot<\/a> element that can visualize data. We create an instance of the <a title=\"Charting for JavaScript API Reference: Plot2D\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Plot2D_0.htm\">Plot2D<\/a> class:<\/p>\n<pre>var plot = new Charting.Plot2D();\nplot.gridType = Charting.GridType.Horizontal;\nplot.gridColor1 = plot.gridColor2 = new Drawing.Color.fromArgb(200, 243, 244, 254);<\/pre>\n<p>Then we specify that the plot will render a horizontal grid with light gray grid lines. Each <a title=\"Charting for JavaScript API Reference: Plot2D\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Plot2D_Members_0.htm\">Plot2D<\/a> has a <a title=\"Charting for JavaScript API Reference: seriesRenderers\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_Plot_seriesRenderers_0_0.htm\">seriesRenderers<\/a> property that stores all -SeriesRenderer -s that are responsible for drawing correctly the data series according to their type &#8211; LineSeries <a title=\"Charting for JavaScript API Reference: BarSeries\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_BarSeries_Members_0.htm\">BarSeries<\/a> <a title=\"Charting for JavaScript API Reference: PieSeries\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_PieSeries_Members_0.htm\">PieSeries<\/a> etc. More about that later.<\/p>\n<p><strong>III. Data Series and Renderers<\/strong><\/p>\n<p>Each data series is represented by a class that corresponds to its type. MindFusion Charting for JavaScript has a variety of ISeries classes, some of whom can be used in different chart types. We will first use the <a title=\"Charting for JavaScript API Reference: BarSeries\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_BarSeries_0.htm\">BarSeries<\/a> class to create one of the series that render bars:<\/p>\n<pre>\/\/ data for first bar series\nvar barSeries1 = new Charting.BarSeries(\n\t\tnew Collections.List([9, 11, 13, 18, 19, 22, 23, 26, 29, 32, 33, 36, 41, 46, 49, 55, 57, 58, 61, 63]), \/\/y\n\t\tnull, null,\n\t\tnew Collections.List([\"1999\", \"2000\", \"2001\", \"2002\", \"2003\", \"2004\", \"2005\", \"2006\", \"2007\", \"2008\", \"2009\", \"2010\", \"2011\", \"2012\", \n\t\t\"2012\", \"2013\", \"2014\", \"2015\", \"2016\", \"2017\", \"2018\"]));<\/pre>\n<p>The <a title=\"Charting for JavaScript API Reference: BarSeries\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_BarSeries_Members_0.htm\">BarSeries<\/a> constructor requires several arguments. The first one is the data list, the second are lists with the top and inner labels, which we do not use. The last parameter are the labels for the X-axis and we set here the desired labels.<\/p>\n<p>Then we set the <a title=\"Charting for JavaScript API Reference: title\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_Series_title_0_0.htm\">title<\/a> property of the <a title=\"Charting for JavaScript API Reference: BarSeries\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_BarSeries_Members_0.htm\">BarSeries<\/a> &#8211; it is important because it will render as a legend item.<\/p>\n<pre>barSeries1.title = \"Total amount of goods sold\";<\/pre>\n<p>We create then another series for the top row of bars. We don&#8217;t need any labels any more so we use now a simple <a title=\"Charting for JavaScript API Reference: Series2D\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Series2D_Members_0.htm\">Series2D<\/a> instance:<\/p>\n<pre>var barSeries2 = new Charting.Series2D(\n\t\tnew Collections.List([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]),\/\/x\n\t\tnew Collections.List([3, 4, 5, 5, 7, 8, 7, 6, 8, 15, 17, 21, 19, 18, 17, 16, 17, 19, 20, 22]),\/\/y\n\t\tnull);\n\nbarSeries2.title = \"Extra production to meet demand\";<\/pre>\n<p>The series need a <a title=\"Charting for JavaScript API Reference: SeriesRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_SeriesRenderer_Members_0.htm\">SeriesRenderer<\/a> that can draw them. There are different <a title=\"Charting for JavaScript API Reference: SeriesRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_SeriesRenderer_Members_0.htm\">SeriesRenderer<\/a> -s for the different types of series. The different <a title=\"Charting for JavaScript API Reference: SeriesRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_SeriesRenderer_Members_0.htm\">SeriesRenderer<\/a> instances support different ISeries classes.<\/p>\n<p>In our case we want a stack bar chart and we use the <a title=\"Charting for JavaScript API Reference: BarStackRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_BarStackRenderer_Members_0.htm\">BarStackRenderer<\/a> . Each SeriesRenderer accepts a list with the <a title=\"Charting for JavaScript API Reference: Series\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Series_0.htm\">Series<\/a> instances it must render. Here is the code for the stack bars:<\/p>\n<pre>\/\/ draw bars\nvar barRenderer = new Charting.BarStackRenderer(new Collections.ObservableCollection([barSeries1, barSeries2]));\nbarRenderer.seriesStyle = new Charting.PerSeriesStyle (new Collections.List([new Drawing.Brush(\"#230A59\"), new Drawing.Brush(\"#3E38F2\")]));\nbarRenderer.barSpacingRatio = 0.7;<\/pre>\n<p>The different <a title=\"Charting for JavaScript API Reference: SeriesRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_SeriesRenderer_Members_0.htm\">SeriesRenderer<\/a> instances have different sets of properties that allow you to customize how the data series will be drawn. Here we use the <a title=\"Charting for JavaScript API Reference: barSpacingRatio\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_BarRenderer_barSpacingRatio_0_0.htm\">barSpacingRatio<\/a> to specify the thickness of the stack bars.<\/p>\n<p>As we mentioned earlier, the <a title=\"Charting for JavaScript API Reference: Plot2D\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Plot2D_Members_0.htm\">Plot2D<\/a> class has a <a title=\"Charting for JavaScript API Reference: seriesRenderers\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_Plot_seriesRenderers_0_0.htm\">seriesRenderers<\/a> property where we can add the different <a title=\"Charting for JavaScript API Reference: SeriesRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_SeriesRenderer_Members_0.htm\">SeriesRenderer<\/a> -s that we want to show. We add the <a title=\"Charting for JavaScript API Reference: BarStackRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_BarStackRenderer_Members_0.htm\">BarStackRenderer<\/a> add graphics to plot<br \/>plot.seriesRenderers.add(barRenderer);<\/p>\n<p>The procedure is the same for the line chart. We create another <a title=\"Charting for JavaScript API Reference: Series2D\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Series2D_Members_0.htm\">Series2D<\/a> instance:<\/p>\n<pre>\/\/ sample data for line graphics\nvar lineSeries = new Charting.Series2D(\n\t\t\t\tnew Collections.List([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]),\/\/x\n\t\t\t\tnew Collections.List([7, 9, 12, 15, 18, 23, 24, 27, 35, 41, 46, 49, 53, 55, 58,  61, 63, 66, 67, 69 ]),\/\/right-y\n\t\t\t\tnull);\nlineSeries.title = \"Peak demand\";<\/pre>\n<p>We give it a title and create a <a title=\"Charting for JavaScript API Reference: LineRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_LineRenderer_Members_0.htm\">LineRenderer<\/a> that will render this series:<\/p>\n<pre>\/\/ draw lines\nvar lineRenderer = new Charting.LineRenderer(\n\t\t\t\tnew Collections.ObservableCollection([lineSeries]));\nlineRenderer.seriesStyle = new Charting.UniformSeriesStyle(new Drawing.Brush(\"#ffffff\"), new Drawing.Brush(\"#ffffff\"), 6);<\/pre>\n<p>Finally we add the <a title=\"Charting for JavaScript API Reference: LineRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_LineRenderer_Members_0.htm\">LineRenderer<\/a> to the <a title=\"Charting for JavaScript API Reference: seriesRenderers\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_Plot_seriesRenderers_0_0.htm\">seriesRenderers<\/a> collection of the <a title=\"Charting for JavaScript API Reference: Plot2D\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Plot2D_Members_0.htm\">Plot2D<\/a> instance.<\/p>\n<pre>plot.seriesRenderers.add(lineRenderer);<\/pre>\n<p>You might have noticed that we also set the <a title=\"Charting for JavaScript API Reference: seriesStyle\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_SeriesRenderer_seriesStyle_0_0.htm\">seriesStyle<\/a> property in both the <a title=\"Charting for JavaScript API Reference: BarStackRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_BarStackRenderer_0.htm\">BarStackRenderer<\/a> and the <a title=\"Charting for JavaScript API Reference: LineRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_LineRenderer_Methods_0.htm\">LineRenderer<\/a> classes. This is the property that specifies how the chart series will be painted. There are different classes that derive from <a title=\"Charting for JavaScript API Reference: SeriesStyle\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_SeriesStyle_0.htm\">SeriesStyle<\/a> All of them concern a different pattern of applying brushes and pens to the element of a <a title=\"Charting for JavaScript API Reference: Series\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Series_0.htm\">Series<\/a> We use here an instance of the <a title=\"Charting for JavaScript API Reference: PerSeriesStyle\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_PerSeriesStyle_Members_0.htm\">PerSeriesStyle<\/a> class that accepts lists with brushes and strokes and applies one consequtive brush and stroke to all elements in the corresponding <a title=\"Charting for JavaScript API Reference: Series\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Series_0.htm\">Series<\/a> . The <a title=\"Charting for JavaScript API Reference: LineRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_LineRenderer_Members_0.htm\">LineRenderer<\/a> uses the <a title=\"Charting for JavaScript API Reference: UniformSeriesStyle\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_UniformSeriesStyle_Members_0.htm\">UniformSeriesStyle<\/a> , which accepts just two <a title=\"Charting for JavaScript API Reference: Brush\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Drawing_Brush.htm\">Brush<\/a> instances as arguments and applies them to fill and stroke all elements in all <a title=\"Charting for JavaScript API Reference: Series\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Series_0.htm\">Series<\/a> instances in the <a title=\"Charting for JavaScript API Reference: SeriesRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_SeriesRenderer_Members_0.htm\">SeriesRenderer<\/a> .<\/p>\n<p><strong>IV. The Axes<\/strong><\/p>\n<p>The chart axes are instances of the <a title=\"Charting for JavaScript API Reference: Axis\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Axis_Members_0.htm\">Axis<\/a> class. We use their <a title=\"Charting for JavaScript API Reference: min\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_Axis_minValue_0_0.htm\">min<\/a> , <a title=\"Charting for JavaScript API Reference: max\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_Axis_maxValue_0_0.htm\">max<\/a> and <a title=\"Charting for JavaScript API Reference: interval\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_Axis_interval_0_0.htm\">interval<\/a> properties to specify the numeric data of each of the two axes that our dashboard will have &#8211; X and Y:<\/p>\n<pre>\/\/ create axes\nvar xAxis = new Charting.Axis();\nxAxis.interval = 0;\nxAxis.minValue = -1;\nxAxis.maxValue = 20;\nxAxis.title = \"\";\n\n\/\/ create axes\nvar yAxis = new Charting.Axis();\nyAxis.interval = 10;\nyAxis.minValue = 0;\nyAxis.maxValue = 100;\nyAxis.title = \"Cost of goods in mlns of USD\";<\/pre>\n<p>Then we specify to the <a title=\"Charting for JavaScript API Reference: Plot2D\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Plot2D_Members_0.htm\">Plot2D<\/a> that the <a title=\"Charting for JavaScript API Reference: Axis\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Axis_Members_0.htm\">Axis<\/a> instances we created are its X and Y axes:<\/p>\n<pre>plot.yAxis = yAxis;\nplot.xAxis = xAxis;<\/pre>\n<p>As you might have guessed, the <a title=\"Charting for JavaScript API Reference: Axis\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Axis_0.htm\">Axis<\/a> need Renderer-s to render them. They are called respectively <a title=\"Charting for JavaScript API Reference: XAxisRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_XAxisRenderer_Members_0.htm\">XAxisRenderer<\/a> and <a title=\"Charting for JavaScript API Reference: YAxisRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_YAxisRenderer_Members_0.htm\">YAxisRenderer<\/a> .<\/p>\n<pre>\/\/ create renderers for the two axes\nvar xAxisRenderer = new Charting.XAxisRenderer(xAxis);\nxAxisRenderer.margin = new Charting.Margins(0, 0, 0, 10);\nxAxisRenderer.labelsSource = plot;\nxAxisRenderer.showCoordinates = false;\n\n\nvar yAxisRenderer = new Charting.YAxisRenderer(yAxis);\nyAxisRenderer.margin = new Charting.Margins(10, 0, 0, 0);<\/pre>\n<p>The renderers have various properties for specifying how the axes will be rendered. We use <a title=\"Charting for JavaScript API Reference: margin\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_Components_Component_margin_0_0.htm\">margin<\/a> to add some space around the two axes.<\/p>\n<p>Finally, we use the <a title=\"Charting for JavaScript API Reference: layoutBuilder\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_Controls_Dashboard_layoutBuilder_0.htm\">layoutBuilder<\/a> property of the <a title=\"Charting for JavaScript API Reference: Dashboard\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Controls_Dashboard_Members.htm\">Dashboard<\/a> class to create a <a title=\"Charting for JavaScript API Reference: GridPanel\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Components_GridPanel_0.htm\">GridPanel<\/a> that will correctly measure and arrange all building blocks of our cobination chart:<\/p>\n<pre>dashboard.layoutBuilder.createAndAddPlotAndAxes(\n\t\tplot, null,\n\t\t[yAxisRenderer],\n\t\t[ xAxisRenderer ],\n\t\tnull);<\/pre>\n<p><strong>V. The Legend<\/strong><\/p>\n<p>As we said, the legend items are taken from the <a title=\"Charting for JavaScript API Reference: title\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_Axis_title_0_0.htm\">title<\/a> property of each <a title=\"Charting for JavaScript API Reference: Series\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Series_0.htm\">Series<\/a> . We use a <a title=\"Charting for JavaScript API Reference: LegendRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_LegendRenderer_Members_0.htm\">LegendRenderer<\/a> to render the legend and set some of its properties:<\/p>\n<pre>\/\/ add legend\nvar legendRenderer = new Charting.LegendRenderer();\nlegendRenderer.content = new Collections.ObservableCollection([barRenderer, lineRenderer]);\nlegendRenderer.background = new Drawing.Brush(\"#d0d3fb\");\nlegendRenderer.borderStroke = new Drawing.Brush(\"#BDBFAA\");\nlegendRenderer.showTitle = false;\nlegendRenderer.horizontalAlignment = Components.LayoutAlignment.Far;<\/pre>\n<p>The <a title=\"Charting for JavaScript API Reference: content\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_LegendRenderer_content_0_0.htm\">content<\/a> property of <a title=\"Charting for JavaScript API Reference: LegendRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_LegendRenderer_Members_0.htm\">LegendRenderer<\/a> allows us to specify a collection of <a title=\"Charting for JavaScript API Reference: SeriesRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_SeriesRenderer_Members_0.htm\">SeriesRenderer<\/a> instances. This way we can have one legend for series of different kinds. We don&#8217;t need a title for our legend, so we set <a title=\"Charting for JavaScript API Reference: showTitle\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_LegendRenderer_showTitle_0_0.htm\">showTitle<\/a> to false.<\/p>\n<p>The <a title=\"Charting for JavaScript API Reference: LegendRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_LegendRenderer_Members_0.htm\">LegendRenderer<\/a> requires no special positioning in the dashboard layout, so we simple add it to the <a title=\"Charting for JavaScript API Reference: rootPanel\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_Controls_Dashboard_rootPanel_0.htm\">rootPanel<\/a> of the <a title=\"Charting for JavaScript API Reference: Dashboard\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Controls_Dashboard_Members.htm\">Dashboard<\/a> and let it handle its easure and placement:<\/p>\n<pre>dashboard.rootPanel.children.add(legendRenderer);<\/pre>\n<p><strong>VI. The Title and Subtitle<\/strong><\/p>\n<p>The title is an instance of the <a title=\"Charting for JavaScript API Reference: TextComponent\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Components_TextComponent_Members_0.htm\">TextComponent<\/a> class:<\/p>\n<pre>var tc = new Components.TextComponent();\ntc.text = \"STEADY GROWTH\";\ntc.fontSize = 20.4;\ntc.horizontalAlignment = Components.LayoutAlignment.Near;\ntc.margin = new Charting.Margins(100, 10, 0, 0);\ndashboard.layoutPanel.children.add(tc);<\/pre>\n<p>It has various appearance properties. Just like the <a title=\"Charting for JavaScript API Reference: LegendRenderer\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_LegendRenderer_Members_0.htm\">LegendRenderer<\/a> the <a title=\"Charting for JavaScript API Reference: TextComponent\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?T_MindFusion_Charting_Components_TextComponent_Members_0.htm\">TextComponent<\/a> can be added directly to the <a title=\"Charting for JavaScript API Reference: children\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?P_MindFusion_Charting_Components_Panel_children_0_0.htm\">children<\/a> of the layoutPanel.<\/p>\n<p>Now that we&#8217;ve made all arrangements for the chart let&#8217;s not forget to call the <a title=\"Charting for JavaScript API Reference: draw\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/chart.javascript\/index.htm?M_MindFusion_Charting_Controls_Dashboard_draw_3_Graphics_Rect_Rect.htm\">draw<\/a> method that will render the chart on the screen:<\/p>\n<pre>dashboard.draw();<\/pre>\n<p>That was everything. You can see an online demo of the chart here.<\/p>\n<p>You can download the full source code of this combination chart in JavaScript together with all used libraries from here:<\/p>\n<p align=\"center\"><a title=\"Combination Chart in JavaScript Sample\" href=\"https:\/\/mindfusion.dev\/samples\/javascript\/chart\/CombinationChart.zip\">Combination Chart in JavaScript Full Code<\/a><\/p>\n<p><i>About Charting for JavaScript:<\/i> MindFusion library for interactive charts and gauges. It supports all common chart types including 3D bar charts. Charts can have a grid, a legend, unlimitd number of axes and series. Scroll, zoom and pan are supported out of the box. You can easily create your own chart series by implementing the Series interface.<br \/>The gauges library is part of Charting for JavaScript. It supports oval and linear gauge with several types of labels and ticks. Various samples show you how the implement the gauges to create and customize all popular gauge types: car dashboard, clock, thermometer, compass etc. Learn more about Charting and Gauges for JavaScript at <a title=\"JavaScript Chart Library\" href=\"https:\/\/mindfusion.dev\/javascript-chart.html\">https:\/\/mindfusion.dev\/javascript-chart.html<\/a>.<\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog post we will use the Charting for JavaScript library to create the chart that you see below: This is a combination chart has one line series and two bar series drawn in stacks. We will use the &hellip; <a href=\"https:\/\/mindfusion.dev\/blog\/combination-chart-in-javascript\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[61,513,74],"tags":[70,319,567,564,563],"class_list":["post-2158","post","type-post","status-publish","format-standard","hentry","category-charting-2","category-javascript","category-sample-code","tag-chart","tag-combination-chart","tag-javascript-chart-code","tag-js-combi-chart","tag-sample-js-code"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3RlKs-yO","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/2158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/comments?post=2158"}],"version-history":[{"count":7,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/2158\/revisions"}],"predecessor-version":[{"id":2632,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/2158\/revisions\/2632"}],"wp:attachment":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/media?parent=2158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/categories?post=2158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/tags?post=2158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}