return 'rgba(' + Math.round(Math.random() * 255) + ',' + Math.round(Math.random() * 255) + ',' + Math.round(Math.random() * 255) + ',' + (opacity || '.3') + ')';
};
- var lineChartData = {
- labels: ["January", "February", "March", "April", "May", "June", "July"],
- datasets: [{
- label: "My First dataset",
- data: [null, randomScalingFactor(), randomScalingFactor(), null, randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
- fill: false,
- }, {
- label: "My Second dataset",
- data: [null, randomScalingFactor(), randomScalingFactor(), null, randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
- }]
+ var config = {
+ data: {
+ labels: ["January", "February", "March", "April", "May", "June", "July"],
+ datasets: [{
+ label: "My First dataset",
+ data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
+ fill: false,
+ }, {
+ label: "My Second dataset",
+ data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
+ }]
+ },
+ options: {
+ responsive: true
+ }
};
- $.each(lineChartData.datasets, function(i, dataset) {
+ $.each(config.data.datasets, function(i, dataset) {
dataset.borderColor = randomColor(0.4);
dataset.backgroundColor = randomColor(0.5);
dataset.pointBorderColor = randomColor(0.7);
dataset.pointBorderWidth = 1;
});
- console.log(lineChartData);
+ console.log(config.data);
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
- window.myLine = new Chart(ctx).Line({
- data: lineChartData,
- options: {
- responsive: true,
- hover: {
- mode: 'label',
- },
- stacked: false,
- scales: {
- xAxes: [{
- gridLines: {
- offsetGridLines: false
- }
- }]
- }
- }
- });
+ window.myLine = new Chart(ctx).Line(config);
};
$('#randomizeData').click(function() {
- lineChartData.datasets[0].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()];
+ config.data.datasets[0].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()];
- lineChartData.datasets[1].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()];
+ config.data.datasets[1].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()];
window.myLine.update();
});
custom: null,
backgroundColor: "rgba(0,0,0,0.8)",
fontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
- fontSize: 14,
+ fontSize: 10,
fontStyle: "normal",
fontColor: "#fff",
titleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
- titleFontSize: 14,
+ titleFontSize: 12,
titleFontStyle: "bold",
titleFontColor: "#fff",
yPadding: 6,
caretSize: 8,
cornerRadius: 6,
xOffset: 10,
- template: "<%if (label){%><%=label%>: <%}%><%= value %>",
- multiTemplate: "<%if (datasetLabel){%><%=datasetLabel%>: <%}%><%= value %>",
+ template: [
+ '<% if(label){ %>',
+ ' <%=label %>:',
+ '<% } %>',
+ '<%=value %>',
+ ].join(''),
+ multiTemplate: [
+ '<%if (datasetLabel){ %>',
+ ' <%=datasetLabel %>:',
+ '<% } %>',
+ '<%=value %>'
+ ].join(''),
+ 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>',
+ ].join(''),
multiKeyBackground: '#fff',
},
borderColor: defaultColor,
// Hover
hitRadius: 6,
- hoverRadius: 5,
+ hoverRadius: 4,
hoverBorderWidth: 2,
},
}
extend(Chart.Element.prototype, {
initialize: function() {},
pivot: function() {
+ if (!this._view) {
+ this._view = clone(this._model);
+ }
this._start = clone(this._view);
return this;
},
//ctx.clearRect(vm.x + vm.xPadding, this.getLineHeight(index + 1) - vm.fontSize/2, vm.fontSize, vm.fontSize);
//Instead we'll make a white filled block to put the legendColour palette over.
- ctx.fillStyle = helpers.color(vm.legendBackgroundColor).alpha(vm.opacity).rgbString();
- ctx.fillRect(vm.x + vm.xPadding, this.getLineHeight(index + 1) - vm.fontSize / 2, vm.fontSize, vm.fontSize);
+ ctx.fillStyle = helpers.color(vm.legendColors[index].stroke).alpha(vm.opacity).rgbString();
+ ctx.fillRect(vm.x + vm.xPadding - 1, this.getLineHeight(index + 1) - vm.fontSize / 2 - 1, vm.fontSize + 2, vm.fontSize + 2);
ctx.fillStyle = helpers.color(vm.legendColors[index].fill).alpha(vm.opacity).rgbString();
ctx.fillRect(vm.x + vm.xPadding, this.getLineHeight(index + 1) - vm.fontSize / 2, vm.fontSize, vm.fontSize);
mode: "label"
},
- 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>",
scales: {
xAxes: [{
scaleType: "dataset", // scatter should not use a dataset axis
_model: {
x: 0, //xScale.getPixelForValue(null, index, true),
y: 0, //this.chartArea.bottom,
- //controlPointPreviousX: this.previousPoint(dataset.data, index).x,
- //controlPointPreviousY: this.previousPoint(dataset.data, index).y,
- //controlPointNextX: this.nextPoint(dataset.data, index).x,
- //controlPointNextY: this.nextPoint(dataset.data, index).y,
},
}));
+
}, this);
// The line chart onlty supports a single x axis because the x axis is always a dataset axis
});
}, this);
+
// Update control points for the bezier curve
this.eachElement(function(point, index, dataset, datasetIndex) {
var controlPoints = helpers.splineCurve(
for (var i = this.data.datasets.length - 1; i >= 0; i--) {
var dataset = this.data.datasets[i];
- var datasetIndex = i;
// Transition Point Locations
helpers.each(dataset.metaData, function(point, index) {