<button id="removeDataset">Remove Dataset</button>
<button id="addData">Add Data</button>
<button id="removeData">Remove Data</button>
+ <div>
+ <h3>Legend</h3>
+ <div id="legendContainer">
+
+ </div>
+ </div>
<script>
var randomScalingFactor = function() {
return (Math.random() > 0.5 ? 1.0 : -1.0) * Math.round(Math.random() * 100);
}]
};
+
+ function updateLegend() {
+ $legendContainer = $('#legendContainer');
+ $legendContainer.empty();
+ $legendContainer.append(window.myBar.generateLegend());
+ }
+
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
window.myBar = new Chart(ctx, {
responsive: true,
}
});
+
+ updateLegend();
};
$('#randomizeData').click(function() {
});
window.myBar.update();
+ updateLegend();
});
$('#addDataset').click(function() {
}
window.myBar.addDataset(newDataset, 1);
+ updateLegend();
});
$('#addData').click(function() {
for (var index = 0; index < barChartData.datasets.length; ++index) {
window.myBar.addData(randomScalingFactor(), index);
}
+
+ updateLegend();
}
});
$('#removeDataset').click(function() {
window.myBar.removeDataset(0);
+ updateLegend();
});
$('#removeData').click(function() {
barChartData.datasets.forEach(function(dataset, datasetIndex) {
window.myBar.removeData(datasetIndex, -1);
});
+ updateLegend();
});
</script>
</body>
<button id="removeDataset">Remove Dataset</button>
<button id="addData">Add Data</button>
<button id="removeData">Remove Data</button>
+ <div>
+ <h3>Legend</h3>
+ <div id="legendContainer">
+
+ </div>
+ </div>
<script>
var randomScalingFactor = function() {
return Math.round(Math.random() * 100 * (Math.random() > 0.5 ? -1 : 1));
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx, config);
+
+ updateLegend();
};
+ function updateLegend() {
+ $legendContainer = $('#legendContainer');
+ $legendContainer.empty();
+ $legendContainer.append(window.myLine.generateLegend());
+ }
+
$('#randomizeData').click(function() {
$.each(config.data.datasets, function(i, dataset) {
dataset.data = dataset.data.map(function() {
});
window.myLine.update();
+ updateLegend();
});
$('#addDataset').click(function() {
}
window.myLine.addDataset(newDataset);
+ updateLegend();
});
$('#addData').click(function() {
for (var index = 0; index < config.data.datasets.length; ++index) {
window.myLine.addData(randomScalingFactor(), index);
}
+
+ updateLegend();
}
});
$('#removeDataset').click(function() {
window.myLine.removeDataset(0);
+ updateLegend();
});
$('#removeData').click(function() {
config.data.datasets.forEach(function(dataset, datasetIndex) {
window.myLine.removeData(datasetIndex, -1);
});
+
+ updateLegend();
});
</script>
</body>
<button id="removeDataset">Remove Dataset</button>
<button id="addData">Add Data</button>
<button id="removeData">Remove Data</button>
+ ]<div>
+ <h3>Legend</h3>
+ <div id="legendContainer">
+
+ </div>
+ </div>
<script>
var randomScalingFactor = function() {
return Math.round(Math.random() * 100);
}
};
+ function updateLegend() {
+ $legendContainer = $('#legendContainer');
+ $legendContainer.empty();
+ $legendContainer.append(window.myRadar.generateLegend());
+ }
+
window.onload = function() {
window.myRadar = new Chart(document.getElementById("canvas"), config);
+ updateLegend();
};
$('#randomizeData').click(function() {
});
window.myRadar.update();
+ updateLegend();
});
$('#addDataset').click(function() {
}
window.myRadar.addDataset(newDataset);
+ updateLegend();
});
$('#addData').click(function() {
for (var index = 0; index < config.data.datasets.length; ++index) {
window.myRadar.addData(randomScalingFactor(), index);
}
+
+ updateLegend();
}
});
$('#removeDataset').click(function() {
window.myRadar.removeDataset(0);
+ updateLegend();
});
$('#removeData').click(function() {
config.data.datasets.forEach(function(dataset, datasetIndex) {
window.myRadar.removeData(datasetIndex, -1);
});
+
+ updateLegend();
});
</script>
</body>
}],
},
- //String - A legend template
- legendTemplate: "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].borderColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>",
-
tooltips: {
template: "(<%= value.x %>, <%= value.y %>)",
multiTemplate: "<%if (datasetLabel){%><%=datasetLabel%>: <%}%>(<%= value.x %>, <%= value.y %>)",
},
generateLegend: function generateLegend() {
- return template(this.options.legendTemplate, this);
+ return helpers.template(this.options.legendTemplate, this);
},
destroy: function destroy() {
defaultColor: 'rgba(0,0,0,0.1)',
// Element defaults defined in element extensions
- elements: {}
+ elements: {},
+ // Legend template string
+ legendTemplate: "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i = 0; i < data.datasets.length; i++){%><li><span style=\"background-color:<%=data.datasets[i].backgroundColor%>\"><%if(data.datasets[i].label){%><%=data.datasets[i].label%><%}%></span></li><%}%></ul>",
},
};