-->

How to create a Simple tag cloud? Using C# and Sty

2019-08-23 03:33发布

问题:

I'm finding it impossible to create a tag cloud, I can't find any walkthrough’s or tutorials. (ones that work at least).

I'm just looking for a simple, basic example of a working tag cloud and I can spice it up after that.

The best link i found is:

http://www.geekzilla.co.uk/View960C74AE-D01B-428E-BCF3-E57B85D5A308.htm

But it's out dated and I can't download the source file, and there are many gaps in the code.

回答1:

This isn't a really hard problem. Essentially a tag cloud is just a way of linking the fontsize to the how common the tag is.

First thing is how often does the tag appear:

select Value, Count(*)
from Tag
group by Value
order by Count(*)

Then when you render this resultset to the page, have some sort of algorithm to take the count for each tag and represent it as a font size. A naive approach would be to set the fontsize directly to the count, but that's likely to lead to unreadable results. Instead, perhaps just have the top 10% as a large font, the next 10% as the next fontsize down, etc. You'll have to work out an exact algorithm that works for you and your data, though.

Also, tag clouds are really a bit rubbish from several points of view (readability, searching, accessibility). Make sure the tag cloud isn't the only way to get access to the tags. Perhaps in alpha order or by Count(*) on a dedicated page.



回答2:

Use the TermCloud from the Google Charts API. It's very easy to use and it renders beautifully.