官术网_书友最值得收藏!

Staggering labels in a pie chart

I am not a big fan of using pie charts for many segments. The more segments that there are, the less easy it is to see the data. As the segments get smaller, even the labels get smudged into each other.

If you absolutely, positively must create this type of chart, you need to have a better strategy for the labels.

Getting ready

Load the following script:

LOAD * INLINE [
    Country, Sales
    USA, 100000
    Canada, 50000
    Mexico, 25000
    UK, 70000
    Germany, 20000
    Brazil, 15000
    France, 10000
    Japan, 9000
    China, 8000
    Australia, 7000
    South Korea, 5000
    New Zealand, 4000
    Italy, 2000
];

How to do it…

Follow these steps to create a pie chart with staggered labels:

  1. Create a new pie chart.
  2. Add Country as the dimension.
  3. On the Expressions tab, add the following expression:
    Dual(
      Country & '-' & 
      Num(sum(Sales), '#,##0') & 
      Repeat(chr(13)&chr(10), rank(Sum(Sales))-6), 
      sum(Sales)
    )
  4. Select the Values on Data Points option.
  5. On the Sort tab, select the Y-Value option. Confirm Descending as the direction.
  6. On the Presentation tab, deselect the Show Legend option.
  7. Click on Finish.
  8. Resize the chart so that all the values can be seen.

How it works…

The magic here is the Repeat function:

Repeat(chr(13)&chr(10), rank(Sum(Sales))-6)

The ASCII characters 13 and 10 give us a carriage return and line feed. Note that there is a Rank()-6 here. Basically, the repeat doesn't kick in until you get to the seventh ranked value in the dimension. There is no reason to start staggering for the earlier values.

There's more…

This is the only time that I have actually had to use the Repeat function in a chart. It does have uses in the frontend in Text objects. Mostly, it would be used in the script to generate data.

主站蜘蛛池模板: 长寿区| 平阴县| 和平县| 治县。| 仲巴县| 合川市| 柯坪县| 湘乡市| 文安县| 长乐市| 临颍县| 邢台县| 泰兴市| 平邑县| 义马市| 乌拉特前旗| 乐山市| 普陀区| 松原市| 屏东县| 永泰县| 遂溪县| 贡山| 大丰市| 贵州省| 临猗县| 盐源县| 射洪县| 华宁县| 盘锦市| 黔西| 乌鲁木齐市| 莲花县| 定州市| 上杭县| 安新县| 湟源县| 北宁市| 白城市| 绥滨县| 普兰店市|