Average of hail size and average property damage estimates over months, with two y-axes measuring different types of values (inches vs dollars).
What is a combo bar line chart?
Combo bar line charts provide the visualization of bar and line series in a single chart, allowing you to use the appropriate series type for the data, while also being able to compare and analyze the relationship between the two series. The chart can either have one x-axis and one or two y-axes. The x-axis represents discrete categories or continuous values depending on the field type. The y-axis or y-axes represent the associated numeric value that corresponds to each category or continuous interval on the x-axis.
Data configurations
This section demonstrates how different data configurations can be used to create various types of combo bar line charts.
With one y-axis
When the series are all measuring the same type of value, or are at least in a similar range, you can use a single y-axis to visualize the data.
When an x-axis field is specified, the chart will use the unique values provided as the x-axis categories.
The above chart visualizes property damange and agricultural loss estimates over months, with the property damange estimates rendered as bars and the agricultural loss estimates rendered as a line.
- Set the
xAxisFieldproperty to"mo"to use the unique values in the months field as the x-axis categories. - Set the
numericFieldsproperty to["loss", "closs"]to specify the fields that will be visualized. - Next use the
setSeriesTypemethod to set the series type for each field. In this case, we will set the"loss"field (property damage) to be rendered as bars and the"closs"field (agricultural loss) to be rendered as a line.
33 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Esri Developer Guide: Combo Bar Line Chart</title> <style> html, body, arcgis-chart { height: 100%; margin: 0; } </style> <!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script type="module" src="https://js.arcgis.com/5.1/"></script> </head>
<body> <arcgis-chart></arcgis-chart> <script type="module"> const { createModel } = await $arcgis.import("@arcgis/charts-components/model/shared/setup-utils.js"); const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js"); const featureLayer = new FeatureLayer({ portalItem: { id: "5972242f44714758b97c415a62a49ad5", }, }); const chartElement = document.querySelector("arcgis-chart"); const comboBarLineChartModel = await createModel({ layer: featureLayer, chartType: "comboBarLineChart", });
comboBarLineChartModel.xAxisField = "mo"; comboBarLineChartModel.numericFields = ["loss", "closs"]; // Set series type for each numeric fieid comboBarLineChartModel.setSeriesType(0, "barSeries"); comboBarLineChartModel.setSeriesType(1, "lineSeries");13 collapsed lines
comboBarLineChartModel.setSeriesColor([78, 121, 167, 100], 0); comboBarLineChartModel.setSeriesColor([242, 142, 44, 100], 1); comboBarLineChartModel.setSeriesLineWidth(5, 1); comboBarLineChartModel.setAxisTitleText("Months", 0); comboBarLineChartModel.setAxisTitleText("Dollar Value", 1); comboBarLineChartModel.titleText = "Average Property Damage Estimates and Crop Loss Over Months"; comboBarLineChartModel.legendPosition = "top"; chartElement.model = comboBarLineChartModel; chartElement.actionMode = "none"; </script> </body></html>With two y-axes
When the two series are measuring different types of values, or are in very different ranges, you can use two y-axes to visualize the data. The primary y-axis will be used for the first series, and the secondary y-axis will be used for the second series.
The above chart visualizes average hail size and average property damage estimates over months, with the average hail size rendered as a line and the average property damage estimates rendered as bars. Each series is using a different y-axis since they are measuring different types of values (inches vs dollars) and are in very different ranges.
- With the similar data configuration steps as the previous example, set the x-axis field and numeric fields, and define the series type for each field.
- Then use the
setAssignToSecondValueAxismethod to assign the second series to the secondary y-axis.
40 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Esri Developer Guide: Combo Dual Axes</title> <style> html, body, arcgis-chart { height: 100%; margin: 0; } </style> <!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script type="module" src="https://js.arcgis.com/5.1/"></script> </head>
<body> <arcgis-chart></arcgis-chart> <script type="module"> const { createModel } = await $arcgis.import("@arcgis/charts-components/model/shared/setup-utils.js"); const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js"); const featureLayer = new FeatureLayer({ portalItem: { id: "5972242f44714758b97c415a62a49ad5", }, }); const chartElement = document.querySelector("arcgis-chart"); const comboBarLineChartModel = await createModel({ layer: featureLayer, chartType: "comboBarLineChart", });
comboBarLineChartModel.xAxisField = "mo"; comboBarLineChartModel.numericFields = ["mag", "loss"]; comboBarLineChartModel.aggregationType = "avg";
comboBarLineChartModel.setSeriesType(0, "lineSeries"); comboBarLineChartModel.setSeriesType(1, "barSeries");
comboBarLineChartModel.setAssignToSecondValueAxis(true, 1);14 collapsed lines
comboBarLineChartModel.setSeriesColor([78, 121, 167, 100], 0); comboBarLineChartModel.setSeriesColor([242, 142, 44, 100], 1); comboBarLineChartModel.setSeriesLineWidth(8, 1); comboBarLineChartModel.setAxisTitleText("Months", 0); comboBarLineChartModel.setAxisTitleText("Inches", 1); comboBarLineChartModel.setAxisTitleText("Dollar Value", 2); comboBarLineChartModel.titleText = "Average Hail Size and Average Property Damage Estimates Over Months"; comboBarLineChartModel.legendPosition = "top"; chartElement.model = comboBarLineChartModel; chartElement.actionMode = "none"; </script> </body></html>