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

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.

主站蜘蛛池模板: 江津市| 荔浦县| 松滋市| 峨山| 北京市| 张家港市| 江油市| 桐柏县| 阳信县| 德清县| 平陆县| 郧西县| 庆阳市| 洛宁县| 尖扎县| 临安市| 公安县| 南和县| 怀集县| 民勤县| 清河县| 台东市| 两当县| 镇雄县| 邢台市| 磴口县| 民和| 麟游县| 内黄县| 景德镇市| 牙克石市| 海原县| 隆安县| 常州市| 蒙城县| 太谷县| 鹤山市| 乐安县| 东城区| 辽源市| 武夷山市|