mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Fixes to show all lines but not all labels. Added a variable in the template function to make debugging nicer.
This commit is contained in:
parent
e0cdfc6d2d
commit
c1f0a39982
@ -140,7 +140,11 @@
|
||||
position: 'bottom',
|
||||
labels: {
|
||||
userCallback: function(tick) {
|
||||
return tick.toString() + "Hz";
|
||||
var remain = tick / (Math.pow(10, Math.floor(Chart.helpers.log10(tick))));
|
||||
if (remain === 1 || remain === 2 || remain === 5) {
|
||||
return tick.toString() + "Hz";
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}],
|
||||
|
||||
@ -387,8 +387,7 @@
|
||||
} else {
|
||||
// Generate a reusable function that will serve as a template
|
||||
// generator (and which will be cached).
|
||||
fn = new Function("obj",
|
||||
"var p=[],print=function(){p.push.apply(p,arguments);};" +
|
||||
var functionCode = "var p=[],print=function(){p.push.apply(p,arguments);};" +
|
||||
|
||||
// Introduce the data as local variables using with(){}
|
||||
"with(obj){p.push('" +
|
||||
@ -402,8 +401,8 @@
|
||||
.split("\t").join("');")
|
||||
.split("%>").join("p.push('")
|
||||
.split("\r").join("\\'") +
|
||||
"');}return p.join('');"
|
||||
);
|
||||
"');}return p.join('');";
|
||||
fn = new Function("obj", functionCode);
|
||||
|
||||
// Cache the result
|
||||
templateStringCache[str] = fn;
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
show: true,
|
||||
mirror: false,
|
||||
padding: 10,
|
||||
template: "<%=value.toExponential()%>",
|
||||
template: "<%var remain = value / (Math.pow(10, Math.floor(Chart.helpers.log10(value))));if (remain === 1 || remain === 2 || remain === 5) {%><%=value.toExponential()%><%} else {%><%= null %><%}%>",
|
||||
fontSize: 12,
|
||||
fontStyle: "normal",
|
||||
fontColor: "#666",
|
||||
@ -76,9 +76,7 @@
|
||||
|
||||
for (var exponent = minExponent; exponent < maxExponent; ++exponent) {
|
||||
for (var i = 1; i < 10; ++i) {
|
||||
if (i === 1 || i === 2 || i === 3 || i === 5 || i === 7) {
|
||||
this.ticks.push(i * Math.pow(10, exponent));
|
||||
}
|
||||
this.ticks.push(i * Math.pow(10, exponent));
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,7 +121,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
this.labels.push(label ? label : ""); // empty string will not render so we're good
|
||||
this.labels.push(label); // empty string will not render so we're good
|
||||
}, this);
|
||||
},
|
||||
// Get the correct value. If the value type is object get the x or y based on whether we are horizontal or not
|
||||
@ -506,7 +504,9 @@
|
||||
|
||||
helpers.each(this.labels, function(label, index) {
|
||||
var xValue = this.getPixelForValue(this.ticks[index]);
|
||||
this.ctx.fillText(label, xValue, labelStartY);
|
||||
if (label) {
|
||||
this.ctx.fillText(label, xValue, labelStartY);
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user