Examples of chart with asset allocations over time

Necessary parts

Chart container

The chart container is identified by the ID attribute. Be sure to use the same ID in HTML and the Highcharts script.

<div id="chartcontainer"></div>

Highcharts options

There are some base Highcharts options which have to be set (e.g. language specific).

// Global options
Highcharts.setOptions({
    global: {
        timezoneOffset: 0 * 60
    },
    lang: {

        months: ["Januar", "Februar", "M\u00e4rz", "April", "Mai", "Juni",
            "Juli", "August", "September", "Oktober", "November",
            "Dezember"],
        shortMonths: ["Jan", "Feb", "M\u00e4r", "Apr", "Mai", "Jun",
            "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
        weekdays: ["Sonntag", "Montag", "Dienstag", "Mittwoch",
            "Donnerstag", "Freitag", "Samstag"],
        rangeSelectorZoom: '',
        rangeSelectorFrom: 'Von',
        rangeSelectorTo: 'Bis',
        thousandsSep: '.',
        decimalPoint: ',',
        downloadJPEG: 'als JPG herunterladen',
        downloadPDF: 'als PDF herunterladen',
        downloadPNG: 'als PNG herunterladen',
        downloadSVG: 'als SVG herunterladen',
        printChart: 'Chart drucken'

    },
    title: {
        style: {
            color: '#648caa'
        }
    },
    exporting: {
        buttons: {
            contextButton: {
                symbolStroke: '#648caa',
                symbolFill: '#fff',
                theme: {
                    'stroke-width': 1,
                    r: 0,
                    states: {
                        hover: {
                            fill: '#fff',
                            stroke: '#648caa'
                        },
                        select: {
                            fill: '#fff'
                        }
                    }
                }
            }
        },
        scale: 2,
        chartOptions: {
            events: {
                load: function () {
                    this.legend.render();
                }
            },
            rangeSelector: {
                buttons: []
            }
        }
    }
});

Formatting

The function formatAllocations is mandatory to format the API data for use in Highcharts.

// Reformat data from JSON API structure to Highcharts
function formatAllocations(allocationsJSON, colors) {
    const allSeriesData = [];
    let i = 0;

    Object.entries(allocationsJSON).forEach(entry => {
        const [name, values] = entry;

        const seriesData = {
            name: name,
            data: [],
            color: colors[i]
        }

        $.each(values, function (isoDate, value) {
            seriesData.data.push([
                Date.parse(isoDate),
                value
            ]);
        });

        allSeriesData.push(seriesData);
        i++;
    });

    return allSeriesData;
}

AJAX request to the Fund-API and instantiating of the Highcharts chart

This is the central code for generating the chart.

// Get performance data for fund with ISIN DE0008479098
$.getJSON('https://api.hansainvest.com/api/v2/asset-allocations/with-derivatives/DE0008479098', function (json_data) {

    var chart1 = new Highcharts.stockChart(
        {
            "title": {
                "text": json_data.fund.name + ' – ' + json_data.fund.isin
            },
            "chart": {
                "renderTo": "chart1"
            },
            "legend": {
                "enabled": true,
                "layout": "horizontal",
                "verticalAlign": "bottom",
                "useHTML": false,
                "labelFormatter": function () {
                    var series = this;
                    var currentChart = series.chart;
                    var dates = series.processedXData !== undefined ? series.processedXData : series.xData;
                    var values = series.processedYData !== undefined ? series.processedYData : series.yData;
                    var minDate = currentChart.rangeSelector.minInput !== undefined ? currentChart.rangeSelector.minInput.HCTime : dates[0];
                    var maxDate = currentChart.rangeSelector.maxInput !== undefined && currentChart.rangeSelector.maxInput.HCTime <= dates[values.length - 1] ? currentChart.rangeSelector.maxInput.HCTime : dates[values.length - 1];
                    var firstValue = values[0];
                    var compareValue = series.compareValue;

                    if (isNaN(compareValue)) {
                        compareValue = firstValue;
                    }

                    var endValue = values[values.length - 1];
                    if (dates[values.length - 1] > maxDate) {
                        for (var j = values.length - 1; j > values.length - 10; j--) {
                            if (dates[j] <= maxDate) {
                                endValue = values[j];
                                break;
                            }
                        }
                    }

                    var change = Math.round(((endValue / compareValue * 100) - 100) * 100) / 100;

                    var legendText = series.name;
                    legendText = '<span style="color:' + series.color + '">' + legendText + '</span><br>' + (change > 0 ? '+' : '') + Highcharts.numberFormat(change, 2, ',') + ' %';
                    return legendText;

                }
            },
            "credits": {
                "enabled": false
            },
            "exporting": {
                "chartOptions": {
                    "title": {
                        "text": json_data.fund.name + " - Wertentwicklung"
                    }
                },
                "filename": json_data.fund.isin + "_-_Wertentwicklung"
            },
            "series": [{
                "name": json_data.fund.name + ' – ' + json_data.fund.isin,
                "data": json_data.performance,
                "turboThreshold": 0,
                "tooltip": {
                    "valueDecimals": 2
                },
                "color": "#648caa"
            }],
            "xAxis": {
                "startOnTick": true,
                "endOnTick": true,
                "ordinal": false,
                "events": {
                    "afterSetExtremes": function (e) {
                        var legend = this.chart.legend;
                        setTimeout(function () {
                            legend.render();
                        }, 100);

                        $('.highcharts-input-group').find('g:eq(1),g:eq(3)').trigger('change');

                        $('.rsbutton.is-active').removeClass('is-active');

                        setTimeout(function () {

                        }, 0);
                    }
                }
            },
            "yAxis": {
                "labels": {
                    "formatter": function () {
                        return (this.value > 0 ? ' + ' : '') + this.value + '%';
                    }
                }
            },
            "plotOptions": {
                "series": {
                    "compare": "percent",
                    "dataGrouping": {
                        "enabled": false
                    }
                }
            },
            "tooltip": {
                "changeDecimals": 2,
                "valueDecimals": 2,
                "pointFormat": '<span style="color:{series.color}">{series.name}</span>: {point.change} %<br/>'
            }
        });
});

Optional parts

Exporting

The basic JS includes including the Highcharts exporting plugin

<!-- move to closing body tag -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js" crossorigin="anonymous"></script>
<script src="https://code.highcharts.com/10.2/highcharts.js" crossorigin="anonymous"></script>
<script src="https://code.highcharts.com/10.2/modules/exporting.js" crossorigin="anonymous"></script>

<!-- place the individual Highcharts code below as inline script or include -->

Resizing

Resizing of the chart if the viewport or the visibility of the chart changes.

/**
 * Adjust size for hidden charts
 * @param chart highcharts
 */
function adjustGraph(chart) {
    try {
        if (typeof (chart === 'undefined' || chart === null)
            && this instanceof jQuery) { // if no obj chart and the context is set
            this.find('.chart-container:visible').each(
                function () { // for only visible charts container in the curent context
                    $container = $(this); // context container
                    $container.find('div[id^="chart-"]').each(
                        function () { // for only chart
                            $chart = $(this).highcharts(); // cast from JQuery to highcharts obj
                            $chart.setSize($container.width(),
                                $chart.chartHeight,
                                doAnimation = true); // adjust chart size with animation transition
                        });
                });
        } else {
            chart.setSize($('.chart-container:visible').width(),
                chart.chartHeight, doAnimation = true); // if chart is set, adjust
        }
    } catch (err) {
        // do nothing
    }
}

$(function (H) {

    $(window).resize(function () {
        if (this.resizeTO)
            clearTimeout(this.resizeTO);
        this.resizeTO = setTimeout(function () {
            // resizeEnd call function with pass context body
            adjustGraph.call($('body'));
        }, 500);
    });

});

Normal (HANSAINVEST) styling

<div id="chart1"></div>

<!-- move to closing body tag -->

<!-- use jQuery only in necessary -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js" crossorigin="anonymous"></script>
<!-- Highcharts is mandatory -->
<script src="https://code.highcharts.com/10.2/highcharts.js" crossorigin="anonymous"></script>
<!-- use Highcharts exporting plugin only in necessary -->
<script src="https://code.highcharts.com/10.2/modules/exporting.js" crossorigin="anonymous"></script>

<!-- place the individual Highcharts code below as inline script or include -->
// Reformat data from JSON API structure to Highcharts
function formatAllocations(allocationsJSON, colors) {
    const allSeriesData = [];
    let i = 0;

    Object.entries(allocationsJSON).forEach(entry => {
        const [name, values] = entry;

        const seriesData = {
            name: name,
            data: [],
            color: colors[i]
        }

        $.each(values, function (isoDate, value) {
            seriesData.data.push([
                Date.parse(isoDate),
                value
            ]);
        });

        allSeriesData.push(seriesData);
        i++;
    });

    return allSeriesData;
}

/**
 * Adjust size for hidden charts
 * @param chart highcharts
 */
function adjustGraph(chart) {
    try {
        if (typeof (chart === 'undefined' || chart === null)
            && this instanceof jQuery) { // if no obj chart and the context is set
            this.find('.chart-container:visible').each(
                function () { // for only visible charts container in the curent context
                    $container = $(this); // context container
                    $container.find('div[id^="chart-"]').each(
                        function () { // for only chart
                            $chart = $(this).highcharts(); // cast from JQuery to highcharts obj
                            $chart.setSize($container.width(),
                                $chart.chartHeight,
                                doAnimation = true); // adjust chart size with animation transition
                        });
                });
        } else {
            chart.setSize($('.chart-container:visible').width(),
                chart.chartHeight, doAnimation = true); // if chart is set, adjust
        }
    } catch (err) {
        // do nothing
    }
}

$(function (H) {

    $(window).resize(function () {
        if (this.resizeTO)
            clearTimeout(this.resizeTO);
        this.resizeTO = setTimeout(function () {
            // resizeEnd call function with pass context body
            adjustGraph.call($('body'));
        }, 500);
    });

});

// Global options
Highcharts.setOptions({
    global: {
        timezoneOffset: 0 * 60
    },
    lang: {

        months: ["Januar", "Februar", "M\u00e4rz", "April", "Mai", "Juni",
            "Juli", "August", "September", "Oktober", "November",
            "Dezember"],
        shortMonths: ["Jan", "Feb", "M\u00e4r", "Apr", "Mai", "Jun",
            "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
        weekdays: ["Sonntag", "Montag", "Dienstag", "Mittwoch",
            "Donnerstag", "Freitag", "Samstag"],
        rangeSelectorZoom: '',
        rangeSelectorFrom: 'Von',
        rangeSelectorTo: 'Bis',
        thousandsSep: '.',
        decimalPoint: ',',
        downloadJPEG: 'als JPG herunterladen',
        downloadPDF: 'als PDF herunterladen',
        downloadPNG: 'als PNG herunterladen',
        downloadSVG: 'als SVG herunterladen',
        printChart: 'Chart drucken'

    },
    title: {
        style: {
            color: '#648caa'
        }
    },
    exporting: {
        buttons: {
            contextButton: {
                symbolStroke: '#648caa',
                symbolFill: '#fff',
                theme: {
                    'stroke-width': 1,
                    r: 0,
                    states: {
                        hover: {
                            fill: '#fff',
                            stroke: '#648caa'
                        },
                        select: {
                            fill: '#fff'
                        }
                    }
                }
            }
        },
        scale: 2,
        chartOptions: {
            events: {
                load: function () {
                    this.legend.render();
                }
            },
            rangeSelector: {
                buttons: []
            }
        }
    }
});

// Get asset allocations data for fund with ISIN DE0009799718
$.getJSON('https://api.hansainvest.com/api/v2/asset-allocations/with-derivatives/DE0009799718/', function (json_data) {

    const colors = ["#466e8c", "#648caa", "#7b9db7", "#92aec4", "#aac0d0", "#c1d1dd", "#6e0532", "#8c2350", "#9d446a", "#ae6585"];

    const chart1 = new Highcharts.Chart(
        {
            "chart": {
                "renderTo": "chart1",
                "type": "area"
            },
            "title": {
                "text": json_data.fund.name + ' – ' + json_data.fund.isin
            },
            "credits": {
                "enabled": false
            },
            "legend": {
                "enabled": true,
                "navigation": {
                    "enabled": false
                },
                "symbolRadius": 0,
                "layout": "horizontal",
                "verticalAlign": "bottom",
                "floating": false,
                "align": "center",
                "x": 40,
                "y": 0,
                "padding": 0,
                "useHTML": false,
                "itemStyle": {
                    "fontWeight": "normal"
                }
            },
            "plotOptions": {
                "area": {
                    "stacking": "percent",
                    "marker": {
                        "enabled": false
                    }
                }
            },
            "yAxis": [
                {
                    "gridLineDashStyle": "Dot",
                    "gridLineColor": "#648caa",
                    "min": 0,
                    "labels": {
                        "format": "{value} %",
                        "y": 8,
                        "style": {
                            "fontSize": "13.5px"
                        }
                    },
                    "title": {
                        "text": null
                    }
                }
            ],
            "xAxis": [
                {
                    "type": "datetime",
                    "dateTimeLabelFormats": {
                        "month": "%b %Y"
                    },
                    "gridLineDashStyle": "Dot",
                    "gridLineWidth": 1,
                    "gridLineColor": "#648caa",
                    "startOnTick": false,
                    "endOnTick": false,
                    "labels": {
                        "style": {
                            "fontSize": "13.5px"
                        }
                    }
                }
            ],
            "labels": {
                "style": {
                    "fontSize": "13px"
                }
            },
            "series": formatAllocations(json_data.allocations, colors)
        });
});

Different colors

<div id="chart2"></div>

<!-- move to closing body tag -->

<!-- use jQuery only in necessary -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js" crossorigin="anonymous"></script>
<!-- Highcharts is mandatory -->
<script src="https://code.highcharts.com/10.2/highcharts.js" crossorigin="anonymous"></script>
<!-- use Highcharts exporting plugin only in necessary -->
<script src="https://code.highcharts.com/10.2/modules/exporting.js" crossorigin="anonymous"></script>

<!-- place the individual Highcharts code below as inline script or include -->
// Reformat data from JSON API structure to Highcharts
function formatAllocations(allocationsJSON, colors) {
    const allSeriesData = [];
    let i = 0;

    Object.entries(allocationsJSON).forEach(entry => {
        const [name, values] = entry;

        const seriesData = {
            name: name,
            data: [],
            color: colors[i]
        }

        $.each(values, function (isoDate, value) {
            seriesData.data.push([
                Date.parse(isoDate),
                value
            ]);
        });

        allSeriesData.push(seriesData);
        i++;
    });

    return allSeriesData;
}

/**
 * Adjust size for hidden charts
 * @param chart highcharts
 */
function adjustGraph(chart) {
    try {
        if (typeof (chart === 'undefined' || chart === null)
            && this instanceof jQuery) { // if no obj chart and the context is set
            this.find('.chart-container:visible').each(
                function () { // for only visible charts container in the curent context
                    $container = $(this); // context container
                    $container.find('div[id^="chart-"]').each(
                        function () { // for only chart
                            $chart = $(this).highcharts(); // cast from JQuery to highcharts obj
                            $chart.setSize($container.width(),
                                $chart.chartHeight,
                                doAnimation = true); // adjust chart size with animation transition
                        });
                });
        } else {
            chart.setSize($('.chart-container:visible').width(),
                chart.chartHeight, doAnimation = true); // if chart is set, adjust
        }
    } catch (err) {
        // do nothing
    }
}

$(function (H) {

    $(window).resize(function () {
        if (this.resizeTO)
            clearTimeout(this.resizeTO);
        this.resizeTO = setTimeout(function () {
            // resizeEnd call function with pass context body
            adjustGraph.call($('body'));
        }, 500);
    });

});

// Global options
Highcharts.setOptions({
    global: {
        timezoneOffset: 0 * 60
    },
    lang: {

        months: ["Januar", "Februar", "M\u00e4rz", "April", "Mai", "Juni",
            "Juli", "August", "September", "Oktober", "November",
            "Dezember"],
        shortMonths: ["Jan", "Feb", "M\u00e4r", "Apr", "Mai", "Jun",
            "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
        weekdays: ["Sonntag", "Montag", "Dienstag", "Mittwoch",
            "Donnerstag", "Freitag", "Samstag"],
        rangeSelectorZoom: '',
        rangeSelectorFrom: 'Von',
        rangeSelectorTo: 'Bis',
        thousandsSep: '.',
        decimalPoint: ',',
        downloadJPEG: 'als JPG herunterladen',
        downloadPDF: 'als PDF herunterladen',
        downloadPNG: 'als PNG herunterladen',
        downloadSVG: 'als SVG herunterladen',
        printChart: 'Chart drucken'

    },
    title: {
        style: {
            color: '#648caa'
        }
    },
    exporting: {
        buttons: {
            contextButton: {
                symbolStroke: '#648caa',
                symbolFill: '#fff',
                theme: {
                    'stroke-width': 1,
                    r: 0,
                    states: {
                        hover: {
                            fill: '#fff',
                            stroke: '#648caa'
                        },
                        select: {
                            fill: '#fff'
                        }
                    }
                }
            }
        },
        scale: 2,
        chartOptions: {
            events: {
                load: function () {
                    this.legend.render();
                }
            },
            rangeSelector: {
                buttons: []
            }
        }
    }
});

// Get asset allocations data for fund with ISIN DE0008479098
$.getJSON('https://api.hansainvest.com/api/v2/asset-allocations/without-derivatives/DE0008479098/', function (json_data) {

    const colors = ["#003f5c", "#ffa600", "#a05195", "#2f4b7c", "#ff7c43", "#665191", "#d45087", "#bada55", "#f95d6a", "#e67f83"];

    const chart2 = new Highcharts.Chart(
        {
            "chart": {
                "renderTo": "chart2",
                "type": "area"
            },
            "title": {
                "text": json_data.fund.name + ' – ' + json_data.fund.isin,
                "style": {
                    "color": "#666"
                }
            },
            "credits": {
                "enabled": false
            },
            "legend": {
                "enabled": true,
                "navigation": {
                    "enabled": false
                },
                "symbolRadius": 0,
                "layout": "horizontal",
                "verticalAlign": "bottom",
                "floating": false,
                "align": "center",
                "x": 40,
                "y": 0,
                "padding": 0,
                "useHTML": false,
                "itemStyle": {
                    "fontWeight": "normal"
                }
            },
            "plotOptions": {
                "area": {
                    "stacking": "percent",
                    "marker": {
                        "enabled": false
                    }
                }
            },
            "yAxis": [
                {
                    "gridLineDashStyle": "Dot",
                    "gridLineColor": "#666666",
                    "min": 0,
                    "labels": {
                        "format": "{value} %",
                        "y": 8,
                        "style": {
                            "fontSize": "13.5px"
                        }
                    },
                    "title": {
                        "text": null
                    }
                }
            ],
            "xAxis": [
                {
                    "type": "datetime",
                    "dateTimeLabelFormats": {
                        "month": "%b %Y"
                    },
                    "gridLineDashStyle": "Dot",
                    "gridLineWidth": 1,
                    "gridLineColor": "#666666",
                    "startOnTick": false,
                    "endOnTick": false,
                    "labels": {
                        "style": {
                            "fontSize": "13.5px"
                        }
                    }
                }
            ],
            "labels": {
                "style": {
                    "fontSize": "13px"
                }
            },
            "series": formatAllocations(json_data.allocations, colors)
        }
    );
});

Different width, colors and chart type

<div id="chart3"></div>

<!-- move to closing body tag -->

<!-- use jQuery only in necessary -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js" crossorigin="anonymous"></script>
<!-- Highcharts is mandatory -->
<script src="https://code.highcharts.com/10.2/highcharts.js" crossorigin="anonymous"></script>
<!-- use Highcharts exporting plugin only in necessary -->
<script src="https://code.highcharts.com/10.2/modules/exporting.js" crossorigin="anonymous"></script>

<!-- place the individual Highcharts code below as inline script or include -->
// Reformat data from JSON API structure to Highcharts
function formatAllocations(allocationsJSON, colors) {
    const allSeriesData = [];
    let i = 0;

    Object.entries(allocationsJSON).forEach(entry => {
        const [name, values] = entry;

        const seriesData = {
            name: name,
            data: [],
            color: colors[i]
        }

        $.each(values, function (isoDate, value) {
            seriesData.data.push([
                Date.parse(isoDate),
                value
            ]);
        });

        allSeriesData.push(seriesData);
        i++;
    });

    return allSeriesData;
}

/**
 * Adjust size for hidden charts
 * @param chart highcharts
 */
function adjustGraph(chart) {
    try {
        if (typeof (chart === 'undefined' || chart === null)
            && this instanceof jQuery) { // if no obj chart and the context is set
            this.find('.chart-container:visible').each(
                function () { // for only visible charts container in the curent context
                    $container = $(this); // context container
                    $container.find('div[id^="chart-"]').each(
                        function () { // for only chart
                            $chart = $(this).highcharts(); // cast from JQuery to highcharts obj
                            $chart.setSize($container.width(),
                                $chart.chartHeight,
                                doAnimation = true); // adjust chart size with animation transition
                        });
                });
        } else {
            chart.setSize($('.chart-container:visible').width(),
                chart.chartHeight, doAnimation = true); // if chart is set, adjust
        }
    } catch (err) {
        // do nothing
    }
}

$(function (H) {

    $(window).resize(function () {
        if (this.resizeTO)
            clearTimeout(this.resizeTO);
        this.resizeTO = setTimeout(function () {
            // resizeEnd call function with pass context body
            adjustGraph.call($('body'));
        }, 500);
    });

});

// Global options
Highcharts.setOptions({
    global: {
        timezoneOffset: 0 * 60
    },
    lang: {

        months: ["Januar", "Februar", "M\u00e4rz", "April", "Mai", "Juni",
            "Juli", "August", "September", "Oktober", "November",
            "Dezember"],
        shortMonths: ["Jan", "Feb", "M\u00e4r", "Apr", "Mai", "Jun",
            "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
        weekdays: ["Sonntag", "Montag", "Dienstag", "Mittwoch",
            "Donnerstag", "Freitag", "Samstag"],
        rangeSelectorZoom: '',
        rangeSelectorFrom: 'Von',
        rangeSelectorTo: 'Bis',
        thousandsSep: '.',
        decimalPoint: ',',
        downloadJPEG: 'als JPG herunterladen',
        downloadPDF: 'als PDF herunterladen',
        downloadPNG: 'als PNG herunterladen',
        downloadSVG: 'als SVG herunterladen',
        printChart: 'Chart drucken'

    },
    title: {
        style: {
            color: '#648caa'
        }
    },
    exporting: {
        buttons: {
            contextButton: {
                symbolStroke: '#648caa',
                symbolFill: '#fff',
                theme: {
                    'stroke-width': 1,
                    r: 0,
                    states: {
                        hover: {
                            fill: '#fff',
                            stroke: '#648caa'
                        },
                        select: {
                            fill: '#fff'
                        }
                    }
                }
            }
        },
        scale: 2,
        chartOptions: {
            events: {
                load: function () {
                    this.legend.render();
                }
            },
            rangeSelector: {
                buttons: []
            }
        }
    }
});

// Get asset allocations data for fund with ISIN DE0009799742
$.getJSON('https://api.hansainvest.com/api/v2/asset-allocations/with-derivatives/DE0009799742/', function (json_data) {

    const colors = ["#003f5c", "#ffa600", "#a05195", "#2f4b7c", "#ff7c43", "#665191", "#d45087", "#bada55", "#f95d6a", "#e67f83"];

    const chart3 = new Highcharts.Chart(
        {
            "chart": {
                "renderTo": "chart3",
                "type": "spline"
            },
            "title": {
                "text": json_data.fund.name + ' – ' + json_data.fund.isin
            },
            "credits": {
                "enabled": false
            },
            "legend": {
                "enabled": true,
                "navigation": {
                    "enabled": false
                },
                "symbolRadius": 0,
                "layout": "horizontal",
                "verticalAlign": "bottom",
                "floating": false,
                "align": "center",
                "x": 40,
                "y": 0,
                "padding": 0,
                "useHTML": false,
                "itemStyle": {
                    "fontWeight": "normal"
                }
            },
            "yAxis": [
                {
                    "gridLineDashStyle": "Dot",
                    "gridLineColor": "#666666",
                    "min": 0,
                    "labels": {
                        "format": "{value} %",
                        "y": 8,
                        "style": {
                            "fontSize": "13.5px"
                        }
                    },
                    "title": {
                        "text": null
                    }
                }
            ],
            "xAxis": [
                {
                    "type": "datetime",
                    "dateTimeLabelFormats": {
                        "month": "%b %Y"
                    },
                    "gridLineDashStyle": "Dot",
                    "gridLineWidth": 1,
                    "gridLineColor": "#666666",
                    "startOnTick": false,
                    "endOnTick": false,
                    "labels": {
                        "style": {
                            "fontSize": "13.5px"
                        }
                    }
                }
            ],
            "labels": {
                "style": {
                    "fontSize": "13px"
                }
            },
            "series": formatAllocations(json_data.allocations, colors)
        }
    );
});

Generate code for custom colors

<div id="chart-cg"></div>

<!-- move to closing body tag -->

<!-- use jQuery only in necessary -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js" crossorigin="anonymous"></script>
<!-- use Highcharts exporting plugin only in necessary -->
<script src="https://code.highcharts.com/stock/10.2/modules/exporting.js" crossorigin="anonymous"></script>

<!-- place the individual Highcharts code below as inline script or include -->
/**
 * Adjust size for hidden charts
 * @param chart highcharts
 */
function adjustGraph(chart) {
    try {
        if (typeof (chart === 'undefined' || chart === null)
            && this instanceof jQuery) { // if no obj chart and the context is set
            this.find('.chart-container:visible').each(
                function () { // for only visible charts container in the curent context
                    $container = $(this); // context container
                    $container.find('div[id^="chart-"]').each(
                        function () { // for only chart
                            $chart = $(this).highcharts(); // cast from JQuery to highcharts obj
                            $chart.setSize($container.width(),
                                $chart.chartHeight,
                                doAnimation = true); // adjust chart size with animation transition
                        });
                });
        } else {
            chart.setSize($('.chart-container:visible').width(),
                chart.chartHeight, doAnimation = true); // if chart is set, adjust
        }
    } catch (err) {
        // do nothing
    }
}

$(function (H) {

    $(window).resize(function () {
        if (this.resizeTO)
            clearTimeout(this.resizeTO);
        this.resizeTO = setTimeout(function () {
            // resizeEnd call function with pass context body
            adjustGraph.call($('body'));
        }, 500);
    });

});

// Global options
Highcharts.setOptions({
    global: {
        timezoneOffset: 0 * 60
    },
    lang: {

        months: ["Januar", "Februar", "M\u00e4rz", "April", "Mai", "Juni",
            "Juli", "August", "September", "Oktober", "November",
            "Dezember"],
        shortMonths: ["Jan", "Feb", "M\u00e4r", "Apr", "Mai", "Jun",
            "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
        weekdays: ["Sonntag", "Montag", "Dienstag", "Mittwoch",
            "Donnerstag", "Freitag", "Samstag"],
        rangeSelectorZoom: '',
        rangeSelectorFrom: 'Von',
        rangeSelectorTo: 'Bis',
        thousandsSep: '.',
        decimalPoint: ',',
        downloadJPEG: 'als JPG herunterladen',
        downloadPDF: 'als PDF herunterladen',
        downloadPNG: 'als PNG herunterladen',
        downloadSVG: 'als SVG herunterladen',
        printChart: 'Chart drucken'

    },
    title: {
        style: {
            color: ''
        }
    },
    exporting: {
        buttons: {
            contextButton: {
                symbolStroke: '',
                symbolFill: '#fff',
                theme: {
                    'stroke-width': 1,
                    r: 0,
                    states: {
                        hover: {
                            fill: '#fff',
                            stroke: ''
                        },
                        select: {
                            fill: '#fff'
                        }
                    }
                }
            }
        },
        scale: 2,
        chartOptions: {
            events: {
                load: function () {
                    this.legend.render();
                }
            },
            rangeSelector: {
                buttons: []
            }
        }
    }
});

(function (H) {

    // Override the legend symbol creator function
    Highcharts.wrap(Highcharts.Series.prototype, 'drawLegendSymbol', function (proceed, legend) {
        proceed.call(this, legend);

        this.legendLine.attr({
            d: ['M', -0.42447477, 15.295743, 8.4290971, 7.2893553, 13.2928, 12.618887, 16.748548, 8.0565589]
        });
    });

}(Highcharts));

/**
 * Adjust size for hidden charts
 * @param chart highcharts
 */
function adjustGraph(chart) {
    try {
        if (typeof (chart === 'undefined' || chart === null)
            && this instanceof jQuery) { // if no obj chart and the context is set
            this.find('.chart-container:visible').each(
                function () { // for only visible charts container in the curent context
                    $container = $(this); // context container
                    $container.find('div[id^="chart-"]').each(
                        function () { // for only chart
                            $chart = $(this).highcharts(); // cast from JQuery to highcharts obj
                            $chart.setSize($container.width(),
                                $chart.chartHeight,
                                doAnimation = true); // adjust chart size with animation transition
                        });
                });
        } else {
            chart.setSize($('.chart-container:visible').width(),
                chart.chartHeight, doAnimation = true); // if chart is set, adjust
        }
    } catch (err) {
        // do nothing
    }
}

$(function (H) {

    $(window).resize(function () {
        if (this.resizeTO)
            clearTimeout(this.resizeTO);
        this.resizeTO = setTimeout(function () {
            // resizeEnd call function with pass context body
            adjustGraph.call($('body'));
        }, 500);
    });

});

// Global options
Highcharts.setOptions({
    global: {
        timezoneOffset: 0 * 60
    },
    lang: {

        months: ["Januar", "Februar", "M\u00e4rz", "April", "Mai", "Juni",
            "Juli", "August", "September", "Oktober", "November",
            "Dezember"],
        shortMonths: ["Jan", "Feb", "M\u00e4r", "Apr", "Mai", "Jun",
            "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
        weekdays: ["Sonntag", "Montag", "Dienstag", "Mittwoch",
            "Donnerstag", "Freitag", "Samstag"],
        rangeSelectorZoom: '',
        rangeSelectorFrom: 'Von',
        rangeSelectorTo: 'Bis',
        thousandsSep: '.',
        decimalPoint: ',',
        downloadJPEG: 'als JPG herunterladen',
        downloadPDF: 'als PDF herunterladen',
        downloadPNG: 'als PNG herunterladen',
        downloadSVG: 'als SVG herunterladen',
        printChart: 'Chart drucken'

    },
    title: {
        style: {
            color: ''
        }
    },
    exporting: {
        buttons: {
            contextButton: {
                symbolStroke: '#648caa',
                symbolFill: '#fff',
                theme: {
                    'stroke-width': 1,
                    r: 0,
                    states: {
                        hover: {
                            fill: '#fff',
                            stroke: '#648caa'
                        },
                        select: {
                            fill: '#fff'
                        }
                    }
                }
            }
        },
        scale: 2,
        chartOptions: {
            events: {
                load: function () {
                    this.legend.render();
                }
            }
        }
    }
});

// Get performance data for fund with ISIN DE0008479015
$.getJSON('https://api.hansainvest.com/api/v1/performance-launch/DE0008479015/', function (json_data) {

    var chart = new Highcharts.stockChart(
        {
            "title": {
                "text": json_data.fund.name + ' – ' + json_data.fund.isin
            },
            "chart": {
                "renderTo": "chart-cg",
                "backgroundColor": ""
            },
            "legend": {
                "enabled": true,
                "layout": "horizontal",
                "verticalAlign": "bottom",
                "useHTML": false,
                "labelFormatter": function () {
                    var series = this;
                    var currentChart = series.chart;
                    var dates = series.processedXData !== undefined ? series.processedXData : series.xData;
                    var values = series.processedYData !== undefined ? series.processedYData : series.yData;
                    var minDate = currentChart.rangeSelector.minInput !== undefined ? currentChart.rangeSelector.minInput.HCTime : dates[0];
                    var maxDate = currentChart.rangeSelector.maxInput !== undefined && currentChart.rangeSelector.maxInput.HCTime <= dates[values.length - 1] ? currentChart.rangeSelector.maxInput.HCTime : dates[values.length - 1];
                    var firstValue = values[0];
                    var compareValue = series.compareValue;

                    if (isNaN(compareValue)) {
                        compareValue = firstValue;
                    }

                    var endValue = values[values.length - 1];
                    if (dates[values.length - 1] > maxDate) {
                        for (var j = values.length - 1; j > values.length - 10; j--) {
                            if (dates[j] <= maxDate) {
                                endValue = values[j];
                                break;
                            }
                        }
                    }

                    var change = Math.round(((endValue / compareValue * 100) - 100) * 100) / 100;

                    var legendText = series.name;
                    legendText = '<span style="color:' + series.color + '">' + legendText + '</span><br>' + (change > 0 ? '+' : '') + Highcharts.numberFormat(change, 2, ',') + ' %';
                    return legendText;

                }
            },
            "credits": {
                "enabled": false
            },
            "exporting": {
                "chartOptions": {
                    "title": {
                        "text": json_data.fund.name + " - Wertentwicklung"
                    }
                },
                "filename": json_data.fund.isin + "_-_Wertentwicklung"
            },
            "series": [{
                "name": json_data.fund.name + ' – ' + json_data.fund.isin,
                "data": json_data.performance,
                "turboThreshold": 0,
                "tooltip": {
                    "valueDecimals": 2
                },
                "color": ""
            }],
            "xAxis": {
                "startOnTick": true,
                "endOnTick": true,
                "ordinal": false,
                "gridLineDashStyle": "Dot",
                "gridLineWidth": 1,
                "gridLineColor": "",
                "events": {
                    "afterSetExtremes": function (e) {
                        var legend = this.chart.legend;
                        setTimeout(function () {
                            legend.render();
                        }, 100);

                        $('.highcharts-input-group').find('g:eq(1),g:eq(3)').trigger('change');

                        $('.rsbutton.is-active').removeClass('is-active');

                        setTimeout(function () {

                        }, 0);
                    }
                }
            },
            "yAxis": {
                "labels": {
                    "formatter": function () {
                        return (this.value > 0 ? ' + ' : '') + this.value + '%';
                    }
                },
                "gridLineDashStyle": "Dot",
                "gridLineColor": ""
            },
            "plotOptions": {
                "series": {
                    "compare": "percent",
                    "dataGrouping": {
                        "enabled": false
                    }
                }
            },
            "navigator": {
                "maskFill": ""
            },
            "tooltip": {
                "changeDecimals": 2,
                "valueDecimals": 2,
                "pointFormat": '<span style="color:{series.color}">{series.name}</span>: {point.change} %<br/>'
            }
        });
});