SAP

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
⤢ Open full site

Integrate Charts and Conditional Rendering

Display data in charts using UI5 Web Components for React.

Overview

🎓 beginner ⏱ 20 min. HTML5BeginnerSAP Fiori

You will learn

  • ✔How to install and import charts
  • ✔Learn about charts in UI5 Web Components for React
  • ✔How to add dynamic rendering
Lukas Harbarth L Lukas Harbarth August 21, 2026
Created on December 5, 2019
Contributors

More from Lukas Harbarth

See all 6 tutorials by Lukas Harbarth →

Steps

Intro

UI5 Web Components for React also comes with a chart library. In this tutorial, you will integrate two chart types and add data to them. Also, you will learn how to conditionally render components, and how React handles updates to the DOM and single components.


Step 1 Install module and import charts
—

  1. Install the chart library of UI5 Web Components for React.

    Shell
     npm install @ui5/webcomponents-react-charts
     > **Note:**
     When facing issues with installing, please ensure you're using the same [minor version](https://semver.org/#summary) as the other `@ui5/webcomponents...` packages.
    
    1. Then, import LineChart and BarChart into MyApp.tsx.

      TypeScript
      import { BarChart, LineChart } from "@ui5/webcomponents-react-charts";
    Code

Add charts to Card component

Charts only offer limited accessibility support with only basic built-in features, so it’s essential to ensure your implementation meets the accessibility standards of your application!

  1. Start with the LineChart. You can add it underneath the Text component. Then pass the dimensions and measures prop with an empty array as value.

    TypeScript
     <Text style={{ padding: "var(--sapContent_Space_S)" }}>
       This is the content area of the Card
     </Text>
     <LineChart measures={[]} dimensions={[]} />
     Now you should see a placeholder for the `LineChart` within the `Card` content. The reason for this is that the chart has not received any data and therefore the placeholder is displayed.
    
    1. Add data to your component. Since data is static you can define it outside the component, right above your MyApp component.

      TypeScript
      const dataset = [
        {
          month: "January",
          data: 65
        },
        {
          month: "February",
          data: 59
        },
        {
          month: "March",
          data: 80
        },
        {
          month: "April",
          data: 81
        },
        {
          month: "May",
          data: 56
        },
        {
          month: "June",
          data: 55
        },
        {
          month: "July",
          data: 40
        }
      ];
    Code
  2. Now add the dataset to your LineChart and configure the dimensions and measures props.

    TypeScript
     <LineChart
       dimensions={[{ accessor: "month" }]}
       measures={[{ accessor: "data", label: "Price" }]}
       dataset={dataset}
     />
     Congratulation, you implemented your first Chart component.
    
     ![LineChart](https://raw.githubusercontent.com/sap-tutorials/Tutorials/master/tutorials/ui5-webcomponents-react-charts/01_linechart.png)
    
    1. Add a BarChart to the Card.

      We want the same data just with a different representation, therefore you can use the same props as you did with the LineChart.

      TypeScript
      <BarChart
         dimensions={[{ accessor: "month" }]}
         measures={[{ accessor: "data", label: "Price" }]}
         dataset={dataset}
      />
    Code
    
    Two charts are rendered now with equal datasets but different representation.

Your MyApp.tsx component should look like this:

TypeScript
import { Card, CardHeader, Text } from "@ui5/webcomponents-react";
import { BarChart, LineChart } from "@ui5/webcomponents-react-charts";

const dataset = [
  {
    month: "January",
    data: 65,
  },
  {
    month: "February",
    data: 59,
  },
  {
    month: "March",
    data: 80,
  },
  {
    month: "April",
    data: 81,
  },
  {
    month: "May",
    data: 56,
  },
  {
    month: "June",
    data: 55,
  },
  {
    month: "July",
    data: 40,
  },
];

export function MyApp() {
  const handleHeaderClick = () => {
    alert("Header clicked");
  };
  return (
    <div>
      <Card
        header={
          <CardHeader
            titleText="Card"
            interactive
            onClick={handleHeaderClick}
          />
        }
        style={{ width: "300px" }}
      >
        <Text style={{ padding: "var(--sapContent_Space_S)" }}>
          This is the content area of the Card
        </Text>
        <LineChart
          dimensions={[{ accessor: "month" }]}
          measures={[{ accessor: "data", label: "Price" }]}
          dataset={dataset}
        />
        <BarChart
          dimensions={[{ accessor: "month" }]}
          measures={[{ accessor: "data", label: "Price" }]}
          dataset={dataset}
        />
      </Card>
    </div>
  );
}
Step 2 Add conditional rendering
+
Step 3 Update a component in React - Loading Indicator
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 3
1. Install module and import charts 2. Add conditional rendering 3. Update a component in React - Loading Indicator
Next