jquery – HighCharts饼图 – 在每个切片中添加文本

前端之家收集整理的这篇文章主要介绍了jquery – HighCharts饼图 – 在每个切片中添加文本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用代表资产分配的HighCharts创建一个金融饼图.我的目标是创建一个表示每个切片中实际分配值的图表,但每张幻灯片内部将显示第二个数据标签,该标签显示各种投资工具的目标百分比.值得注意的是,当前的资产配置可能并不总是与目标分配值相匹配.

除了每张幻灯片中的Target标签外,我已经完成了所有工作.请参阅下图,了解我想要完成的任务:

这是我到目前为止:

  1. var asset_allocation_pie_chart = new Highcharts.Chart({
  2. chart: { renderTo: 'asset_allocation_bottom_left_div' },title: { text: 'Current Asset Allocation',style: { fontSize: '17px',color: entity_color,fontWeight: 'bold',fontFamily: 'Verdana'} },subtitle: { text: '(As of ' + effective_date_formatted + ')',style: { fontSize: '15px',fontFamily: 'Verdana',marginBottom: '10px' },y: 40 },tooltip: { pointFormat: '{series.name}: <b>{point.percentage}%</b>',percentageDecimals: 0 },plotOptions: {
  3. pie: { allowPointSelect: true,cursor: 'pointer',dataLabels: { enabled: true,color: '#000000',connectorWidth: 1,connectorColor: '#000000',formatter: function() { return '<b>' + this.point.name + '</b>:<br/> ' + Math.round(this.percentage) + ' %'; } } }
  4. },series: [{
  5. type: 'pie',name: 'Asset Allocation',data: [['Investment Grade Bonds',InvestmentGradeBondPercentage],['High Yield Bonds',HighYieldBondPercentage],['Hedged Equity',HedgedEquityPercentage],['Global Equity',GlobalEquityPercentage],['Cash',CashPercentage]]
  6. }],exporting: { enabled: false },credits: { enabled: false }
  7. });

解决方法

这是用于此的 jsfiddle和用于显示内部和外部数据标签代码.

为了达成这个

>你需要给出两个饼图系列.一个人会在前面看,另一个人在后面.
>如果你想模拟它然后改变大小:’80%’.
>距离:距离的使用是显示进出的数据标签,您可以根据自己想要的位置进行更改.
> allowPointSelect:默认值为false但如果使用此值,则单击前饼图切片时将显示后面的饼图.

码:

  1. var asset_allocation_pie_chart = new Highcharts.Chart({
  2. chart: {
  3. renderTo: 'asset_allocation_bottom_left_div'
  4. },title: {
  5. text: 'Current Asset Allocation',style: {
  6. fontSize: '17px',color: 'red',fontFamily: 'Verdana'
  7. }
  8. },subtitle: {
  9. text: '(As of ' + 'dfdf' + ')',style: {
  10. fontSize: '15px',marginBottom: '10px'
  11. },y: 40
  12. },tooltip: {
  13. pointFormat: '{series.name}: <b>{point.percentage}%</b>',percentageDecimals: 0
  14. },plotOptions: {
  15. pie: {
  16. size: '80%',data: [
  17. ['Investment Grade Bonds',100],200],300],400],500]
  18. ]
  19. }
  20. },dataLabels: {
  21. verticalAlign: 'top',enabled: true,distance: -30,formatter: function() {
  22. return Math.round(this.percentage) + ' %';
  23. }
  24. }
  25. },{
  26. type: 'pie',dataLabels: {
  27. enabled: true,distance: 30,formatter: function() {
  28. return '<b>' + this.point.name + '</b>:<br/> ' + Math.round(this.percentage) + ' %';
  29. }
  30. }
  31. }],exporting: {
  32. enabled: false
  33. },credits: {
  34. enabled: false
  35. }
  36. });

饼图将如下所示:

猜你在找的jQuery相关文章