You need to sign in to do that
Don't have an account?
Harshitha B
How to display chart using visualforce page
Hi,
can any one help me, How to display chart based on the selection of from date and to date using visualforce page.
Thanks,
can any one help me, How to display chart based on the selection of from date and to date using visualforce page.
Thanks,
Your code is perfect apart from few changes. Please find below modified code and let me know if that works for you.
VF Page:
Controller:
Best Regards,
BALAJI
All Answers
To display charts, you can use apex charts(https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_charting_overview_simple_example.htm).
And for Date range, you can get two date fields and a button to process and fetch input related data, add this to charting.
please check my code and let me know if you get it
Your code is perfect apart from few changes. Please find below modified code and let me know if that works for you.
VF Page:
Controller:
Best Regards,
BALAJI
Yes, you can do the same thing using Custom Objects as well. Just query the records from the Custom Object and aggregate them by require fields . Take appropriate chart in Visualforce page and do required changes in Controller.
Best Regards,
BALAJI
I have a custom object names as Emp and API name is Emp__c which has a custom field Designation whose API name is desig__c.
Now, I am creating a Chart for that Custom Object which displays Pie chart with different designations.
VF Page:
Controller:
Screeshot of the Chart:
Best Regards,
BALAJI
same thing Bar Chart
I Have One Custom object (Customer_C) and Two Date Field Start date and End Date
can u give Conrtoller code and vf page
Actully i m new in salesforce
You have to just replace with the Account object with your custom object Customer__c and replace billingcity with your required field in custom object.
Please find below links to understand more about Visualforce Charts:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_charting.htm
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_charting_overview_simple_example.htm
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_chart.htm
Best Regards,
BALAJI
System.UnexpectedException: field 'Start_Date__c' can not be grouped in a query call
Error is in expression '{!submit}' in component <apex:commandButton> in page barchart: Class.AccountRec_Barchart.submit: line 11, column 1
Class.AccountRec_Barchart.submit: line 11, column 1
Generate
this my code
Contoller
public class AccountRec_Barchart
{
public date fromDate{set;get;}
public date todate{set;get;}
public list<aggregateresult> listaggregate= new list<aggregateresult>();
public list<barchartdata> lb = new list<barchartdata>();
public void submit()
{
listaggregate=[SELECT Hall__c,Name,Count(Id) n,End_Date__c FROM Booking__c
where Start_Date__c> : fromDate and End_Date__c<:todate
group BY Hall__c ,Name,Start_Date__c,End_Date__c,Customer__r.Name
];
system.debug('ffdd'+ listaggregate);
}
public barchartdata[] getdata()
{
system.debug('getdata');
barchartdata[] datachart = new barchartdata[]{};
for(aggregateresult a :listaggregate)
{
datachart.add(new barchartdata(a));
}
return datachart;
}
// wrapper class
public class barchartdata
{
public string city {set;get;}
public integer count{set;get;}
public string billingcityname{set;get;}
barchartdata(aggregateresult result)
{
this.count = (Integer) result.get('n');
this.city = (string) result.get('billingcity');
this.billingcityname = city+'';
}
}
}
Vf page
<apex:page controller="AccountRec_Barchart" docType="html-5.0" title="Bar chart" >
<apex:form >
<apex:outputText value="from Date">
</apex:outputText>
<apex:input type="date" value="{!fromdate}"/>
<apex:outputText value="ToDate"></apex:outputText>
<apex:input type="date" value="{!todate}" />
<apex:commandButton value="submit" action="{!submit}" reRender="chartid" />
</apex:form>
<apex:chart id="chartid" height="300" width="650" data="{!data}" colorSet="2A98DC" resizable="true" >
<apex:axis type="Numeric" position="left" fields="count" title="Recordcount" minimum="0" grid="false" />
<apex:axis type="Category" position="bottom" fields="billingcityname" title="billingcity" />
<apex:barSeries orientation="vertical" axis="left" xField="billingcityname" yField="count">
</apex:barSeries>
</apex:chart>
<apex:chart height="300" width="650" data="{!data}" resizable="true">
<apex:pieSeries tips="true" dataField="count" labelField="billingcityname"></apex:pieSeries>
<apex:legend position="right"/>
</apex:chart>
</apex:page>