ASP.NET MVC:
@(Html.EJ().Chart("PieChartContainer1")
//...
.Load("chartLoad")
)
function chartLoad(sender) {
//Get the data source
var chartData = sender.model.series[0].dataSource;
for (var i = 0; i < chartData.length; i++) {
//Created div element dynamically
var divElement = document.createElement('div');
divElement.id = 'annotation' + i;
divElement.style.display = "none";
divElement.innerText = chartData[i].InstanceUsed
document.getElementsByTagName('body')[0].appendChild(divElement);
//Added annotation dynamically
sender.model.annotations[i] = {};
sender.model.annotations[i].visible = true;
sender.model.annotations[i].content = 'annotation' + i;
sender.model.annotations[i].coordinateUnit = "points";
sender.model.annotations[i].x = i;
sender.model.annotations[i].y = chartData[i].NumOccurance;
}
} |
Thank you Upon inspection of your solution I saw that you were assigning an ID value to the divs and realized that with multiple pie charts that I would need to name all of these id's differently and would also need to have multiple javascript functions in order to have proper values in each section of the various pie charts. So here is what I ended up doing. Anyway it works so thanks.
1st pie chart
function chartLoad(sender){
var chartData = sender.model.series[0].dataSource;
for (var i = 0; i < chartData.length; i++) {
var divElement = document.createElement('div');
divElement.id = 'annotation' + i;
divElement.style.display = "none";
divElement.innerText = chartData[i].NumOccurance
document.getElementsByTagName('body')[0].appendChild(divElement);
//Added annotation dynamically
sender.model.annotations[i] = {};
sender.model.annotations[i].visible = true;
sender.model.annotations[i].content = 'annotation' + i;
sender.model.annotations[i].coordinateUnit = "points";
sender.model.annotations[i].x = i;
sender.model.annotations[i].y = chartData[i].NumOccurance;
}
}
function chartLoad2(sender){
var chartData = sender.model.series[0].dataSource;
for (var i = 0; i < chartData.length; i++) {
var divElement = document.createElement('div');
divElement.id = 'annotation2' + i;
divElement.style.display = "none";
divElement.innerText = chartData[i].Instances
document.getElementsByTagName('body')[0].appendChild(divElement);
//Added annotation dynamically
sender.model.annotations[i] = {};
sender.model.annotations[i].visible = true;
sender.model.annotations[i].content = 'annotation2' + i;
sender.model.annotations[i].coordinateUnit = "points";
sender.model.annotations[i].x = i;
sender.model.annotations[i].y = chartData[i].NumOccurance;
}
}
function chartLoad3(sender){
var chartData = sender.model.series[0].dataSource;
for (var i = 0; i < chartData.length; i++) {
var divElement = document.createElement('div');
divElement.id = 'annotation3' + i;
divElement.style.display = "none";
divElement.innerText = chartData[i].Instances
document.getElementsByTagName('body')[0].appendChild(divElement);
//Added annotation dynamically
sender.model.annotations[i] = {};
sender.model.annotations[i].visible = true;
sender.model.annotations[i].content = 'annotation3' + i;
sender.model.annotations[i].coordinateUnit = "points";
sender.model.annotations[i].x = i;
sender.model.annotations[i].y = chartData[i].NumOccurance;
}
}
@(Html.EJ().Chart("PieChartContainer1")
//...
.Load("chartLoad")
)
@(Html.EJ().Chart("PieChartContainer2")
//...
.Load("chartLoad")
)
@(Html.EJ().Chart("PieChartContainer3")
//...
.Load("chartLoad")
)
function chartLoad(sender) {
var chartData = sender.model.series[0].dataSource;
for (var i = 0; i < chartData.length; i++) {
var divElement = document.createElement('div');
divElement.id = 'annotation' + i + this._id;
divElement.style.display = "none";
divElement.innerText = chartData[i].InstanceUsed
document.getElementsByTagName('body')[0].appendChild(divElement);
sender.model.annotations[i] = {};
sender.model.annotations[i].visible = true;
sender.model.annotations[i].content = 'annotation' + i + this._id;
sender.model.annotations[i].coordinateUnit = "points";
sender.model.annotations[i].x = i;
sender.model.annotations[i].y = chartData[i].NumOccurance;
}
}
|