dojo堆积柱形图中的工具提示问题

时间:2014-05-29 12:36:19

标签: javascript dojo dojox.charting

现在我正在使用dojo柱形图和堆积图表。当页面加载时它工作正常。当我将鼠标悬停在不同的堆叠字段上并且无法显示工具提示时。请向您询问如何在鼠标悬停时显示我的工具提示,其中包含受尊重的系列名称。这是我的js小提琴[link] [{{3} }]。

如此友好地请求您如何在鼠标悬停的各个字段上显示我的工具提示。

所以这是我的代码是

  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: 7000,
     //from:1000,
     //to:6000,
        vertical: true
    });

    chart1.addSeries("AC",[3000,5000,5500,6000,1300,8280] ,

     {

        plot: "stackedColumnsPlot",
        stroke: {
            color: "#FFFFFF" ,

        },
        fill: "#FFAEAE "
    });
    chart1.addSeries("TV", [2844,7301,6699,620,820,9683] , {
        plot: "stackedColumnsPlot",
        stroke: {
            color: "#FFFFFF"
        },
        fill: "#FFEC94"
    });
    chart1.addSeries("ACCE", [5000,1000,1000,1000,2500,2500] , {
        plot: "stackedColumnsPlot",
        stroke: {
            color: "#FFFFFF"
        },
        fill: "#B4D8E7"
    });
    chart1.addSeries("OTHER", [1500,150,1500,700,7000,0,8000,1300,1300] , {
        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");
   });
   });

在这里,我想为不同的不同系列提供不同的工具提示。那么它是如何实现的。

1 个答案:

答案 0 :(得分:0)

你只是缺少dojo css和body class属性。

<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/resources/dojo.css"> 
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dijit/themes/claro/claro.css" type="text/css">

<body class="claro">
<div data-dojo-type="dojox.charting.widget.Chart" id="chart1" style="width: 800px; height: 450px;">

</div>
<div id="chart1SelectableLegend"></div>
</body>
相关问题