I am new to the Javascript API (JSAPI), and am trying not to get bogged down with what should be very basic and easy by now. But, nonetheless, here I am . . .
I would like to symbolize selected features in a polygon layer by unique value without hard-coding all of the values.
I also want to be sure that the colors are as distinguishable as possible depending on the quantity of unique values (in other words, not render 15 values in 15 shades of green, but render via an algorithm that does a better job than just random color generation).
I've been searching the web for a solution, but found none as of yet. I've also been banging my head with ESRI support, but the answer I finally got was that there is no such thing as an ESRI unique value renderer for JSAPI and that I will have to hard code all of the values manually and write a bunch of Javascript to sort out any duplicates. That just doesn't seem reasonable to me since rendering a selected set of polygons by unique value is fundamental GIS - basic thematic mapping that we've been doing for many years.
I just know there are many out there doing this successfully. Any guidance would be appreciated.
although the number of unique values, algorithm, fromColor, and toColor can be modified to generate different results, This is not a "random" palette generator, but produces instead a ramp.
As John pointed out, it's not a random color palette. If you want the effect of the sample you attached, you can create a field with random values and generate the renderer based on it.