I'm using http://www.highcharts.com/plugin-registry/single/17/Annotations and they suggested in order for me to save anything, to use
var items = chart.annotations.allItems,
annotationsArr = [],
iLen = items.length - 1;
for( ; iLen >= 0; iLen--) {
annotationsArr[iLen] = items[iLen].options;
}
$.post('my/path/to/save/annotations', annotationsArr);
Unfortunately this is where I get stuck. Doing
$(".result").text(annotationsArr);
Gives me [object Object],[object Object],[object Object],[object Object]
If I wanted to post the "proper" array to a PHP page, how would I do that? How would I grab the array on the PHP page? Doing a console.log(annotationsArr)
gives me the following
[UPDATE]
I can now submit the data which gets processed just fine using
$("#submit").click(function () {
var items = chart.annotations.allItems,
annotationsArr = [],
iLen = items.length - 1;
//alert('DEBUG INFO: '+JSON.stringify(items));
for (; iLen >= 0; iLen--) {
annotationsArr[iLen] = items[iLen].options;
}
$.ajax({
type: "POST",
url: "process.asp",
data: JSON.stringify(annotationsArr),
dataType: JSON
});
});
However the resulting array, as an example shows no colours e.g.
[{
"xAxis": 0,
"yAxis": 0,
"title": "Annotationtitle<br>withlinebreak",
"shape": {
"params": {
"r": 106,
"d": null,
"width": null,
"height": null
}
},
"x": 160,
"y": 122,
"allowDragX": true,
"allowDragY": true,
"anchorX": "left",
"anchorY": "top"
}]
I adjusted the return
part of function getParams(e)
to read
return {
r: shape.r ? getRadius(e) : null,
d: shape.d ? getPath(e) : null,
width: shape.width ? getWidth(e) : null,
height: shape.height ? getHeight(e) : null,
stroke: shape.stroke ? $("#stroke").val() : null,
strokeWidth: shape.strokeWidth ? $("#strokeWidth").val() : 2,
fill: shape.fill ? $("#fill").val() : null
};
This resorts in the following but unfortunately this doesn't seem to work either! Any suggestions?
[{
"xAxis": 0,
"yAxis": 0,
"title": "Annotationtitle<br>withlinebreak",
"shape": {
"params": {
"r": 76,
"d": null,
"width": null,
"height": null,
"stroke": "red",
"strokeWidth": null,
"fill": "#AB3445"
}
},
"x": 144,
"y": 136,
"allowDragX": true,
"allowDragY": true,
"anchorX": "left",
"anchorY": "top"
}]
UPDATE
The shape wasn't being registered so I changed drop(e)
to the following
function drop(e) {
Highcharts.removeEvent(document, 'mousemove', step);
// store annotation details
if (annotation) {
annotation.update({
shape: {
params: getParams(e),
"type": $("input[type='radio']:checked").val()
}
});
}
annotation = null;
}
It seems to be working but there is one thing left! If I save annotations, that is fine. When I come back to the screen, they are presented fine.
HOWEVER if I want to move them and then save them, they do not get saved in the new position
So for a rectangle, it had co-ords
"x": 116,
"y": 117,
I moved it the the opposite corner and it still came back with
"x": 116,
"y": 117,