@geins/ralph-module-chart-js
v1.0.1
Published
Chart.js module for Geins PWA Storefront Ralph
Downloads
3
Readme
Chart.js module for Geins PWA Storefront Ralph
A module for Geins PWA Storefront Ralph that adds Chart.js charts to your storefront.
Pre-requisites
- Geins Account and PWA Storefront Ralph. Get a free trial here
Description
This module enables you to add Chart.js charts to your storefront in seconds.
Module can be used in any page of your storefront and is configuerd to work with Geins Cart out-of-box. Module can be added via Geins CMS or any CMS of your choice.
Installation
1. Install the module
npm i @geins/ralph-module-chart-js
2. Add the module to your Geins PWA Storefront Ralph
Add the module to your Geins PWA Storefront Ralph by adding the following line to your nuxt.config.js
file:
// nuxt.config.js
...
modules: [
[
'@geins/ralph-module-chart-js',
{
enabled: true,
debug: true
}
]
],
To use with Geins CMS (no-code)
1. Add the module to your Geins PWA Storefront Ralph
Use the @geins/ralph-module-cms-json-container
npm i @geins/ralph-module-cms-json-container
2. Add the module to your Geins PWA Storefront Ralph
Add module to your nuxt.config.json
file:
...
modules: [
'@geins/ralph-module-cms-json-container'
]
..
Set the widgetRenderTypesComponents
in your nuxt.config.json
file to use the GeinsWidgetJsonContainer
component for the JSON
widget type.
// nuxt.config.js
...
publicRuntimeConfig: {
widgetRenderTypesComponents: {
JSON: 'GeinsWidgetJsonContainer'
},
}
...
Module Options
Add extra options to module configuration in nuxt.config.js
file.
| Parameter | Type | Default | Example |
|-|-|-|
| enabled | String | true
| Enables the module|
| debug | String | false
| Enables debug info to console |
| chartOptions | Object | {} | For chart-customization, add your own options object here Chart.js docs |
| chartPlugins | Array | [] | If available, add an arrray of your chart-plugins here Chart.js docs |
Usage
Add component to desired page of your storefront. Either by cms or as a component.
Component
Components
Module adds two components to your storefront. GeinsChartJs
and GeinsWidgetChartJs
.
GeinsChartJs
This component is used to show the streamify player. It is used by the GeinsWidgetChartJs
component. You can use it directly in your page if you want to add the player directly to your page.
Properties
The properties of the component are one to one with the Chart.js API. You can add any property to the component and it will be passed to the API.
| Property | Type | Default Value | Required | Description | | --------------- | ------- | ------------- | -------- | -------------------------------------------------------------------------------------------------- | | type | String | 'line' | No | Type of chart | | data | Object | - | Yes | Dataset and labels for your chart | | options | Object | default Chart.js options | No | Chart options | | plugins | Array | [] | No | Chart plugins|
Use with Geins CMS
Add a JSON Widget
to your page in the Geins CMS. Add the following JSON to your widget (replace with your own dataset and labels). Customize the values according to your own dataset and preferences.
Example of JSON widget content:
{
"renderWidget": "GeinsWidgetChartJs",
"data": {
"data": {
"labels": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
"datasets": [{
"label": "Sunlight hours per month",
"data": [197, 216, 232, 244, 248, 290, 288, 274, 268, 246, 212, 182]
}]
}
}
}
Customizing Styling of chart to match your storefront
To add global customization to your charts, create a folder inside your static-folder called chartJs
. Inside this create a file called chartOptions.js
.
Inside this file, add your custom options (see below example):
// chartOptions.js
export const chartOptions = {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
border: {
display: false
},
grid: {
display: false,
drawTicks: false
}
},
x: {
border: {
display: false
},
grid: {
display: false,
drawTicks: false
}
}
}
}
See docs for Chart.js options for more options.
Import your chartOptions.js
file into your nuxt.config.js
:
import { chartOptions } from './static/chartJs/chartOptions';
Add the chartOptions to your module options:
[
'@geins/ralph-module-chart-js',
{
enabled: true,
chartOptions: chartOptions,
}
]
As a component or with any CMS
Add the component to your page. Add the type as properties to the component.
<GeinsChartJs
:type="chartType"
:data="chartData"
:options="chartOptions"
:plugins="chartPlugins"
/>
Tips!
Add a chart to you PDP to display product meta data in a intuitive way.