Loading...

Bring Salesforce data to life with dynamic charts inside Lightning pages! While Salesforce dashboards are powerful, sometimes business users want visual insights without leaving their current page. That’s where Chart.js with Lightning Web Components (LWC) becomes a game-changer.

In this step-by-step guide, you’ll learn how to:


  • Upload Chart.js as a static resource in Salesforce.

  • Build an Apex controller to fetch real-time Opportunity data.

  • Create a Lightning Web Component that renders an interactive chart.

  • Deploy it directly inside Lightning App Pages, Record Pages, or Home Pages.

By the end, you’ll have a fully functional, real-time Salesforce chart using LWC and Chart.js, complete with dropdown filters, tooltips, and beautiful animations; ready to impress your users and stakeholders.

Step-by-Step Guide to Upload Chart.js as a Static Resource

Step 1: Download Chart.js


  • Go to the Chart.js official website.

  • Download the latest chart.min.js file.

Step 2: Open Salesforce Setup


  • Log in to Salesforce.

  • Click on the gear icon, then Setup.

Step 3: Navigate to Static Resources


  • In the Quick Find box, search for Static Resources.

  • Click New to create a new static resource.

Step 4: Upload the File


  • Enter Name: ChartJS (make sure there are no spaces).

  • Click Choose File, then select the downloaded chart.min.js file.

  • Set Cache Control to Public.

  • Click Save.

Step 5: Go to the Setup Tab in Salesforce.

Step 6: Search for Static Resource.

Step 7: Click on New Static Resources.

Step 8: Fill in the Required Details.

Once the Static Resources are set up, we can create a Lightning component and make an Apex controller.

Now, let’s take Salesforce Custom Object Opportunity and ensure you have Opportunities with Amount values in your org (otherwise the chart will be empty).

Step to Create an Apex Controller.

We need an Apex class to fetch the Opportunity data grouped by Stage. This class groups Opportunities by Stage and returns the label (stage name) + value (total amount).

Now, let’s build the Lightning Web Component.

Step to Create LWC (Lightning Web Component).

Since JavaScript is crucial in this case, we will begin with it next.

XML

Step 2: Deploy & Test


  • Deploy the Apex class and LWC bundle to your Salesforce org.

  • Go to Lightning App Builder, then drag the chartDemo component onto a page.

  • Open the page, and you’ll see your animated doughnut chart of Opportunity Amounts.

  • Use the dropdown filter to switch between All, Closed Won, Closed Lost, etc.

Final Output


  • A dynamic, animated chart showing Opportunity Amounts by Stage.

  • Supports filters from a dropdown.

  • Automatically updates chart and total amount.

  • Beautiful colors, tooltips, and animations using Chart.js.

And that’s it! You’ve successfully created an interactive, animated chart in Salesforce LWC using Chart.js.

Watch Live Demo Video:

Conclusion

And that’s it! You’ve successfully built a dynamic, animated Salesforce chart with LWC and Chart.js. With just a few steps, you can transform plain Opportunity data into meaningful visualizations right inside Lightning pages; no external BI tools are required.

This approach is flexible and reusable:


  • Replace Opportunities with Leads, Cases, or custom objects.

  • Customize chart types (bar, line, pie, doughnut, etc.)

  • Add more filters to make insights even more interactive.

By combining Salesforce data visualization with the power of Chart.js in LWC, you empower business users with actionable insights where they need them most. Try it in your org today, and take your Lightning Web Components to the next level!

👉 Looking to build tailored solutions like this for your business? Explore our Salesforce Development Services and let our experts help you create scalable, future-ready apps that drive results.

Related Articles

Sticky notes aren’t just for your desk anymore! In this tutorial, we’ll create a Lightning Web Component (LWC) in Salesforce that allows you to pin notes on your app page or record page. With a clean, interactive UI, these digital sticky notes ensure you never forget important tasks or details. What Will You Learn? By […]

Read More
How to Encrypt and Decrypt Data in Salesforce Using Apex Crypto Class

Data security is more important than ever. Whether you’re storing customer information, sensitive business data, or private communication, ensuring that your data stays safe is critical. Salesforce provides built-in tools to help with this, and one of the most powerful yet easy-to-use approaches is encryption and decryption using the Apex Crypto class. In this blog, […]

Read More
Benefits & Step-by-Step Setup Guide for Salesforce Code Analyzer

When building on the Salesforce platform, code quality and security are non-negotiable, especially before submitting your app for a Salesforce Security Review. Catching bugs and vulnerabilities early not only saves time but also ensures compliance with Salesforce’s best practices. That’s where the Salesforce Code Analyzer comes in. This open-source tool scans your Apex classes, triggers, […]

Read More
A Step-by-Step Guide to Integrate Zoho CRM with Salesforce (Without Coding)

Managing data across multiple CRMs can be a real challenge for businesses that want a single source of truth. If your teams use Zoho CRM but want to move or sync all records seamlessly into Salesforce, you don’t need to write a single line of code. Thanks to MultiSync Made Easy, the integration process is […]

Read More
How to Integrate Salesforce with Copilot

Integrating Salesforce with Copilot is becoming an essential step for organizations aiming to streamline workflows, automate client data management, and unlock the power of AI-driven CRM. By connecting these two platforms, businesses can centralize customer information, reduce manual tasks, and accelerate growth. This guide walks you through the Salesforce–Copilot integration process with clear steps, Apex […]

Read More
Expert Guide Seamlessly Sync Refunds Taxes & Shipping Lines from Shopify to Salesforce

Managing eCommerce transactions efficiently requires accurate data flow between platforms. For Shopify store owners using Salesforce, it’s crucial that every order detail, including refunds, taxes, and shipping charges, is accurately transferred. This ensures financial records remain consistent, customer service stays smooth, and reporting is always up to date. In this guide, we’ll walk you through […]

Read More