我的道场堆积柱形图似乎有问题。每个堆栈值都放置在堆栈图表“内部”。但我希望这些堆积总计应该位于顶部但在图表之外,就在 x 轴标签上方。那么如何实现堆栈总计显示在堆栈列顶部的位置。这是我的 jsfiddle link 。在这里,我需要在栏顶部显示我的总堆叠值,以及每个堆叠值的工具提示。
这是我的代码
require(["dojox/charting/Chart",
"dojox/charting/plot2d/Lines",
"dojox/charting/axis2d/Default",
"dojox/charting/plot2d/StackedColumns",
"dojox/charting/action2d/Tooltip",
"dojo/ready",
"dojox/charting/widget/SelectableLegend"],
function(Chart, Lines, Default, StackedColumns, Tooltip, ready, SelectableLegend) {
ready(function() {
var chart1 = new Chart("chart1");
chart1.title = "stacked chart";
chart1.addPlot("stackedColumnsPlot", {
type: StackedColumns,
gap:6,
lines: true,
areas: true,
markers: true,
labels: true,
labelStyle:"inside",
//maxBarSize: 35,
tension: "2"
});
chart1.addAxis("x", {
dropLabels: false,
labelSizeChange: true,
rotation:-20,
majorTicks:true,
majorTickStep:1,
minorTicks:false,
font: "normal normal bold 12px Tahoma",
fontColor: "black",
labels: [{"value":1,"text":"A"},{"value":2,"text":"B"},{"value":3,"text":"C"},{"value":4,"text":"D"},{"value":5,"text":"E"},{"value":6,"text":"F"}]
});
chart1.addAxis("y", {title:"Cost",
fixLower: "major",
fixUpper: "major",
includeZero: true,
majorTickStep:500,
max: 1500,
//from:1000,
//to:6000,
vertical: true
});
chart1.addSeries("AC",[300,500,500,600,300,280] ,
{
plot: "stackedColumnsPlot",
stroke: {
color: "#FFFFFF" ,
},
fill: "#FFAEAE "
});
chart1.addSeries("TV", [244,301,699,620,820,837], {
plot: "stackedColumnsPlot",
stroke: {
color: "#FFFFFF"
},
fill: "#FFEC94"
});
chart1.addSeries("ACCE", [500,100,100,100,200,250] , {
plot: "stackedColumnsPlot",
stroke: {
color: "#FFFFFF"
},
fill: "#B4D8E7"
});
chart1.addSeries("OTHER", [100,150,100,700,700,0,800,300,300] , {
plot: "stackedColumnsPlot",
stroke: {
color: "#FFFFFF"
},
fill: "#56BAEC"
});
new Tooltip(chart1, "stackedColumnsPlot", {
text: function(chartItem) {
console.debug(chartItem);
//return "Rating: " + chartItem.run.data[chartItem.index] + "; Total Value: " + chartItem.y;
// return "Comparision Rating: " + chartItem.y;
return "Value: " + chartItem.run.data[chartItem.index] + "; Stacked Value: " + chartItem.y;
}
});
chart1.render();
new SelectableLegend({
chart: chart1,
horizontal: true,
align:top
}, "chart1SelectableLegend");
});
});
根据我的经验,当我有一个系列的第一个值:300,另一个系列的第一个值:244时,当将鼠标悬停在这些系列上时,工具提示会显示静态系列名称值:300和值:244。我希望它仍然显示 AC:300 和 TV:244,总堆叠值显示在堆叠顶部,总计:544。 但我无法获得这种类型的值(value)。 感谢任何帮助。
最佳答案
我不是 100% 确定您最终想要实现什么,但您绝对可以使用以下文本函数来显示“AC:300,TV:244”:
text: function(chartItem, plot) {
return "AC: "+plot.series[0].data[chartItem.index] +
", TV: "+plot.series[1].data[chartItem.index];
}
另请参阅:http://jsfiddle.net/B45PW/3/
编辑:在您的示例中,您还缺少正确显示工具提示所需的 CSS。您需要添加:
<link rel="stylesheet" href="dojoinstall/dijit/themes/claro/claro.css">
并在你的 body 上使用 claro 类:
<body class="claro">
参见:
关于javascript - Dojo 堆叠柱形图在堆叠顶部添加总堆叠值时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24019497/