function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC_LearnerSFDC_Learner 

Multi Color Bar

HI

 

I am working with multi colored bar charts.

 

I have 5 fields, and get a list throuth wrapper and displayed in <apex:chart/> and working fine.

 

Questions is,

 

<apex:barSeries title="R1,R2,R3,R4,R5" orientation="horizontal" axis="bottom"  xField="data,data1,data2,data3,data4" yField="name" colorSet="blue,Magenta,Yellow,LightSeaGreen,cyan" stacked="true">
      <apex:chartTips height="20" width="120"/>
 </apex:barSeries> 
 
 
In above code, How can i add a  dynamic color for the values based on filter... 
 
For ex, 
IF(R1>0 && R1 <=10) : Color should be red
IF(R!>10 && R1<=20) : Color should be green  .. etc
 
like this based on a specific criteria i want to add a color value in colorSet.
 
In General we can bind the IF() in "Style" tags and then we can apply the conditions accordingly.
But here barseries is not having a "Style" tag to do this.
 
Any Idea!
 
 
Thank you
bob_buzzardbob_buzzard

You can use merge syntax in the colorSet atrribute.  For example, I have a chart where the bar color is set by the controller and I can access the controller property as follows:

 

colorSet="{!barColor}"

 So you can embed your IF etc exactly as you would in a style attribute for other components.

SFDC_LearnerSFDC_Learner

HI Bob,

Thanks for the reply.

 

It is working fine when we have a single record.

 

But How it can works for multi records. I want to apply this for all the records...

 

Page:

 
<apex:page controller="expensebarChartController" sidebar="false" showHeader="false">
    <apex:chart data="{!bardata}" width="500" height="400" colorset="#8B008B,#9900CC,#FFFF33" theme="Category1"> 
    <apex:axis type="Category" position="left" fields="name"/> 
    <apex:axis type="Numeric" position="bottom" fields="rev1,rev2,rev3,rev4,rev5"  title="Amount($)" /> 
    <apex:legend position="right"/> 
        <apex:barSeries title="R1,R2,R3,R4,R5" orientation="horizontal" axis="bottom"  xField="rev1,rev2,rev3,rev4,rev5" yField="name" colorSet="{!colortest},blue,green,yellow,cyan" stacked="true">
                          <apex:chartTips height="50" width="10"/>
         </apex:barSeries> 
    </apex:chart> 
</apex:page>
 
 
class:
 
public class expensebarChartController{
 
    public String colorTest{get;set;}
    public List<wrapper> getBarData(){
        colorTest = 'red';
         list<countrydata__c> l = [select id,name,revenue1__c,revenue2__c,revenue3__c,revenue4__c,revenue5__c from countrydata__c limit 1]; // Just to test i have used limit 1, when i remove limit 1 it not works, bcz value get override.
         List<wrapper> data = new List<wrapper>();
         for(countrydata__c loc: l){
             if(loc.revenue1__c <10){
                 colorTest= 'yellow';
             }
             else{
                 colorTest= 'red';
             }
               data.add(new wrapper(colorTest,loc.name,loc.revenue1__c,loc.revenue2__c,loc.revenue3__c,loc.revenue4__c,loc.revenue5__c ));
          }
          system.debug('--->data is -->'+data);
        return data;
    }
 
 
    public class wrapper
    {
        public String name  {get; set;}
        public String color {get;set;}
        public decimal rev1 {get; set;}
        public decimal rev2 {get; set;}
        public decimal rev3 {get; set;}
        public decimal rev4 {get; set;}
        public decimal rev5 {get; set;}
        public wrapper(string color,String name, decimal rev1, decimal rev2,decimal rev3,decimal rev4,decimal rev5) 
        {
            this.color = color;
            this.name = name;
            this.rev1= rev1;
            this.rev2= rev2;
            this.rev3= rev3;
            this.rev4= rev4;
            this.rev5= rev5;
        }
    }
}

 

 

 

 

bob_buzzardbob_buzzard

The color set applies to the bars plotted for that series - you can't change the colour of the bars inside a series based on the values.