Skip to content

Commit

Permalink
Add JSONfn as dependency and use it to parse chartjs options
Browse files Browse the repository at this point in the history
This enables functions to be passed as options, e.g. for custom formatting of scale/axis tickmarks:
{...

"scales": {
"yAxes":{
"ticks": {
"callback": "function(value){return value+'%' }"
}
}
}
...
}
  • Loading branch information
rosspdnpa committed Aug 19, 2021
1 parent 4ea979f commit a0f6833
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"prettier": "^2.3.0",
"sort-package-json": "^1.50.0",
"vuepress": "^1.8.2",
"vuepress-theme-gungnir": "^0.2.0"
"vuepress-theme-gungnir": "^0.2.0",
"json-fn": "^1.1.1"
},
"useWorkspaces": true
}
3 changes: 2 additions & 1 deletion packages/plugins/chart/lib/Chart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<script>
import Chart from "chart.js";
import JSONfn from "json-fn";
export default {
name: "Chart",
Expand All @@ -20,7 +21,7 @@ export default {
}
},
mounted() {
const data = JSON.parse(this.code);
const data = JSONfn.parse(this.code);
const ctx = this.$refs.chartjs.getContext("2d");
new Chart(ctx, data);
}
Expand Down

0 comments on commit a0f6833

Please sign in to comment.