Examples of performance chart (legal)
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>
Basic JS includes
The basic JS includes are JQuery and Highcharts.
<!-- 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>
<!-- place the individual Highcharts code below as inline script or include -->
Formatting
The function periodsFormatted
is mandatory to format the API data for use in Highcharts. For older browsers a polyfill for Object.entries
has to be included.
// Object.entries Polyfill
if (!Object.entries) {
Object.entries = function (obj) {
var ownProps = Object.keys(obj),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--)
resArray[i] = [ownProps[i], obj[ownProps[i]]];
return resArray;
};
}
// Formatting of periods
function periodsFormatted(periods) {
var periodsFormatted = [];
periods = Object.entries(periods);
for(var i = 0; i < periods.length; i++) {
periodsFormatted.push(periods[i][1].fromformatted + ' – ' + periods[i][1].toformatted);
}
return periodsFormatted;
}
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: []
}
}
}
});
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/v1/performance-legal/DE0008479098/', function (json_data) {
var chart = new Highcharts.Chart(
{
"title": {
"text": json_data.fund.name + ' – ' + json_data.fund.isin
},
"chart": {
"renderTo": "chartcontainer"
},
"legend": {
"enabled": true,
"layout": "horizontal",
"verticalAlign": "bottom",
"useHTML": false
},
"yAxis": {
"title": {
"enabled": false
},
"gridLineDashStyle": "Dot",
"gridLineColor": "#648caa",
"tickAmount": 8,
"startOnTick": false,
"endOnTick": false,
"minPadding": 0.2,
"maxPadding": 0.2
},
"xAxis": [
{
"type": "category",
"categories": periodsFormatted(json_data.performance.periods),
"gridLineDashStyle": "Dot",
"gridLineWidth": 1,
"gridLineColor": "#648caa"
}, {
"type": "datetime",
"visible": false,
"min": new Date(Object.entries(json_data.performance.periods)[0][1].from).getTime()
}],
"labels": {
"style": {
"fontSize": "13px"
}
},
"credits": {
"enabled": false
},
"plotOptions": {
"column": {
"dataLabels": {
"enabled": true,
"useHTML": true,
"formatter": function() { return Highcharts.numberFormat(this.y, 2, ',') + (Object.entries(json_data.performance.periods)[0][1].from !== Object.entries(json_data.performance.periods)[0][1].realfrom && this.point.index === 0 ? '*' : ''); },
"crop": false,
"overflow": "none",
"backgroundColor": "rgba(252, 255, 255, 0.7)",
"zIndex": 10
},
"softThreshold": false
},
"spline": {
"lineWidth": 1,
"marker": {
"enabled": false
},
"dataLabels": {
"format": "{point.y:.1f}"
}
}
},
"exporting": {
"chartOptions": {
"title": {
"text": json_data.fund.name + " - Wertentwicklung in %"
}
},
"filename": json_data.fund.isin + "_-_Wertentwicklung_in_%"
},
"tooltip": {
"changeDecimals": 2,
"valueDecimals": 1,
"pointFormat": "<span style=\"color:{series.color}\">{series.name}<\/span>: <b>{point.y} %<\/b><br\/>"
},
"series": [
{
"name": "brutto",
"data": Object.entries(json_data.performance.bargross),
"type": "column",
"color": "#BADA55"
},
{
"name": "netto",
"data": Object.entries(json_data.performance.barnet),
"type": "column",
"color": "#C55"
},
{
"name": "kumuliert (brutto)",
"data": json_data.performance.line,
"type": "spline",
"color": "#663399",
"xAxis": 1,
turboThreshold: 0
}]
});
});
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 -->
Custom legend symbol for line
Override the normal symbol for the line chart in legend with SVG path
(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));
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 -->
// Object.entries Polyfill
if (!Object.entries) {
Object.entries = function (obj) {
var ownProps = Object.keys(obj),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--)
resArray[i] = [ownProps[i], obj[ownProps[i]]];
return resArray;
};
}
// Formatting of periods
function periodsFormatted(periods) {
var periodsFormatted = [];
periods = Object.entries(periods);
for(var i = 0; i < periods.length; i++) {
periodsFormatted.push(periods[i][1].fromformatted + ' – ' + periods[i][1].toformatted);
}
return periodsFormatted;
}
(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: '#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 performance data for fund with ISIN DE0008479015
$.getJSON('https://api.hansainvest.com/api/v1/performance-legal/DE0008479015/', function (json_data) {
// Generate chart
var chart1 = new Highcharts.Chart(
{
"title": {
"text": json_data.fund.name + ' – ' + json_data.fund.isin
},
"chart": {
"renderTo": "chart1",
"backgroundColor": "#ffffff"
},
"legend": {
"enabled": true,
"layout": "horizontal",
"verticalAlign": "bottom",
"useHTML": false
},
"yAxis": {
"title": {
"enabled": false
},
"gridLineDashStyle": "Dot",
"gridLineColor": "#648caa",
"tickAmount": 8,
"startOnTick": false,
"endOnTick": false,
"minPadding": 0.2,
"maxPadding": 0.2
},
"xAxis": [
{
"type": "category",
"categories": periodsFormatted(json_data.performance.periods),
"gridLineDashStyle": "Dot",
"gridLineWidth": 1,
"gridLineColor": "#648caa"
}, {
"type": "datetime",
"visible": false,
"min": new Date(Object.entries(json_data.performance.periods)[0][1].from).getTime()
}],
"labels": {
"style": {
"fontSize": "13px"
}
},
"credits": {
"enabled": false
},
"plotOptions": {
"column": {
"dataLabels": {
"enabled": true,
"useHTML": true,
"formatter": function() { return Highcharts.numberFormat(this.y, 2, ',') + (Object.entries(json_data.performance.periods)[0][1].from !== Object.entries(json_data.performance.periods)[0][1].realfrom && this.point.index === 0 ? '*' : ''); },
"crop": false,
"overflow": "none",
"backgroundColor": "rgba(252, 255, 255, 0.7)",
"zIndex": 10
},
"softThreshold": false
},
"spline": {
"lineWidth": 1,
"marker": {
"enabled": false
},
"dataLabels": {
"format": "{point.y:.1f}"
}
}
},
"exporting": {
"chartOptions": {
"title": {
"text": json_data.fund.name + " - Wertentwicklung in %"
}
},
"filename": json_data.fund.isin + "_-_Wertentwicklung_in_%"
},
"tooltip": {
"changeDecimals": 2,
"valueDecimals": 1,
"pointFormat": "<span style=\"color:{series.color}\">{series.name}<\/span>: <b>{point.y} %<\/b><br\/>"
},
"series": [
{
"name": "brutto",
"data": Object.entries(json_data.performance.bargross),
"type": "column",
"color": "#466e8c"
},
{
"name": "netto",
"data": Object.entries(json_data.performance.barnet),
"type": "column",
"color": "#7b9db7"
},
{
"name": "kumuliert (brutto)",
"data": json_data.performance.line,
"type": "spline",
"color": "#6e0532",
"xAxis": 1,
turboThreshold: 0
}]
});
});
Different colors
<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 -->
// Object.entries Polyfill
if (!Object.entries) {
Object.entries = function (obj) {
var ownProps = Object.keys(obj),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--)
resArray[i] = [ownProps[i], obj[ownProps[i]]];
return resArray;
};
}
// Formatting of periods
function periodsFormatted(periods) {
var periodsFormatted = [];
periods = Object.entries(periods);
for(var i = 0; i < periods.length; i++) {
periodsFormatted.push(periods[i][1].fromformatted + ' – ' + periods[i][1].toformatted);
}
return periodsFormatted;
}
(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: '#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 performance data for fund with ISIN DE0008479098
$.getJSON('https://api.hansainvest.com/api/v1/performance-legal/DE0008479098/', function (json_data) {
var chart2 = new Highcharts.Chart(
{
"title": {
"text": json_data.fund.name + ' – ' + json_data.fund.isin,
style: {
color: 'black'
}
},
"chart": {
"renderTo": "chart2",
"backgroundColor": "#ffffff"
},
"legend": {
"enabled": true,
"layout": "horizontal",
"verticalAlign": "bottom",
"useHTML": false
},
"yAxis": {
"title": {
"enabled": false
},
"gridLineDashStyle": "Dot",
"gridLineColor": "gray",
"tickAmount": 8,
"startOnTick": false,
"endOnTick": false,
"minPadding": 0.2,
"maxPadding": 0.2
},
"xAxis": [
{
"type": "category",
"categories": periodsFormatted(json_data.performance.periods),
"gridLineDashStyle": "Dot",
"gridLineWidth": 1,
"gridLineColor": "gray"
}, {
"type": "datetime",
"visible": false,
"min": new Date(Object.entries(json_data.performance.periods)[0][1].from).getTime()
}],
"labels": {
"style": {
"fontSize": "13px"
}
},
"credits": {
"enabled": false
},
"plotOptions": {
"column": {
"dataLabels": {
"enabled": true,
"useHTML": true,
"formatter": function() { return Highcharts.numberFormat(this.y, 2, ',') + (Object.entries(json_data.performance.periods)[0][1].from !== Object.entries(json_data.performance.periods)[0][1].realfrom && this.point.index === 0 ? '*' : ''); },
"crop": false,
"overflow": "none",
"backgroundColor": "rgba(252, 255, 255, 0.7)",
"zIndex": 10
},
"softThreshold": false
},
"spline": {
"lineWidth": 1,
"marker": {
"enabled": false
},
"dataLabels": {
"format": "{point.y:.1f}"
}
}
},
"exporting": {
"chartOptions": {
"title": {
"text": json_data.fund.name + " - Wertentwicklung in %"
}
},
"filename": json_data.fund.isin + "_-_Wertentwicklung_in_%",
buttons: {
contextButton: {
symbolStroke: 'black'
},
}
},
"tooltip": {
"changeDecimals": 2,
"valueDecimals": 1,
"pointFormat": "<span style=\"color:{series.color}\">{series.name}<\/span>: <b>{point.y} %<\/b><br\/>"
},
"series": [
{
"name": "brutto",
"data": Object.entries(json_data.performance.bargross),
"type": "column",
"color": "red"
},
{
"name": "netto",
"data": Object.entries(json_data.performance.barnet),
"type": "column",
"color": "green"
},
{
"name": "kumuliert (brutto)",
"data": json_data.performance.line,
"type": "spline",
"color": "blue",
"xAxis": 1,
turboThreshold: 0
}]
});
});
Different width and colors
<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 -->
// Object.entries Polyfill
if (!Object.entries) {
Object.entries = function (obj) {
var ownProps = Object.keys(obj),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--)
resArray[i] = [ownProps[i], obj[ownProps[i]]];
return resArray;
};
}
// Formatting of periods
function periodsFormatted(periods) {
var periodsFormatted = [];
periods = Object.entries(periods);
for(var i = 0; i < periods.length; i++) {
periodsFormatted.push(periods[i][1].fromformatted + ' – ' + periods[i][1].toformatted);
}
return periodsFormatted;
}
(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: '#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 performance data for fund with ISIN DE0008479098
$.getJSON('https://api.hansainvest.com/api/v1/performance-legal/DE0008479098/', function (json_data) {
var chart3 = new Highcharts.Chart(
{
"title": {
"text": json_data.fund.name + ' – ' + json_data.fund.isin
},
"chart": {
"renderTo": "chart3"
},
"legend": {
"enabled": true,
"layout": "horizontal",
"verticalAlign": "bottom",
"useHTML": false
},
"yAxis": {
"title": {
"enabled": false
},
"gridLineDashStyle": "Dot",
"gridLineColor": "#648caa",
"tickAmount": 8,
"startOnTick": false,
"endOnTick": false,
"minPadding": 0.2,
"maxPadding": 0.2
},
"xAxis": [
{
"type": "category",
"categories": periodsFormatted(json_data.performance.periods),
"gridLineDashStyle": "Dot",
"gridLineWidth": 1,
"gridLineColor": "#648caa"
}, {
"type": "datetime",
"visible": false,
"min": new Date(Object.entries(json_data.performance.periods)[0][1].from).getTime()
}],
"labels": {
"style": {
"fontSize": "13px"
}
},
"credits": {
"enabled": false
},
"plotOptions": {
"column": {
"dataLabels": {
"enabled": true,
"useHTML": true,
"formatter": function() { return Highcharts.numberFormat(this.y, 2, ',') + (Object.entries(json_data.performance.periods)[0][1].from !== Object.entries(json_data.performance.periods)[0][1].realfrom && this.point.index === 0 ? '*' : ''); },
"crop": false,
"overflow": "none",
"backgroundColor": "rgba(252, 255, 255, 0.7)",
"zIndex": 10
},
"softThreshold": false
},
"spline": {
"lineWidth": 1,
"marker": {
"enabled": false
},
"dataLabels": {
"format": "{point.y:.1f}"
}
}
},
"exporting": {
"chartOptions": {
"title": {
"text": json_data.fund.name + " - Wertentwicklung in %"
}
},
"filename": json_data.fund.isin + "_-_Wertentwicklung_in_%"
},
"tooltip": {
"changeDecimals": 2,
"valueDecimals": 1,
"pointFormat": "<span style=\"color:{series.color}\">{series.name}<\/span>: <b>{point.y} %<\/b><br\/>"
},
"series": [
{
"name": "brutto",
"data": Object.entries(json_data.performance.bargross),
"type": "column",
"color": "#BADA55"
},
{
"name": "netto",
"data": Object.entries(json_data.performance.barnet),
"type": "column",
"color": "#C55"
},
{
"name": "kumuliert (brutto)",
"data": json_data.performance.line,
"type": "spline",
"color": "#663399",
"xAxis": 1,
turboThreshold: 0
}]
});
});
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>
<!-- 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 -->
// Object.entries Polyfill
if (!Object.entries) {
Object.entries = function (obj) {
var ownProps = Object.keys(obj),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--)
resArray[i] = [ownProps[i], obj[ownProps[i]]];
return resArray;
};
}
// Formatting of periods
function periodsFormatted(periods) {
var periodsFormatted = [];
periods = Object.entries(periods);
for(var i = 0; i < periods.length; i++) {
periodsFormatted.push(periods[i][1].fromformatted + ' – ' + periods[i][1].toformatted);
}
return periodsFormatted;
}
(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: '#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 performance data for fund with ISIN DE0008479015
$.getJSON('https://api.hansainvest.com/api/v1/performance-legal/DE0008479015/', function (json_data) {
// Generate chart
var chart = new Highcharts.Chart(
{
"title": {
"text": json_data.fund.name + ' – ' + json_data.fund.isin
},
"chart": {
"renderTo": "chart-cg",
"backgroundColor": "#ffffff"
},
"legend": {
"enabled": true,
"layout": "horizontal",
"verticalAlign": "bottom",
"useHTML": false
},
"yAxis": {
"title": {
"enabled": false
},
"gridLineDashStyle": "Dot",
"gridLineColor": "#648caa",
"tickAmount": 8,
"startOnTick": false,
"endOnTick": false,
"minPadding": 0.2,
"maxPadding": 0.2
},
"xAxis": [
{
"type": "category",
"categories": periodsFormatted(json_data.performance.periods),
"gridLineDashStyle": "Dot",
"gridLineWidth": 1,
"gridLineColor": "#648caa"
}, {
"type": "datetime",
"visible": false,
"min": new Date(Object.entries(json_data.performance.periods)[0][1].from).getTime()
}],
"labels": {
"style": {
"fontSize": "13px"
}
},
"credits": {
"enabled": false
},
"plotOptions": {
"column": {
"dataLabels": {
"enabled": true,
"useHTML": true,
"formatter": function() { return Highcharts.numberFormat(this.y, 2, ',') + (Object.entries(json_data.performance.periods)[0][1].from !== Object.entries(json_data.performance.periods)[0][1].realfrom && this.point.index === 0 ? '*' : ''); },
"crop": false,
"overflow": "none",
"backgroundColor": "rgba(252, 255, 255, 0.7)",
"zIndex": 10
},
"softThreshold": false
},
"spline": {
"lineWidth": 1,
"marker": {
"enabled": false
},
"dataLabels": {
"format": "{point.y:.1f}"
}
}
},
"exporting": {
"chartOptions": {
"title": {
"text": json_data.fund.name + " - Wertentwicklung in %"
}
},
"filename": json_data.fund.isin + "_-_Wertentwicklung_in_%"
},
"tooltip": {
"changeDecimals": 2,
"valueDecimals": 1,
"pointFormat": "<span style=\"color:{series.color}\">{series.name}<\/span>: <b>{point.y} %<\/b><br\/>"
},
"series": [
{
"name": "brutto",
"data": Object.entries(json_data.performance.bargross),
"type": "column",
"color": "#466e8c"
},
{
"name": "netto",
"data": Object.entries(json_data.performance.barnet),
"type": "column",
"color": "#7b9db7"
},
{
"name": "kumuliert (brutto)",
"data": json_data.performance.line,
"type": "spline",
"color": "#6e0532",
"xAxis": 1,
turboThreshold: 0
}]
});
});