title: Set colors in asp.net pie chart by name
body: <p>I have an a chart control which measures customer satisfaction.</p>
  
  <p>The possible values are Happy, Neutral and Sad. (e.g. a possible set of values might be: Happy (23), Neutral (12), Sad (19) )</p>
  
  <p>I want Happy to always be Green, Neutral to always be Orange and Sad to always be Red (e.g. like a RAG status)</p>
  
  <p>I set the colors thus:</p>
  
  <blockquote>
    <p>fbChart.Palette = ChartColorPalette.None;<br>
               fbChart.PaletteCustomColors = new Color[] { Color.Green, Color.Orange, Color.Red };</p>
  </blockquote>
  
  <p>This works fine if all three possible options have values, but if there is only one or two with values the colors screws up. (e.g. If I have Happy (12) and Sad (9) but no Neutral, the colors come out as Green for Happy and Orange for Sad.)</p>
  
  <p>Is there a way I can tie down the colors to the name (e.g Happy / Neutral / Sad)?</p>
  
  <p>EDIT: </p>
  
  <p>The data is loaded into the chart from a datatable:</p>
  
  <pre><code>    var fb = from f in db.tl_feedbacks
               where f.timestamp &gt;= new DateTime(fromYear, fromMonth, fromDay, 0, 0, 0) &amp;&amp;                f.timestamp &lt;= new DateTime(toYear, toMonth, toDay, 23, 59, 59)  
                 group f by f.tl_feedback_score.score into grp
                 select new
                 {
                       Score = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(grp.Key),  
                       Count = grp.Select(x =&gt; x.tl_feedback_score.score).Count()  
                 };  
                fbChart.Series["Feedback"].XValueMember = "Score";  
                fbChart.Series["Feedback"].YValueMembers = "Count";
  
                fbChart.DataSource = fb;
                fbChart.DataBind();
  </code></pre>