we have two kinds of highcharts graphs one line chart and one bar chart, we were required to draw lines on the chart based on some calculations. we used renderer to draw SVG Paths on both charts. the problem was when exporting (SVG, PNG, and PDF) the line charts export properly - includes our rendered lines. however, the bar chart doesnt, we used very similar code for the lines.
following is the code we used for the bar chart. it is very similar to the code we use for the line chart the only difference is the orientation and that the line chart has multiple series'
is there a difference between export for line charts and bar charts? can you pls advise what we can do to troubleshoot this?
here is a link to a jsfiddle. enter link description here
i do understand that highcharts now has error bars, but there are other specific requirements where we cant use it. the sample ive added above just shows a basic line render for your test thanks edwin
//this is the code we used for the line chart:
function (chart) {
//this disables interaction with the legend entries if trend
$.each(chart.series, function(i, series){
series.group.element.onmouseover = null;
});
const strokeWidth=1;
//this adds confidence intervals
if(ChartData.Configuration.IncludeConfidenceLevels=='Yes' && ChartData.Configuration.MetricHasConfidenceLevels=="Yes" ){
ChartData.HighChartData.forEach((row, index)=>{
row.Descriptors.forEach((item, itemSeries)=>{
let plotYLCI, plotYUCI, point1;
if(item.SuppressionFlag=='No'){
plotYLCI = chart.yAxis[0].toPixels(item.ConfidenceLow);
plotYUCI = chart.yAxis[0].toPixels(item.ConfidenceHigh);
point1=chart.series[index].data[itemSeries];
chart.renderer.path(['M', point1.plotX+ chart.plotLeft, plotYLCI, 'L', point1.plotX+ chart.plotLeft, plotYUCI])
.attr({'stroke-width': strokeWidth, stroke: row.color })//"black"})
.add()
chart.renderer.path(['M', point1.plotX+ chart.plotLeft-10, plotYLCI, 'L', point1.plotX+ chart.plotLeft+10, plotYLCI])
.attr({'stroke-width': strokeWidth, stroke: row.color })//"black"})
.add()
chart.renderer.path(['M', point1.plotX+ chart.plotLeft-10, plotYUCI, 'L', point1.plotX+ chart.plotLeft+10, plotYUCI])
.attr({'stroke-width': strokeWidth, stroke: row.color })//"black"})
.add()
}
})
})//end trend confidence intervals
}//ends confidence level IF
}//closes function chart
//this is the code we used for the comparison chart
function (chart) {
//this adds confidence intervals
if(ChartData.Configuration.IncludeConfidenceLevels=='Yes' && ChartData.Configuration.MetricHasConfidenceLevels=="Yes" ){
let i = 0,
yAxis = chart.yAxis[0],
r = chart.renderer,
tickWidth = ((ChartData.Configuration.ChartOrientation=='Horizontal') ? chart.plotHeight : chart.plotWidth) / chart.series[0].data.length,
len = ChartData.HighChartData[0].data.length;
for (i = 0; i < len; i++) {
if(ChartData.HighChartData[0].IsSuppressed[i]=='No'){
let confidenceIntervalLine= (ChartData.Configuration.ChartOrientation=='Horizontal')
? {
x1:chart.plotLeft + yAxis.translate(ChartData.HighChartData[0].Descriptors[i].ConfidenceLow),
y1:chart.plotTop + (i+0.5)*tickWidth,
x2:chart.plotLeft + yAxis.translate(ChartData.HighChartData[0].Descriptors[i].ConfidenceHigh),
y2:chart.plotTop + (i+0.5)*tickWidth
}
: {
x1:chart.plotLeft + (i+0.5)*tickWidth,
y1:chart.plotTop + chart.plotHeight - yAxis.translate(ChartData.HighChartData[0].Descriptors[i].ConfidenceLow),
x2:chart.plotLeft + (i+0.5)*tickWidth,
y2:chart.plotTop + chart.plotHeight - yAxis.translate(ChartData.HighChartData[0].Descriptors[i].ConfidenceHigh)
}
let
x1=confidenceIntervalLine.x1, y1=confidenceIntervalLine.y1, x2=confidenceIntervalLine.x2, y2=confidenceIntervalLine.y2, w=0.125*tickWidth;
//horizontal bar:
chart.renderer.path(['M', x1-1, y1-w-1, 'L', x1+1, y1-w-1,
'L', x1+1, y1-1, 'L', x2-1, y2-1,
'L', x2-1, y2-w-1, 'L', x2+1, y2-w-1,
'L', x2+1, y2+w+1, 'L', x2-1, y2+w+1,
'L', x2-1, y2+1, 'L', x1+1, y1+1,
'L', x1+1, y1+w+1, 'L', x1-1, y1+w+1,
'L', x1-1, y1-w-1
])
.attr({
//'stroke-width': strokeWidth,
//stroke: strokeColor,
zIndex:4
})
.addClass('confidenceClass')
.add();
}
}//ends the for loop
//ends bar confidence interval
}//ends confidence level IF
}//closes function chart
To fix the issue, update your .attr()
method to include:
.attr({
zIndex: 4,
fill: 'black',
stroke: 'white',
"stroke-width": 0.75
})