//------------------------------------------------
// Prepare everything necessary to provide a chart
//------------------------------------------------
//----------------
//...chart related
//----------------
var initialize = true;
// globally to have access from outer scope
var globalChart;
// dynamic credits
var creditsText = '';
var creditsLink = '';
var chartOptions = {
chart: {
resetZoomButton: {
position: {
x:-32,
y:-40
}
},
zoomType: 'x',
events: {
load: function() {
this.credits.element.onclick = function() {
window.open(
creditsLink,
'_blank' // <- This is what makes it open in a new window.
);
}
}
}
},
title: {
//text: 'Grafische Darstellung der Parameter',
x: -20 //center
},
subtitle: {
text: 'Hier der Zeitraum',
x: -20
},
legend :{
// provide space between legend and credits text
y: -16
},
tooltip: {
useHTML: true,
crosshairs: true,
shared: false
}
}; // chartOptions
//--------------------------------------------
// .......................special theme
//--------------------------------------------
// Load the fonts
//Highcharts.createElement('link', {
// href: '//fonts.googleapis.com/css?family=Signika:400,700',
// rel: 'stylesheet',
// type: 'text/css'
//}, null, document.getElementsByTagName('head')[0]);
Highcharts.theme = {
colors:
//["#f45b5b", "#8085e9", "#8d4654", "#7798BF", "#aaeeee", "#ff0066", "#eeaaee", "#55BF3B", "#DF5353", "#7798BF", "#aaeeee"],
["#0000FF", "#FF0000", "#00FF00", "#404040", "#CCCC00", "#FF9900", "#8085E9", "#8D4654", "#FF0066", "#55BF3B", "#7798BF"],
chart: {
backgroundColor: null,
style: {
//fontFamily: "Signika, serif"
fontFamily: "Arial, serif"
}
},
title: {
style: {
color: 'black',
fontSize: '16px',
fontWeight: 'normal'
}
},
subtitle: {
style: {
fontSize: '14px',
color: 'black'
}
},
tooltip: {
borderWidth: 1,
style: {
fontSize: '11px'
}
},
legend: {
itemStyle: {
fontWeight: 'normal',
fontSize: '16px'
}
},
xAxis: {
labels: {
style: {
//color: '#6e6e70'
color: 'black',
fontSize: '14px'
}
}
},
yAxis: {
labels: {
style: {
//color: '#6e6e70'
color: 'black',
fontSize: '14px'
}
},
title: {
style: {
color: 'black',
fontSize: '16px'
}
}
},
plotOptions: {
series: {
shadow: true
},
candlestick: {
lineColor: '#404048'
},
map: {
shadow: false
}
},
// Highstock specific
navigator: {
xAxis: {
gridLineColor: '#D0D0D8'
}
},
rangeSelector: {
buttonTheme: {
fill: 'white',
stroke: '#C0C0C8',
'stroke-width': 1,
states: {
select: {
fill: '#D0D0D8'
}
}
}
},
scrollbar: {
trackBorderColor: '#C0C0C8'
},
// General
background2: '#E0E0E8'
};
// --------------------------------
//...main chart function
// --------------------------------
function prepareCharts(jsonData) {
$('#container').html('');
//...It is recommended to destroy the obsolete highcharts objects
//...Have a look at: http://api.highcharts.com/highcharts#Chart.destroy
if ($('#container').highcharts()) $('#container').highcharts().destroy();
if (Highcharts.charts.length > 0) Highcharts.charts.length = 0;
// set charts
var chartDiv = document.getElementById('container');
// global data
creditsLink = jsonData.CreditsLink;
creditsText = jsonData.CreditsText;
var titleText = jsonData.TitleText;
//...prepare chartoptions
chartOptions.chart.renderTo = chartDiv;
chartOptions.subtitle.text = jsonData.ChartInfo;
chartOptions.xAxis = convertString2Bool(jsonData.Xaxis);
chartOptions.yAxis = convertString2Bool(jsonData.Yaxis);
chartOptions.series = jsonData.Series;
//...set global chart options
if (initialize) {
Highcharts.setOptions(
{
lang: {
months: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
shortMonths: [ "Jan" , "Feb" , "Mrz" , "Apr" , "Mai" , "Jun" , "Jul" , "Aug" , "Sep" , "Okt" , "Nov" , "Dez"],
weekdays: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
printChart: 'Grafik drucken...',
contextButtonTitle: 'Optionen...',
downloadPNG: 'Speichern als PNG Grafik...',
downloadJPEG: 'Speichern als JPG Grafik...',
downloadPDF: 'Speichern als PDF Dokument...',
downloadSVG: 'Speichern als SVG Grafik...',
resetZoom: '<< Zurück zur Übersicht',
resetZoomTitle: 'Ansicht wieder herstellen',
thousandsSep: ""
},
credits: {
enabled: true,
text: 'Quelle: ' + creditsText,
position: {
align: 'right',
verticalAlign: 'bottom'
}
},
tooltip: {
formatter: function () {
var pointTxt = this.series.options.yCurrentDateHash[this.point.index][this.x] +
'' + this.series.name +
'Tag: ' + this.series.options.yDayDataHash[this.point.index][this.x] +
' kgKumuliert: ' + this.y +
' kgDatum min: ' + this.series.options.yMinDateHash[this.point.index][this.x] +
'Datum max: ' + this.series.options.yMaxDateHash[this.point.index][this.x] +
'
Anzahl Waagen:' + this.series.options.yAmountWaageHash[this.point.index][this.x];
return pointTxt;
}
}
}
);
initialize = false;
}
// Apply the theme
Highcharts.setOptions(Highcharts.theme);
//...create chart object
globalChart = new Highcharts.Chart(chartOptions);
// set title extra because we have more than one chart
globalChart.setTitle({ text: titleText });
// ...add dynamically event listener for period management when zooming in
Highcharts.addEvent(
globalChart.xAxis[0],
'setExtremes',
syncExtremes
);
// build own custom legend for different years
BuildCustomLegend();
}
// --------------------------------
//...main chart function
// --------------------------------
function emptyCharts() {
$('#container').empty();
//$('#container').hide();
$('#customLegend').empty();
$('#customLegend').hide();
}
// -----------------------------------------
// Manage custom legend for year selection
// -----------------------------------------
function BuildCustomLegend() {
var yearCacheArr = [];
$('#customLegend').show();
$('#customLegend').html('');
var legend = $('#customLegend');
var dashStyle = 'solid'; // default line style
var dashLineArr = ["Dash","DashDot","LongDash","ShortDash","LongDashDot"];
var dotLineArr = ["Dot","ShortDot","ShortDashDot","ShortDashDotDot","LongDashDotDot"];
var legendTmplReplaced = '';
var legendTmpl = '