Introduction
We often build Lightning Web Components (LWC) as Salesforce developers to deliver interactive features. However, configuring them for non-technical admins usually requires editing code. What if admins could adjust properties like chart type, title, or data filters directly in Community Builder? In this post, you’ll learn how to build an LWC using Chart.js that exposes @api properties—making it fully configurable in Experience Cloud without touching code.
Why Public Properties Matter
By marking component attributes with @api and declaring them in the .js-meta.xml file, you empower admins to control your component’s behavior—chart type (pie, bar, e.g.), legend placement, title, and data filters—via drag-and-drop. This aligns well with Salesforce’s philosophy of admin-driven configuration, boosting flexibility and reducing developer dependencies.
Example Scenario: Visualizing Case Metrics for a Customer Support Community
Objective
A Salesforce customer support team wanted to empower their Experience Cloud community admins to visualize case metrics dynamically. These metrics included case statuses such as “New,” “Working,” “Closed,” and others. The solution needed to ensure that admins could adjust the chart type, title, and legend placement directly in Experience Builder. They should be able to manage data filters as well. This should be done without requiring developer assistance.
Implementation Steps
- Backend Logic with Apex
An Apex controller,CaseController, was built to fetch case metrics grouped by status. The method,getCaseData, accepted a comma-separated string of statuses as input, making it flexible for filtering specific case types. - Dynamic LWC Component
The LWC,dynamicChartComponent, was designed to display the case metrics using Chart.js. It included the following features:- Public
@apiproperties for admin configurability:chartType: Determines the type of chart (e.g., pie, bar, doughnut).legendPosition: Sets the legend’s location (e.g., top, left).chartTitle: Allows custom titles for charts.caseStatuses: Filters the case data by status.
@wireto fetch data from the Apex controller and dynamically update the chart.
- Public
- Configurable Metadata
The.js-meta.xmlfile declared public properties, exposing them in Experience Builder. Admins could modify these properties via drag-and-drop without touching the code. - Chart.js Integration
- The component loaded the Chart.js library dynamically using
loadScript. - Once data was available, the component initialized or updated the chart with user-defined settings.
- The component loaded the Chart.js library dynamically using
- Experience Builder Deployment
After deploying the LWC and Apex components:- The admin added the
dynamicChartComponentto the Experience Builder page. - Configured the properties:
- Chart Type: Doughnut
- Legend Position: Right
- Title: “Support Case Distribution”
- Case Status Filter: New, Working, Closed
- The admin added the
- Testing and Validation
The community was published. The chart updated instantly based on user interactions. It was also updated with property changes in the Experience Builder.
Outcome
The implemented solution allowed admins to:
- Visualize key case metrics dynamically in various chart formats.
- Configure charts without involving developers, fostering agility.
- Provide community users with actionable insights through interactive visual dashboards.
This approach not only streamlined community management but also enhanced user engagement with visually appealing and up-to-date data.
Demo
Sample Code
Conclusion
By adding @api properties and defining them in .js-meta.xml, you create LWC components that are both developer-driven and admin-configurable. In this Chart.js example, admins can tailor how data is visualized—shape, labels, filters—entirely from Community Builder. This approach reduces dev workload, increases flexibility, and empowers business users with dynamic dashboards.


Leave a comment