Overview
Application Scenario
The population pyramid is a bar chart in the pyramid shape that shows the distribution of the population by age and gender, visually showing the proportions of population in different ages and gender.
The horizontal axis represents the population size, the vertical axis represents age groups, and the gender of the population is distinguished by different colors. The following figure shows the effect.
Implementation Method
Two key points to be noted to achieve the dual-way bar chart:
1. The auxiliary data is required. For example, you need to use the auxiliary data to transform the number of female/male population (positive numbers) to negative numbers to achieve the opposite direction effect.
2. As the auxiliary data contains negative numbers, the X axis of the chart coordinate axis will also display negative numbers. In this case, you need to customize the format of the axis labels by choosing Style > Axis > X Axis > Format on the chart attribute panel to display negative numbers as positive numbers.
Example
Data Preparation
You can download the sample data: Population Structure.xlsx.
Create a general report, click Excel Dataset, and upload the downloaded Excel file data to the report.
In this example, the template has been output as a built-in dataset Population Structure, where the male population data in the auxiliary column is negative, and the female population data is positive, as shown in the following figure.
Chart Insertion
Merge required cells, click the Insert Chart icon on the toolbar, select Bar Chart, and click OK, as shown in the following figure.
Chart Design
Data Binding
Select the chart, and bind the data to it, as shown in the following figure.
Style Setting
1. Choose Style > Title on the chart attribute panel, and enter the text Population Pyramid, as shown in the following figure. .
2. Choose Style > Series on the attribute panel, and set Series Gap to -100% to ensure that there is no gap between the series to avoid misalignment, as shown in the following figure.
3. Choose Style > Axis on the attribute panel, and customize the X axis label format to display numbers smaller than 0 as positive numbers by multiplying them by -1.
The code is as follows:
function() {
if (this > 0) return this ;
else return this * (-1) ;
}
The following figure shows the setting.
4. As the chart data uses an auxiliary column, the population data for males in the chart labels or prompts is also displayed as negative numbers. In this case, you can set the labels or prompts as Rich Text and select the Population field from Dataset Field, which are all positive numbers, as shown in the following figure.
Effect Display
PC
Save the report and click Pagination Preview. The following figure shows the effect.
Mobile Terminal
The report can be previewed on the DataAnalyst APP and H5 terminal, as shown in the following figure.
Template Download
For details, you can click to download the template Population Pyramid.cpt.