<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Changing colors in a list based on survey answer in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1149727#M5910</link>
    <description>&lt;P&gt;In Arcade, as soon as your expression encounters a &lt;STRONG&gt;return&lt;/STRONG&gt;, it stops. So the way this is written, your FOUNDATIONSPALLING field is not going to get evaluated at all.&lt;/P&gt;&lt;P&gt;A note on ifs: when your subsequent conditions are related, they should be chained together with &lt;STRONG&gt;else&lt;/STRONG&gt; statements. Otherwise your expression will check every condition, regardless of whether it already matched a preceding condition (unless, of course, that condition ended early with a &lt;STRONG&gt;return&lt;/STRONG&gt; statment).&lt;/P&gt;&lt;P&gt;You might write that as:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var c = $datapoint['FOUNDATIONCRACKING']

if(c == 'Yes'){
    return {textColor:red}
} else if(c == 'No'){
    return {textColor:blue}
} else {
    return {textcolor:black}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if I'm understanding this correctly, you want each line to have its own color? The &lt;STRONG&gt;textColor:&amp;lt;some color&amp;gt; &lt;/STRONG&gt;property is going to apply to the whole list item. If you want to get each line colored separately, you'll need to make use of the &lt;STRONG&gt;attributes &lt;/STRONG&gt;property and pipe the values into the HTML.&lt;/P&gt;&lt;P&gt;Also, since we need two separate values in a single &lt;STRONG&gt;return&lt;/STRONG&gt;, I am going to use &lt;STRONG&gt;Decode&lt;/STRONG&gt; to create a variable for each color. I'm also using a custom function so that I don't have to write everything twice. Here's what it looks like:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var c = $datapoint['FOUNDATIONCRACKING']
var s = $datapoint['FOUNDATIONSPALLING']

function colorCode(x){
    return Decode(
        x,
        'Yes', 'Red',
        'No', 'Blue',
        'Black'
    )
}

return {
   attributes: {
    c_col: colorCode(c),
    s_col: colorCode(s)
   }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then in my &lt;STRONG&gt;Line item template&lt;/STRONG&gt;, I open up the &lt;STRONG&gt;source &lt;/STRONG&gt;and edit the HTML as follows:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;p style="color:{expression/c_col}"&amp;gt;Foundation Cracking: {FOUNDATIONCRACKING}&amp;lt;/p&amp;gt;

&amp;lt;p style="color:{expression/s_col}"&amp;gt;Foundation Spalling: {FOUNDATIONSPALLING}&amp;lt;/p&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which yields the following list:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1646243285305.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35378iC4BF45BBF429AB74/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1646243285305.png" alt="jcarlson_0-1646243285305.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Mar 2022 17:48:00 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2022-03-02T17:48:00Z</dc:date>
    <item>
      <title>Changing colors in a list based on survey answer</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1149698#M5908</link>
      <description>&lt;P&gt;I have a survey that is completed to survey building conditions.&lt;/P&gt;&lt;P&gt;In my dashboard I would like to change color based on a negative or positive answer.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I asked this question before and thought it worked until I got more complicated. Please don't get irate, I am asking again so new people see it.&lt;/P&gt;&lt;P&gt;Below is a copy of my code.&amp;nbsp; The null is for those questions that are not answered. I thought that may be an issue so in the test survey questions I added an answer.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RobertBorchert_0-1646239737768.png" style="width: 367px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35371i0A2297B48291073C/image-dimensions/367x364?v=v2" width="367" height="364" role="button" title="RobertBorchert_0-1646239737768.png" alt="RobertBorchert_0-1646239737768.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RobertBorchert_1-1646239841304.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35372iB66DBBC70C9FBD70/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RobertBorchert_1-1646239841304.png" alt="RobertBorchert_1-1646239841304.png" /&gt;&lt;/span&gt;But here are the results.&amp;nbsp; The first 2 yes answers are red. The first No answer should be blue (in the final result they will be black).&amp;nbsp; Then it changes everything back to red for the next Yes answer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 16:54:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1149698#M5908</guid>
      <dc:creator>RobertBorchert</dc:creator>
      <dc:date>2022-03-02T16:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Changing colors in a list based on survey answer</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1149727#M5910</link>
      <description>&lt;P&gt;In Arcade, as soon as your expression encounters a &lt;STRONG&gt;return&lt;/STRONG&gt;, it stops. So the way this is written, your FOUNDATIONSPALLING field is not going to get evaluated at all.&lt;/P&gt;&lt;P&gt;A note on ifs: when your subsequent conditions are related, they should be chained together with &lt;STRONG&gt;else&lt;/STRONG&gt; statements. Otherwise your expression will check every condition, regardless of whether it already matched a preceding condition (unless, of course, that condition ended early with a &lt;STRONG&gt;return&lt;/STRONG&gt; statment).&lt;/P&gt;&lt;P&gt;You might write that as:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var c = $datapoint['FOUNDATIONCRACKING']

if(c == 'Yes'){
    return {textColor:red}
} else if(c == 'No'){
    return {textColor:blue}
} else {
    return {textcolor:black}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if I'm understanding this correctly, you want each line to have its own color? The &lt;STRONG&gt;textColor:&amp;lt;some color&amp;gt; &lt;/STRONG&gt;property is going to apply to the whole list item. If you want to get each line colored separately, you'll need to make use of the &lt;STRONG&gt;attributes &lt;/STRONG&gt;property and pipe the values into the HTML.&lt;/P&gt;&lt;P&gt;Also, since we need two separate values in a single &lt;STRONG&gt;return&lt;/STRONG&gt;, I am going to use &lt;STRONG&gt;Decode&lt;/STRONG&gt; to create a variable for each color. I'm also using a custom function so that I don't have to write everything twice. Here's what it looks like:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var c = $datapoint['FOUNDATIONCRACKING']
var s = $datapoint['FOUNDATIONSPALLING']

function colorCode(x){
    return Decode(
        x,
        'Yes', 'Red',
        'No', 'Blue',
        'Black'
    )
}

return {
   attributes: {
    c_col: colorCode(c),
    s_col: colorCode(s)
   }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then in my &lt;STRONG&gt;Line item template&lt;/STRONG&gt;, I open up the &lt;STRONG&gt;source &lt;/STRONG&gt;and edit the HTML as follows:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;p style="color:{expression/c_col}"&amp;gt;Foundation Cracking: {FOUNDATIONCRACKING}&amp;lt;/p&amp;gt;

&amp;lt;p style="color:{expression/s_col}"&amp;gt;Foundation Spalling: {FOUNDATIONSPALLING}&amp;lt;/p&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which yields the following list:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1646243285305.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35378iC4BF45BBF429AB74/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1646243285305.png" alt="jcarlson_0-1646243285305.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 17:48:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1149727#M5910</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-03-02T17:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Changing colors in a list based on survey answer</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1149732#M5911</link>
      <description>&lt;P&gt;thank you I think I understand and will try it.&amp;nbsp; I was able to get it working in Pro for a pop up but I was able to use html markup for the color change in the IF statement.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 18:03:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1149732#M5911</guid>
      <dc:creator>RobertBorchert</dc:creator>
      <dc:date>2022-03-02T18:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: Changing colors in a list based on survey answer</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1149741#M5913</link>
      <description>&lt;P&gt;That actually made a lot of sense once I wrote it out. That decode function is going to come in very handy.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now to repeat it 75 times.&amp;nbsp; Very long detailed survey.&amp;nbsp; Which is why wanted to pop out the colors for negative answers .&amp;nbsp;&lt;/P&gt;&lt;P&gt;We also need to use this to represent Arc Flash levels so the field techs will quickly see how dangerous a situation is.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 18:15:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1149741#M5913</guid>
      <dc:creator>RobertBorchert</dc:creator>
      <dc:date>2022-03-02T18:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: Changing colors in a list based on survey answer</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1151279#M5945</link>
      <description>&lt;P&gt;Just a quick follow up to&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;thanks for your help. This worked perfectly.&amp;nbsp; I had to modify it to use an iif statement for the variable as not all answers of a Yes were negative and vice versa.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;239 lines of code later I have it functioning perfectly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;We have a variety of other needs/desires to do this.&amp;nbsp; My next task will be applying this to Arc Flash data but using the BDG tag as well&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 15:13:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1151279#M5945</guid>
      <dc:creator>RobertBorchert</dc:creator>
      <dc:date>2022-03-07T15:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: Changing colors in a list based on survey answer</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1151284#M5946</link>
      <description>&lt;P&gt;Glad to hear it!&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 15:16:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1151284#M5946</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-03-07T15:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Changing colors in a list based on survey answer</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1555926#M10470</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;hope all is well so quick learning question why didn't you use &amp;lt;span&amp;gt; in your HTML? like should we use &amp;lt;span&amp;gt; while assigning Arcade attributes in HTML?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2024 17:53:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1555926#M10470</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-11-06T17:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: Changing colors in a list based on survey answer</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1556379#M10478</link>
      <description>&lt;P&gt;I believe Arcade automatically wraps text.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 17:07:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/changing-colors-in-a-list-based-on-survey-answer/m-p/1556379#M10478</guid>
      <dc:creator>RobertBorchert</dc:creator>
      <dc:date>2024-11-07T17:07:45Z</dc:date>
    </item>
  </channel>
</rss>

