简体   繁体   English

谷歌饼图强制渲染馅饼外的“次要”标签

[英]Google pie chart force rendering of “minor” labels outside the pie

I've already researched a lot about google pie charts and hidden slice labels but didn't find anything with the labels outside the slices, so I'm hoping there is another solution than already suggested on SO . 我已经研究了很多关于谷歌饼图和隐藏的切片标签,但没有找到切片外的标签,所以我希望有另一个解决方案,而不是已经 建议 的SO

I generate a lot of different chart types and for better readability I customize pie (doghnut) charts so they show their labels outside the slices, connected with lines. 我生成了许多不同的图表类型,为了更好的可读性,我自定义了pie(doghnut)图表,以便在切片外部显示标签,并用线条连接。 Now as seen in other questions google charts will just hide the slice label if there is no room for it or if the value is too small, which is unacceptable for me and why I wanted to show them outside where there should be enough room. 现在正如其他问题中所见,谷歌图表只会隐藏切片标签,如果没有空间或价值太小,这对我来说是不可接受的,为什么我想把它们显示在应该有足够空间的地方之外。

Still google charts dislikes "minor" data values and just doesn't show their label(s), even with sliceVisibilityThreshold set to 0 , is there any other solution with the following setup in mind? 仍然谷歌图表不喜欢“次要”数据值,只是没有显示他们的标签,即使sliceVisibilityThreshold设置为0 ,是否还有其他解决方案,并考虑到以下设置? (You should see that the label "Far" for the violet slice is not rendered) (您应该看到紫色切片的标签“远”未呈现)

 var chartData = { "options": { "legend": { "position": "none" }, "pieHole": 0.5 }, "data": [ [ "Label 1", "Label 2" ], [ "Foo", 33059 ], [ "Bar", 57893 ], [ "Baz", 8135 ], [ "Boo", 12211 ], [ "Far", 3740 ], [ "Faz", 7219 ] ] }, ctx = document.getElementById('canvas'); var onLoadGoogle = function() { var data = new google.visualization.arrayToDataTable(chartData.data); var chart = new google.visualization['PieChart'](ctx); var options = chartData.options; options.legend.position = 'labeled'; options.pieSliceText = 'none'; options.sliceVisibilityThreshold = 0; chart.draw(data, chartData.options); } window.google.load("visualization", "1.1", { packages: ["corechart"], callback: onLoadGoogle, nocss: true }); 
 #canvas { width: 600px; height: 300px; } 
 <div id="canvas"></div> <script src="https://www.google.com/jsapi"></script> 

As noted in the documentation for PieChart , the pieStartAngle option can help to make space for some labels, though there is nothing that can be done if there is just not enough space. 正如pieStartAngle 文档中所述, pieStartAngle选项可以帮助为某些标签腾出空间,但如果空间不足,则无法做任何事情。 This applies to both the default labels inside slices and the labeled legend option you are using. 这适用于切片内的默认标签和您正在使用的标签图例选项。

You could also experiment with the pieSliceTextStyle and legend.textStyle to set the fontSize option to a smaller font. 您还可以尝试使用pieSliceTextStylelegend.textStylefontSize选项设置为较小的字体。

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

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