Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all,
Is there an API to get the colors of a master item in a QS extension?
I've noticed that layout.qHyperCube.qDimensionInfo[0].coloring.colorMapRef contains an ID of a ColorMap in case of master items.
How can I get this ColorMap?
Thanks
Hi,
The master dimension colors are stored in a separate generic object called ColorMapModel_<colorMapRef>, to get those values you would need to get the object and then its layout:
app.getObject('ColorMapModel_abcdef').then(model => model.getLayout().then(layout => console.log(layout)));
Hi,
The master dimension colors are stored in a separate generic object called ColorMapModel_<colorMapRef>, to get those values you would need to get the object and then its layout:
app.getObject('ColorMapModel_abcdef').then(model => model.getLayout().then(layout => console.log(layout)));
Dear colleagues
This is a very interesting topic, as i¡m trying to get this info too from the colorMapRef object.
Your proposal just don't show anything.
And if I just get and print in the console this info
app.getObject('ColorMapModel_abcdef')
it always show an error message, Object Not Found.
What I'm missing here?
Thanks!
Hi Ife,
Maybe you have not inizialized correctly the "app" variable.
For example with var app = qlik.currApp()
Hope this will help.
Regards,
Marco
Hi marco
Thanks for the answer,
No it's not like that, the variable app is correctly initialized.
It seems Qlik does not expose in the extensions API any way to get this info from the colorMapRef.
Marco, have you tested it? have you been able to get info from the colorMapRef object?
Regards
The abcdef part of the object id in my example is just a placeholder, it needs to be replaced with the actual id of the dimension you want the colors for 😉
I've tried this, but it seems to only return the colors that I specifically change from the default ones, as seen in the attached screenshot.
Do you happen to know how to retrieve the colors for the other values?
Correct, only the changed colors are stored - the other colors are populated from the currently applied theme. There is currently no straight way to figure out exactly which colors other dimension values will have as that varies depending on other variables like the number of dimension values, persistence etc. The colors themselves are stored in the theme api.
Thanks... what I'm actually trying to do is to replicate the "persistent colors" feature of the native Qlik Sense charts... where you flag "persistent colors" and all charts throughout the app will have the same color for the same dimension, regardless of the type of chart or the filter. Is that possible at all? I checked out the theme API, but while that lists a series of colors, I don't see any method that I can use to obtain the color for a certain value...
It's possible, the first step is to get the colors from the theme properties. You can then use the remainder operator on qElemNumber and array length to get the correct color value from the palette, something like
const palette = theme.properties.palettes.data[0].scale;
const color = palette[cell.qElemNumber % palette.length];