From 048c2563e7b7078e108bed72ab0c2165041c2432 Mon Sep 17 00:00:00 2001
From: cagataycivici
Date: Thu, 23 May 2019 15:41:45 +0300
Subject: [PATCH] Add select event to Chart and updated docs
---
src/assets/styles/app.scss | 4 +--
src/components/chart/Chart.vue | 17 +++++++++-
src/views/chart/ChartDoc.vue | 61 ++++++++++++++++++++++++++++++++--
3 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/assets/styles/app.scss b/src/assets/styles/app.scss
index af39fb25b..0c2e4b5f8 100644
--- a/src/assets/styles/app.scss
+++ b/src/assets/styles/app.scss
@@ -674,14 +674,14 @@ body {
th {
background-color: #d6dade;
- padding: 8px 14px;
+ padding: 10px 14px;
text-align: left;
border: solid 1px #d6dade;
}
tbody{
td {
- padding: 8px 14px;
+ padding: 10px 14px;
border: 1px solid #eaecee;
}
diff --git a/src/components/chart/Chart.vue b/src/components/chart/Chart.vue
index c47874ba4..0b246b3da 100644
--- a/src/components/chart/Chart.vue
+++ b/src/components/chart/Chart.vue
@@ -1,6 +1,6 @@
-
+
@@ -60,6 +60,21 @@ export default {
this.chart.destroy();
this.initChart();
}
+ },
+ onCanvasClick(event) {
+ if (this.chart) {
+ const element = this.chart.getElementAtEvent(event);
+ const dataset = this.chart.getDatasetAtEvent(event);
+
+ if (element && element[0] && dataset) {
+ this.emit('select', {originalEvent: event, element: element[0], dataset: dataset});
+ }
+ }
+ },
+ generateLegend() {
+ if (this.chart) {
+ return this.chart.generateLegend();
+ }
}
}
}
diff --git a/src/views/chart/ChartDoc.vue b/src/views/chart/ChartDoc.vue
index 2a4eed2b1..0cb53c6b1 100644
--- a/src/views/chart/ChartDoc.vue
+++ b/src/views/chart/ChartDoc.vue
@@ -12,10 +12,10 @@ import Chart from 'primevue/chart';
Chart Types
- Chart type is defined using the type property. Currently there are 6 options available; "pie", "doughtnut", "line", "bar", "radar" and "polarArea".
+ Chart type is defined using the type property. Currently there are 6 options available; pie, doughtnut, line, bar, radar and polarArea.
Data
- Data of a chart is provided using a binding to the data property, each type has its own format of data. Here is an example of a line chart.
+ Data of a chart is provided using a binding to the data property, each type has its own format of data. Here is an example of a line chart. For more information refer to the charts.js documentation.
<Chart type="bar" :data="basicData" />
@@ -46,7 +46,7 @@ export default {
Options
While a series can be customized per dataset, general chart options are defined with options property.
- Example below adds a title and customizes the legend position of the chart. For all available options refer to the charts.js documentation.
+ Example below adds a title and customizes the legend position of the chart. For all available options refer to the charts.js documentation.
<Chart type="line" :data="data" :options="options" />
@@ -78,6 +78,7 @@ options: {
Properties
+ Any attribute such as style and class are passed to the main container element. Following is the additional property to configure the component.
@@ -138,9 +139,63 @@ options: {
refresh |
- |
Redraws the graph. |
+
+
+ reinit |
+ - |
+ Destroys the graph first and then creates it again. |
+
+
+ generateLegend |
+ - |
+ Returns an HTML string of a legend for that chart. The legend is generated from the legendCallback in the options. |
+
+ Events
+
+
+
+
+ Name |
+ Parameters |
+ Description |
+
+
+
+
+ select |
+
+ event: original event
+ event.dataset: Selected dataset
+ event.element: Selected element
+ event.element._datasetIndex = Index of the dataset in data
+ event.element._index = Index of the data in dataset
+ |
+ Callback to invoke when a tab gets expanded. |
+
+
+
+
+
+ Styling
+
+
+
+
+ Name |
+ Element |
+
+
+
+
+ p-chart |
+ Container element. |
+
+
+
+
\ No newline at end of file