简体   繁体   English

如何仅使用1系列数据创建饼图并以背景为圆

[英]How to create pie chart with only 1 series data and have background be a circle

Ok, using highcharts and I need to create a pie chart with only 1 data and the rest of the circle is a gray line that does not do anything. 好的,使用highcharts,我需要创建一个仅包含1个数据的饼图,其余的圆圈是一条无用的灰线。 Is there anyways to do this? 反正有这样做吗? Currently, with the following code I have I have to set a data point so that it contains a percentage, but not able to disable the gray section in this pic: 当前,使用以下代码,我必须设置一个数据点,使其包含百分比,但无法禁用此图片中的灰色部分: 我所拥有的照片

But I need the gray section to not be able to be selected, and would help if it looked more like the design in the sense that the gray part is thinner. 但是我需要不能选择灰色部分,如果从灰色部分更薄的角度来看它看起来更像设计,那将有所帮助。 Design here: 在这里设计: 我需要的照片

My current options for this pie chart is as follows: 该饼图的当前选项如下:

    {  
   "chart":{  
      "renderTo":"amenity-0",
      "plotBackgroundColor":null,
      "plotBorderWidth":0,
      "plotShadow":false,
      "height":220,
      "marginBottom":40,
      "spacingBottom":30
   },
   "title":{  
      "text":"Amenity 1",
      "align":"center",
      "verticalAlign":"bottom",
      "y":15
   },
   "credits":{  
      "enabled":false
   },
   "tooltip":{  
      "headerFormat":"",
      "pointFormat":"{point.name}: <b>{point.percentage:.1f}%</b>"
   },
   "plotOptions":{  
      "pie":{  
         "dataLabels":{  
            "enabled":true,
            "distance":-50,
            "style":{  
               "fontWeight":"bold",
               "color":"white"
            }
         },
         "startAngle":0,
         "endAngle":360,
         "center":[  
            "50%",
            "50%"
         ],
         "size":"100%"
      }
   },
   "series":[  
      {  
         "type":"pie",
         "name":"Amenity 1",
         "innerSize":"60%",
         "data":[  
            {  
               "name":"Amenity 1",
               "y":69,
               "color":"#C1AFBD",
               "dataLabels":{  
                  "enabled":false
               }
            },
            {  
               "name":"Gray Section",
               "y":31,
               "color":"#E9EDF0",
               "dataLabels":{  
                  "enabled":false
               }
            }
         ]
      }
   ]
}

I have tried using the pointFormatter function instead of pointFormat and returning false if the point.name === 'Gray Section', but this did not remove the tooltip. 我尝试使用pointFormatter函数代替pointFormat ,如果point.name ==='Gray Section',则返回false,但这并没有删除工具提示。 It just created a blank tooltip. 它只是创建了一个空白的工具提示。 In any case, I would like for the gray section to be thinner like in the design and not to be part of the data if possible. 无论如何,我希望灰色部分像设计中一样薄一些,如果可能的话不要成为数据的一部分。

Is this possible? 这可能吗? Any ideas on how to achieve this exactly? 关于如何准确实现这一目标的任何想法? Thanks guys/gals. 谢谢大家。

Regarding the tooltip, you could use some sort of condition for the general tooltip.formatter to disable the tooltip for a given point, like setting noTooltip for the given point. 关于工具提示,您可以对一般的tooltip.formatter使用某种条件来禁用给定点的工具提示,例如为给定点设置noTooltip For example ( JSFiddle ): 例如( JSFiddle ):

tooltip: {
    formatter: function() {
        if(!this.point.noTooltip) {
            return '<span style="color:' + this.point.color + '">●</span>' + 
                this.series.name + '<br/>' + 
                'Value: ' + this.point.y + '<br/>';
        }

        return false;
    },
    hideDelay: 0
},
series: [{
    data: [{
        y: 70
    }, {
        y: 30,
        noTooltip: true
    }]
}]

Regarding the thinner gray section you could use a variablepie instead and set different z values to make the actual value stand out more. 对于较薄的灰色部分,您可以改用variablepie饼并设置不同的z值,以使实际值更加突出。 For example ( JSFiddle ): 例如( JSFiddle ):

chart: {
    type: 'variablepie'
},
series: [{
    innerSize: '40%',
    zMin: 0,
    zMax: 100,
    data: [{
        y: 70,
        z: 10,
    }, {
        y: 30,
        z: 0.1,
        color: 'lightgray'
    }]
}]

It requires the following module imported: 它需要导入以下模块:

<script src="https://code.highcharts.com/modules/variable-pie.js"></script>

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

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