|
| 1 | +--- |
| 2 | +title: Create a Data Visualization Adaptive Card Extension |
| 3 | +description: Step-by-step guide on creating Data Visualization Adaptive Card Extension. |
| 4 | +ms.date: 04/05/2024 |
| 5 | +ms.localizationpriority: high |
| 6 | +--- |
| 7 | +# Create a Data Visualization Adaptive Card Extension |
| 8 | + |
| 9 | +The [SharePoint Framework v1.19](../../release-1.19.md) introduces a new Data Visualization Template that can be used to implement line charts. This tutorial provides step-by-step guidance on implementing Data Visualization with Adaptive Card Extensions (ACEs). |
| 10 | + |
| 11 | +[!INCLUDE [developer-preview-notice](../../../../includes/snippets/developer-preview-notice.md)] |
| 12 | + |
| 13 | +> [!NOTE] |
| 14 | +> Before you start, complete the procedures in the following articles to ensure that you understand the basic flow of creating a custom Adaptive Card Extension: [Build your first SharePoint Adaptive Card Extension](./build-first-sharepoint-adaptive-card-extension.md) |
| 15 | +
|
| 16 | +## Scaffold an Adaptive Card Extension project |
| 17 | + |
| 18 | +Create a new project directory for your project and change your current folder to that directory. |
| 19 | + |
| 20 | +Create a new project by running the Yeoman SharePoint Generator from within the new directory you created: |
| 21 | + |
| 22 | +```console |
| 23 | +yo @microsoft/sharepoint |
| 24 | +``` |
| 25 | + |
| 26 | +When prompted, enter the following values (select the default option for all other prompts): |
| 27 | + |
| 28 | +- **What is your solution name?** dataVisualization-tutorial |
| 29 | +- **Which type of client-side component to create?** Adaptive Card Extension |
| 30 | +- **Which template do you want to use?** Data Visualization Card Template (preview) |
| 31 | +- **What is your Adaptive Card Extension name?** DataVisualization |
| 32 | + |
| 33 | +At this point, Yeoman installs the required dependencies and scaffolds the solution files. This process might take few minutes. |
| 34 | + |
| 35 | +## Update your project's hosted workbench URL |
| 36 | + |
| 37 | +When you use the gulp task **serve**, by default it will launch a browser with the specified hosted workbench URL specified in your project. The default URL for the hosted workbench in a new project points to an invalid URL. |
| 38 | + |
| 39 | +- Locate and open the file **./config/serve.json** in your project. |
| 40 | +- Locate the property `initialPage`: |
| 41 | + |
| 42 | + ```json |
| 43 | + { |
| 44 | + "$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json", |
| 45 | + "port": 4321, |
| 46 | + "https": true, |
| 47 | + "initialPage": "https://{tenantDomain}/ _layouts/workbench.aspx" |
| 48 | + } |
| 49 | + ``` |
| 50 | + |
| 51 | +- Change the `{tenantDomain}` ___domain to the URL of your SharePoint tenant and site you want to use for testing. For example: `https://contoso.sharepoint.com/sites/devsite/_layouts/workbench.aspx`. |
| 52 | + |
| 53 | +At this point, if you do `gulp serve`, and select the add icon in the hosted workbench to open the toolbox, you'll see the **Data Visualization** card: |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +Select the **DataVisualization** component to add it to the workbench. The default rendering renders the line chart using mock data: |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +## Explore the scaffolded code |
| 62 | + |
| 63 | +### Explore the Card View |
| 64 | + |
| 65 | +Locate and open the following file: **./src/adaptiveCardExtensions/dataVisualization/cardView/CardView.ts**. The card view implements the `BaseComponentsCardView` base class `cardViewParameters` getter to specify the card configuration: |
| 66 | + |
| 67 | +```typescript |
| 68 | +const seriesData : IDataPoint<Date>[] = [ |
| 69 | + ... // omitted for brevity |
| 70 | +]; |
| 71 | + |
| 72 | +export class CardView extends BaseComponentsCardView<..> { |
| 73 | + public get cardViewParameters(): IDataVisualizationCardViewParameters { |
| 74 | + return LineChartCardView({ |
| 75 | + cardBar: { |
| 76 | + componentName: 'cardBar', |
| 77 | + title: this.properties.title |
| 78 | + }, |
| 79 | + body: { |
| 80 | + componentName: 'dataVisualization', |
| 81 | + dataVisualizationKind: 'line', |
| 82 | + series: [{ |
| 83 | + data: seriesData, |
| 84 | + lastDataPointLabel: '3.1K' |
| 85 | + }] |
| 86 | + } |
| 87 | + }); |
| 88 | + } |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +Notice how the `body` section of the card view specifies the `dataVisualization` component. |
| 93 | + |
| 94 | +### Explore possible layouts |
| 95 | + |
| 96 | +Based on the configuration in card view, a chart can be rendered in two layouts: |
| 97 | + |
| 98 | +#### Regular |
| 99 | + |
| 100 | +Adding zero or one component along with a `dataVisualization` component in the body: |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | +#### Right side |
| 105 | + |
| 106 | +Adding more than one component in the card view along with `dataVisualization` component in the body will render the chart on the right side of the card. For example: Header and Footer along with `dataVisualization` component in body. |
| 107 | + |
| 108 | +Locate & replace the `cardViewParameters()` getter with the following code to add a `header` and `footer` to the card: |
| 109 | + |
| 110 | +```typescript |
| 111 | +public get cardViewParameters(): IDataVisualizationCardViewParameters { |
| 112 | + return LineChartCardView({ |
| 113 | + cardBar: { |
| 114 | + componentName: 'cardBar', |
| 115 | + title: this.properties.title |
| 116 | + }, |
| 117 | + header: { |
| 118 | + componentName: 'text', |
| 119 | + text: 'Sales Projection' |
| 120 | + }, |
| 121 | + body: { |
| 122 | + componentName: 'dataVisualization', |
| 123 | + dataVisualizationKind: 'line', |
| 124 | + series: [{ |
| 125 | + data: seriesData, |
| 126 | + lastDataPointLabel: '3.1K' |
| 127 | + }] |
| 128 | + }, |
| 129 | + footer: { |
| 130 | + componentName: 'cardButton', |
| 131 | + title: 'View Details', |
| 132 | + action: { |
| 133 | + type: 'QuickView', |
| 134 | + parameters: { |
| 135 | + view: QUICK_VIEW_REGISTRY_ID |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + }); |
| 140 | +} |
| 141 | +``` |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | +### Explore the Quick Views |
| 146 | + |
| 147 | +The ACE class is located in the following file: **./src/adaptiveCardExtensions/dataVisualization/quickView/QuickView.ts** and mostly has the same code as [Generic Card View](./build-first-sharepoint-adaptive-card-extension.md). |
| 148 | + |
| 149 | +### Explore the ACE class |
| 150 | + |
| 151 | +The ACE class is located in the following file: **./src/adaptiveCardExtensions/dataVisualization/dataVisualizationAdaptiveCardExtension.ts** and mostly has the same code as [Generic Card View](./build-first-sharepoint-adaptive-card-extension.md). |
0 commit comments