Skip to content

Commit

Permalink
fix: minor
Browse files Browse the repository at this point in the history
  • Loading branch information
s0ftik3 committed May 16, 2023
1 parent 73ebd82 commit 52a6b9a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ function MyChart() {
```

## Chart Props
| Prop | Description | Type |
|-------------|------------------------------------------------|---------|
| width | The width of the chart canvas in pixels. | number \| undefined |
| height | The height of the chart canvas in pixels. | number \| undefined |
| fallback | A fallback element to display when chart fails. | JSX.Element |
| type | The type of the chart. | keyof [ChartTypeRegistry](https://www.chartjs.org/docs/latest/api/interfaces/ChartTypeRegistry.html) |
| data | The chart data object. | [ChartData](https://www.chartjs.org/docs/latest/api/interfaces/ChartData.html) \| undefined |
| options | The chart options object. | [ChartOptions](https://www.chartjs.org/docs/latest/api/interfaces/CoreChartOptions.html) \| undefined |
| Prop | Description | Type |
|----------|-------------------------------------------------|---------|
| width | The width of the chart canvas in pixels. | number \| undefined |
| height | The height of the chart canvas in pixels. | number \| undefined |
| fallback | A fallback element to display when chart fails. | JSX.Element |
| type | The type of the chart. | keyof [ChartTypeRegistry](https://www.chartjs.org/docs/latest/api/interfaces/ChartTypeRegistry.html) |
| data | The chart data object. | [ChartData](https://www.chartjs.org/docs/latest/api/interfaces/ChartData.html) \| undefined |
| options | The chart options object. | [ChartOptions](https://www.chartjs.org/docs/latest/api/interfaces/CoreChartOptions.html) \| undefined |
| plugins | The chart plugins object. | [Plugin](https://www.chartjs.org/docs/latest/api/interfaces/Plugin.html)[] \| undefined |

## Examples
Check out `/dev` folder and run the SolidJs application to see how it works.
Expand Down
2 changes: 1 addition & 1 deletion dev/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const App: Component = () => {
}

const onDimensionsInput = (type: 'width' | 'height', event: any) => {
setChartConfig(type, () => event.target.value)
setChartConfig(type, () => +event.target.value)
}

const onTypeSelect = (event: any) => {
Expand Down
4 changes: 4 additions & 0 deletions src/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function ChartJs(props: ChartJsProps) {
type: 'line',
data: {} as ChartData,
options: { responsive: true } as ChartOptions,
plugins: [],
},
props
)
Expand All @@ -25,6 +26,7 @@ export default function ChartJs(props: ChartJsProps) {
type: config.type,
data: config.data,
options: config.options,
plugins: config.plugins,
})
}

Expand Down Expand Up @@ -61,8 +63,10 @@ export default function ChartJs(props: ChartJsProps) {
on(
() => merged.type,
() => {
const dimensions = [chart.width, chart.height]
chart.destroy()
init()
chart.resize(...dimensions)
},
{
defer: true,
Expand Down
8 changes: 7 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ChartData, ChartOptions, ChartTypeRegistry } from 'chart.js/auto'
import {
ChartData,
ChartOptions,
ChartTypeRegistry,
Plugin,
} from 'chart.js/auto'
import { JSX } from 'solid-js/types/jsx'

export interface ChartJsProps {
Expand All @@ -8,5 +13,6 @@ export interface ChartJsProps {
type: keyof ChartTypeRegistry
data?: ChartData
options?: ChartOptions
plugins?: Plugin[]
[key: string]: any
}

0 comments on commit 52a6b9a

Please sign in to comment.