简体   繁体   English

Dojo堆积柱形图问题在堆积顶部增加总堆积值

[英]Dojo Stacked column chart issues in add total stacked value on the top of stacked

I seem to be having a problem with my dojo stacked column chart. 我的dojo堆积柱形图似乎有问题。 Each stack values are placed "inside" the stacked chart. 每个堆栈值都放置在堆栈图的“内部”。 But I want these stacked totals should be at the top but outside the chart, just above the x axis labels. 但是我希望这些堆叠的总数应该在图表顶部但在x轴标签上方,但在图表外部。 So How do I achieve where the stack totals are displayed just top the stacked columns . 因此,我如何实现堆栈总数显示在堆栈列顶部的位置。 Here is my jsfiddle link . 这是我的jsfiddle 链接 Here i need to show my Total stacked value on the top of bar, as well as tooltip for each stacked value also. 在这里,我需要在栏的顶部显示我的总堆叠值,以及每个堆叠值的工具提示。

Here is my code is 这是我的代码是

    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");
   });
  });

In my experience, when I have a series with first value: 300, and another with first value: 244, the tooltip shows static series name Value:300 and value: 244. when hovering over these series. 以我的经验,当我有一个系列的第一个值:300,另一个具有第一个值:244时,当将鼠标悬停在这些系列上时,工具提示将显示静态系列名称Value:300和value:244。 I would like it to still show AC: 300 and TV: 244 with total stacked value show on the top of the stacked as Total: 544. But I am unble to get this type of value . 我希望它仍然显示AC:300和TV:244,总堆叠值显示为Total:544。但是我无法获得这种类型的值。 Appreciate any help. 感谢任何帮助。

I'm not 100% sure what you are trying to achieve in the end but you can definitely dislpay "AC: 300, TV: 244" by using the following text function: 我不确定100%到底要达到什么目的,但是您可以使用以下文字功能绝对确定“ AC:300,TV:244”:

        text: function(chartItem, plot) {
            return "AC: "+plot.series[0].data[chartItem.index] +
                ", TV: "+plot.series[1].data[chartItem.index];
        }

See also: http://jsfiddle.net/B45PW/3/ 另请参阅: http : //jsfiddle.net/B45PW/3/

EDIT: In your example you are also missing the CSS needed for the tooltip to show up correctly. 编辑:在您的示例中,您还缺少正确显示工具提示所需的CSS。 You need to add: 您需要添加:

<link rel="stylesheet" href="dojoinstall/dijit/themes/claro/claro.css">

and use the claro class on your body: 并在您的身体上使用claro类:

<body class="claro">

See: 看到:

http://jsfiddle.net/B45PW/4/ http://jsfiddle.net/B45PW/4/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM