问题
i have a dojo columns chart. Data is pulled from a rest service. Y values come as doubles, and X values come as integers. The problem is that dojo displays both values as doubles and i need both values to be displayed as integers.
For example, if the X value is "1", dojo shows "1.0".
function loadHist(objectId) {
$.ajax({
url: "/aquur/rest/getData/" + objectId,
}).done(function(data) {
/*
sample data:
data[0] = [0, 0, 1, 0, 0, 1, 4, 3, 1, 0, 0, 0]
data[1] =
[Object { value=1, text="1.0"}, Object { value=2, text="2.0"}, Object { value=3, text="3.0"}, Object { value=4, text="4.0"}, Object { value=5, text="5.0"}, Object { value=6, text="6.0"}, Object { value=7, text="7.0"}, Object { value=8, text="8.0"}, Object { value=9, text="9.0"}, Object { value=10, text="10.0"}, Object { value=11, text="11.0"}, Object { value=12, text="12.0"}]
*/
require(["dojox/charting/Chart2D", "dojox/charting/themes/MiamiNice", 'dojox/charting/plot2d/Columns'], function(Chart2D, MiamiNice, Columns) {
dojo.empty("histogram");
var chart = new Chart2D("histogram");
var origCreateLabel = Columns.prototype.createLabel;
Columns.prototype.createLabel = function(group, value, bbox, theme) {
if (isNaN(value)) {
origCreateLabel.apply(this, arguments);
} else if (value > 0) {
origCreateLabel.apply(this, arguments);
}
};
chart.setTheme(MiamiNice);
chart.addPlot("default", {
type: "Columns",
markers: true,
labels: true,
labelStyle: "outside",
gap: 5
});
/*
chart.addAxis("x", {labels: [
{"value":0, "text":"6"},
{"value":1, "text":"4"},
{"value":2, "text":"5"},
{"value":3, "text":"8"},
{"value":4, "text":"6.5"},
{"value":5, "text":"7"},
{"value":6, "text":"9"},
{"value":7, "text":"10"}x
]});*/
chart.addAxis("x", {
labels: data[1],
title: "snakes",
titleOrientation: "away"
});
chart.addAxis("y", {
title: "apples",
vertical: true,
fixLower: "major",
fixUpper: "major",
min: 0,
max: 100
});
chart.addSeries("Data", data[0]);
chart.render();
})
});
}
<div id="histogram" style="width:800px;height:400px;">
Thank you
来源:https://stackoverflow.com/questions/36296023/dojo-chart2d-columns-plot-prevent-trailing-zeroes-after-values