-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow initialization from a DataTable (#766)
- Loading branch information
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/react-google-charts/stories/DataTable.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from "react"; | ||
import { Chart, GoogleDataTable, GoogleViz } from "../src"; | ||
import * as barChartData from "../../../sandboxes/bar-chart/default/App"; | ||
|
||
export default { | ||
title: "DataTable", | ||
component: Chart, | ||
parameters: { | ||
layout: "centered", | ||
}, | ||
args: { | ||
chartType: "BarChart", | ||
width: 800, | ||
height: 600, | ||
}, | ||
}; | ||
|
||
export function Default({ data, chartType, ...rest }) { | ||
const [dataTable, setDataTable] = React.useState<GoogleDataTable | null>(null); | ||
|
||
const handleGoogleChartLoaded = (google: GoogleViz) => { | ||
const dataTable = google.visualization.arrayToDataTable(data); | ||
|
||
setDataTable(dataTable); | ||
}; | ||
|
||
return <Chart onLoad={handleGoogleChartLoaded} data={dataTable ?? []} chartType={chartType} {...rest} />; | ||
} | ||
|
||
Default.args = { | ||
data: barChartData.data, | ||
options: barChartData.options, | ||
}; |