Save chart to image - background color issue
Posted: Tue May 03, 2016 11:28 am
I used the below line to save generated chart to image. I was able to generate a chart success, but applied background color and format is not displayed with series in the image. Please refer the attached screenshot.
Below is the code that we used to apply the background color and format the report.
Does it require to write additional code to bring the background color and format of the chart to an image?
Code: Select all
Chart1.toImage('pngimage', 'image/png');
Code: Select all
var myFormatTargetRangeLow = new Tee.Format(Chart1);
myFormatTargetRangeLow.stroke.fill = "#95CE39";
myFormatTargetRangeLow.stroke.size = 2;
//myFormatTargetRangeLow.stroke.dash = [3, 3];
myFormatTargetRangeLow.gradient.visible = true;
myFormatTargetRangeLow.gradient.colors = ["#95CE39"];
myFormatTargetRangeLow.transparency = 0.4;
Chart1.series.items[0].beforeDraw = function () {
//Set background color for Below Alarm threshold. Red
var xBelowAlarm1 = Chart1.axes.bottom.startPos,
yBelowAlarm1 = Chart1.axes.left.calc(response.data.MaxBelowAlarm),
xBelowAlarm2 = Chart1.axes.bottom.endPos,
yBelowAlarm2 = Chart1.axes.left.calc(response.data.MaxBelowAlarm);
// X,Y, Width, Height
myFormatBelowAlarm.rectangle(xBelowAlarm1, yBelowAlarm1, xBelowAlarm2 - xBelowAlarm1, yBelowAlarm2 - yBelowAlarm1);
//Set background color for Above Alarm threshold. Red
var xAboveAlarm1 = Chart1.axes.bottom.startPos,
yAboveAlarm1 = Chart1.axes.left.calc(response.data.MinAboveAlarm),
xAboveAlarm2 = Chart1.axes.bottom.endPos,
yAboveAlarm2 = Chart1.axes.left.calc(response.data.MinAboveAlarm);
// X,Y, Width, Height
myFormatAboveAlarm.rectangle(xAboveAlarm1, yAboveAlarm1, xAboveAlarm2 - xAboveAlarm1, yAboveAlarm2 - yAboveAlarm1);
//Set background color for Low Target range. Green
var xTargetRangeLow1 = Chart1.axes.bottom.startPos,
yTargetRangeLow1 = Chart1.axes.left.calc(response.data.MinLowTargetRange),
xTargetRangeLow2 = Chart1.axes.bottom.endPos,
yTargetRangeLow2 = Chart1.axes.left.calc(response.data.MaxLowTargetRange);
// X,Y, Width, Height
myFormatTargetRangeLow.rectangle(xTargetRangeLow1, yTargetRangeLow1, xTargetRangeLow2 - xTargetRangeLow1, yTargetRangeLow2 - yTargetRangeLow1);
}