[SalesForce] Change Default Pie Chart Color in Apex

I'm wondering is there a way to change the default pie-chart colors? the default random colors does not work in my scenario and we have our own set of colors like to implement in the pie-chart.

Here is my current code looks like:

<apex:pageBlockSectionItem >
   <apex:chart height="300" width="500" data="{!PieChartData}">
     <apex:pieSeries labelField="Colorpicker__c" dataField="data">
        <apex:chartLabel display="rotate" field="Colorpicker__c"/>
      </apex:pieSeries>
        <apex:legend position="right"/>
    </apex:chart>
</apex:pageBlockSectionItem> 

Best Answer

You can use colorset attribute documented here to provide custom colors

<apex:pageBlockSection title="Simple colorSet Demo">
<apex:chart data="{!pieData}" height="300" width="400" background="#F5F5F5">
    <apex:legend position="left"/>
    <apex:pieSeries labelField="name" dataField="data1"
        colorSet="#37241E,#94B3C8,#4D4E24,#BD8025,#816A4A,#F0E68C"/>
</apex:chart>

A colorSet is a string that is a comma-delimited list of HTML-style hexadecimal color definitions. For example, colorSet="#0A224E,#BF381A,#A0D8F1,#E9AF32,#E07628". Colors are used in sequence. When the end of the list is reached, the sequence starts over at the beginning

Related Topic