AmPieChart值和百分比

时间:2018-01-25 05:54:23

标签: javascript css html5 pie-chart amcharts

有没有办法删除 AamPieCharts 中的值和百分比。我想仅显示鼠标悬停的描述。应该有办法做到这一点。我们可以隐藏" valueField"在AmPieCharts?我试图删除它但不起作用。试过很多方法但失败了。我附上了我的代码,其中包括html5,css,js。

HTML

<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/pie.js"></script>

<link rel="stylesheet" 
href="https://www.amcharts.com/lib/3/plugins/export/export.css" 
type="text/css" media="all" />
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv"></div>

CSS

#chartdiv {
width: 100%;
height: 500px;
font-size: 11px;
}

.amcharts-pie-slice {
transform: scale(1);
transform-origin: 50% 50%;
transition-duration: 0.3s;
transition: all .3s ease-out;
-webkit-transition: all .3s ease-out;
-moz-transition: all .3s ease-out;
-o-transition: all .3s ease-out;
cursor: pointer;
box-shadow: 0 0 30px 0 #000;
}

.amcharts-pie-slice:hover {
transform: scale(1.1);
filter: url(#shadow);
}

JS

var chart = AmCharts.makeChart("chartdiv", {
"type": "pie",
"theme": "light",
"addClassNames": true,
"innerRadius": "0%",
"defs": {
"filter": [{
  "id": "shadow",
  "width": "200%",
  "height": "200%",
  "feOffset": {
    "result": "offOut",
    "in": "SourceAlpha",
    "dx": 0,
    "dy": 0
  },
  "feGaussianBlur": {
    "result": "blurOut",
    "in": "offOut",
    "stdDeviation": 5
  },
  "feBlend": {
    "in": "SourceGraphic",
    "in2": "blurOut",
    "mode": "normal"
  }
}]
},
"labelRadius": -50,
"labelText": "[[country]]",
"dataProvider": [ {
"country": "Business",
"text":"Description Here",
"value": 50
}, {
"country": "Projects",
"text":"Description Here",
"value": 50
}, {
"country": "Services",
"text":"Description Here",
"value": 50
 }, {
"country": "Admin",
"text":"Description Here",
"value": 50
}],
"valueField": "value",
"titleField": "text",
});

chart.addListener("init", handleInit);

chart.addListener("rollOverSlice", function(e) {
handleRollOver(e);
});

function handleInit(){
chart.legend.addListener("rollOverItem", handleRollOver);
}

function handleRollOver(e){
var wedge = e.dataItem.wedge.node;
wedge.parentNode.appendChild(wedge);
}

1 个答案:

答案 0 :(得分:1)

如果要从鼠标悬停中删除百分比和值,则必须自定义balloonText属性。默认值为"[[title]]: [[percents]]% ([[value]])\n[[description]]",因此您只需将balloonText属性设置为"[[text]]""[[title]]"(因为它是您的titleField)以提取描述字符串。< / p>

var chart = AmCharts.makeChart("chartdiv", {
"type": "pie",
"theme": "light",
"addClassNames": true,
"innerRadius": "0%",
"defs": {
"filter": [{
  "id": "shadow",
  "width": "200%",
  "height": "200%",
  "feOffset": {
    "result": "offOut",
    "in": "SourceAlpha",
    "dx": 0,
    "dy": 0
  },
  "feGaussianBlur": {
    "result": "blurOut",
    "in": "offOut",
    "stdDeviation": 5
  },
  "feBlend": {
    "in": "SourceGraphic",
    "in2": "blurOut",
    "mode": "normal"
  }
}]
},
"labelRadius": -50,
"labelText": "[[country]]",
"balloonText": "[[text]]",
"dataProvider": [ {
"country": "Business",
"text":"Description Here",
"value": 50
}, {
"country": "Projects",
"text":"Description Here",
"value": 50
}, {
"country": "Services",
"text":"Description Here",
"value": 50
 }, {
"country": "Admin",
"text":"Description Here",
"value": 50
}],
"valueField": "value",
"titleField": "text",
"legend": {}
});

chart.addListener("init", handleInit);

chart.addListener("rollOverSlice", function(e) {
handleRollOver(e);
});

function handleInit(){
chart.legend.addListener("rollOverItem", handleRollOver);
}

function handleRollOver(e){
var wedge = e.dataItem.wedge.node;
wedge.parentNode.appendChild(wedge);
}
#chartdiv {
width: 100%;
height: 500px;
font-size: 11px;
}

.amcharts-pie-slice {
transform: scale(1);
transform-origin: 50% 50%;
transition-duration: 0.3s;
transition: all .3s ease-out;
-webkit-transition: all .3s ease-out;
-moz-transition: all .3s ease-out;
-o-transition: all .3s ease-out;
cursor: pointer;
box-shadow: 0 0 30px 0 #000;
}

.amcharts-pie-slice:hover {
transform: scale(1.1);
filter: url(#shadow);
}
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/pie.js"></script>

<link rel="stylesheet" 
href="https://www.amcharts.com/lib/3/plugins/export/export.css" 
type="text/css" media="all" />
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv"></div>