diff --git a/samples/scatter-logX.html b/samples/scatter-logX.html
index 976684f5c..d8d00c85c 100644
--- a/samples/scatter-logX.html
+++ b/samples/scatter-logX.html
@@ -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 '';
}
}
}],
diff --git a/src/core/core.helpers.js b/src/core/core.helpers.js
index 46ad752d8..ab58b0789 100644
--- a/src/core/core.helpers.js
+++ b/src/core/core.helpers.js
@@ -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;
diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js
index 7294cd522..a8d9706b9 100644
--- a/src/scales/scale.logarithmic.js
+++ b/src/scales/scale.logarithmic.js
@@ -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 {