File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
packages/react-google-charts Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -127,7 +127,9 @@ export class GoogleChartInternal {
127127 ) ;
128128 }
129129 if ( data ) {
130- if ( Array . isArray ( data ) ) {
130+ if ( data instanceof google . visualization . DataTable ) {
131+ dataTable = data ;
132+ } else if ( Array . isArray ( data ) ) {
131133 dataTable = google . visualization . arrayToDataTable ( data ) ;
132134 } else {
133135 dataTable = new google . visualization . DataTable ( data ) ;
Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+ import { Chart , GoogleDataTable , GoogleViz } from "../src" ;
3+ import * as barChartData from "../../../sandboxes/bar-chart/default/App" ;
4+
5+ export default {
6+ title : "DataTable" ,
7+ component : Chart ,
8+ parameters : {
9+ layout : "centered" ,
10+ } ,
11+ args : {
12+ chartType : "BarChart" ,
13+ width : 800 ,
14+ height : 600 ,
15+ } ,
16+ } ;
17+
18+ export function Default ( { data, chartType, ...rest } ) {
19+ const [ dataTable , setDataTable ] = React . useState < GoogleDataTable | null > ( null ) ;
20+
21+ const handleGoogleChartLoaded = ( google : GoogleViz ) => {
22+ const dataTable = google . visualization . arrayToDataTable ( data ) ;
23+
24+ setDataTable ( dataTable ) ;
25+ } ;
26+
27+ return < Chart onLoad = { handleGoogleChartLoaded } data = { dataTable ?? [ ] } chartType = { chartType } { ...rest } /> ;
28+ }
29+
30+ Default . args = {
31+ data : barChartData . data ,
32+ options : barChartData . options ,
33+ } ;
You can’t perform that action at this time.
0 commit comments