If you have a small set of categories (less than 20) you can use something like color(fieldindex('Category',Category)).
If you have more categories then assigning colors in the script is a far better option. But there's a good chance some categories will have very similar colors and it will be hard to distinguish them. Using colors in that case is of limited value. It may just create a display that's colorful, but cluttered and hard to understand.