DWS Asset Allocation Pie

Shows DWS fund asset allocation as two pie charts with synchronized data grids. author(s): Askel Eirik Johansson

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/grid-pro/grid-pro.js"></script>
<script src="https://code.highcharts.com/dashboards/dashboards.js"></script>
<script src="https://code.highcharts.com/dashboards/modules/layout.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script src="https://code.highcharts.com/connectors/morningstar/connectors-morningstar-dws.js"></script>

<div class="demo-wrapper">
    <h1>Highcharts Dashboards + Morningstar Investment Details data</h1>
    <p>Performance ID: <b>0P00000FIA</b></p>
    <div id="container"></div>

    <p class="highcharts-description">
        Shows DWS fund asset allocation as two pie charts with synchronized
        data grids.
    </p>
</div>

CSS

@import url("https://code.highcharts.com/grid-pro/css/grid-pro.css");
@import url("https://code.highcharts.com/dashboards/css/dashboards.css");

body {
    font-family: sans-serif;
    padding: 10px;
    background: var(--highcharts-background-color);
    color: var(--highcharts-neutral-color-100);
}

.demo-wrapper {
    max-width: 1000px;
    margin: 0 auto;
}

/* Themes */
.theme-custom {
    --hcg-border-radius: 5px;
    --hcg-color: var(--highcharts-neutral-color-100);
    --hcg-vertical-padding: 9px;
    --hcg-horizontal-padding: 4px;
    --hcg-border-width: 0;
    --hcg-border-color: var(--highcharts-neutral-color-20);
    --hcg-background: transparent;
    --hcg-header-column-border-width: 0;
    --hcg-header-background: transparent;
    --hcg-font-size: 16px;
    --hcg-header-row-border-color: transparent;
    --hcg-row-border-color: transparent;

    /* Hovered colors */
    --hcg-cell-hovered-background: var(--highcharts-neutral-color-5);
    --hcg-row-hovered-background: var(--highcharts-neutral-color-5);
    --hcg-column-hovered-background: var(--highcharts-neutral-color-5);
    --hcg-header-column-hovered-background: var(--highcharts-neutral-color-5);
    --hcg-header-cell-hovered-background: var(--highcharts-neutral-color-5);
    --hcg-cell-hovered-row-background: var(--highcharts-neutral-color-5);

    /* Loader */
    --hcg-loader-color: var(--highcharts-neutral-color-60);
}

#container .highcharts-dashboards-wrapper {
    border: 1px solid var(--highcharts-neutral-color-20);
    border-radius: 6px;
    background-color: var(--highcharts-background-color);
    padding: 10px 15px 0;
    margin: 0 0 30px;
}

#container .highcharts-dashboards-cell > .highcharts-dashboards-component {
    border: none;
    box-shadow: none;
    background-color: transparent;
}

.highcharts-dashboards-layouts-wrapper {
    height: 100%;
}

th:not(:first-child) .hcg-header-cell-content,
td:not(:first-child) {
    text-align: right !important;
}

td:first-child {
   ...

JavaScript

const assetAllocationTypes = {
    Stock: 'Stock',
    Bond: 'Bond',
    Cash: 'Cash',
    ConvBond: 'Conv Bond',
    Equity: 'Equity',
    Other: 'Other',
    CanadianEquity: 'Canadian Equity',
    InternationalEquity: 'International Equity',
    USEquity: 'US Equity',
    FixedIncome: 'Fixed Income'
};

// Helper functions
Highcharts.Templating.helpers.translateAssetAllocation = value =>
    assetAllocationTypes[value];

const basicTypes = ['Bond', 'Cash', 'ConvBond', 'Equity', 'Other'],
    canadianTypes = [
        'CanadianEquity', 'InternationalEquity', 'USEquity', 'Cash',
        'FixedIncome', 'Other'
    ];

const pieColors = [
    '#014CE5',
    '#29D36A',
    '#EA293C',
    'var(--highcharts-neutral-color-100, #000)',
    '#F99406'
];

function getTypeColors(types) {
    let colorIndex = -1;
    return types.map(type => (
        type === 'Other' ?
            '#ABABAB' :
            pieColors[++colorIndex % pieColors.length]
    ));
}

function getTypeColor(types, type) {
    return getTypeColors(types)[types.indexOf(type)];
}

const getPieChartOptions = types => ({
    chart: {
        type: 'pie',
        backgroundColor: 'transparent'
    },
    title: {
        text: '',
        verticalAlign: 'middle',
        y: 30,
        style: {
            fontSize: '28px',
            fontWeight: 'bold'
        }
    },
    subtitle: {
        text: 'Total assets',
        y: -10,
        verticalAlign: 'middle',
        style: {
            fontSize: '14px',
            color: 'var(--highcharts-neutral-color-60, #767676)'
        }
    },
    plotOptions: {
        pie: {
            // A fixed diameter, so both pies match even though their rows
            // differ in height with the number of grid rows.
            size: 223,
            innerSize: '90%',
            borderWidth: 4,
            borderRadius: '50%',
            colors: getTypeColors(types),
            dataLabels: {
                enabled: false
            },
            states: {
   ...