Let me have a stab at it, with something similar I achieved where I didn't need a lookup as I generated the codes based on the fields which appeared in events.
My data had events where one "Name" field value only had one "Code" field value. i.e. Name1 always had Code1 ( Name RED always had Code #FF00FF) in all the events. :
Oct 31 2016 00:00:00; Name= RED; Code= #FF00FF; IP=10.120.10.22
Oct 31 2016 00:00:01; Name= GREEN; Code= #00FF00; IP=110.120.10.22
Oct 31 2016 00:00:02; Name= BLUE; Code= #0000FF; IP=210.120.10.22
Oct 31 2016 00:00:03; Name= YELLOW; Code= #FFFF00; IP=180.120.10.22
Based on above events this is what I followed:
1) Create a hidden drop down input element.
2) In this dropdown's dynamic query create a string value, I called it valuesP , that will save all colourNames and colourCodes. These Name and Codes will be picked up from data field values of "Name" and "Code".
3) Format this valuesP string to suit the charting.fieldColors option, eg. for me the codes in valuesP were coming in #pppppp format but charting.fieldColors required colour in 0xpppppp format. (Might not be applicable for you)
4) Field valuesP was table(d) in dropdown, and set for fieldForLabel and fieldForVlaue . This sets the dropdown token which will be used to display colours. I called my dropdown token as colourToken .
5) Use the colourToken token in the charting.fieldColors option of chart.
Here is the dropdown code which was used.
<input type="dropdown" token="colourToken" searchWhenChanged="true" depends="$hideToken$">
<label>Hidden DropDown</label>
<search>
<query>... | eval colourCode="\"".Name."\": ".Code
| stats values(colourCode) as valuesP
| mvcombine valuesP
| rex field=valuesP mode=sed "s/ \"/, \"/g
s/\#/0x/g"
| table valuesP
</query>
</search>
<fieldForLabel>valuesP</fieldForLabel>
<fieldForValue>valuesP</fieldForValue>
<selectFirstChoice>true</selectFirstChoice>
</input>
Things to note in dropdown code:
- A dummy token called $hideToken$ was used to keep dropdown hidden all the time as this token will never be set.
- Set the selectFirstChoice = true (just for safety, even though only one string is tabled in query, might not be required though)
- Dropdown token colourToken was used in the charting option of pie chart as:
<option name="charting.fieldColors">{$colourToken$}</option>
NOTE
- My base query that was used to create the pie chart created fields called "RED", "YELLOW" and so on (a static part which requires me to be aware of what colours will be coming in my data) as charting.fieldColors works on fields. Here was my query to plot pie chart:
...| stats count(eval(Name=="RED")) as RED, count(eval(Name=="BLUE")) as BLUE, count(eval(Name=="YELLOW")) as YELLOW, count(eval(Name=="GREEN")) as GREEN
Hope it helps 🙂
... View more