[QUESTION] How to have a dynamic properties in a custom block?
Question
Hello, I am making a custom category using ChartJS which would be blocks of draggable charts. I currently have this code to have a static chart rendered in the canvas after dropping
blockManager.add('test-chart-block', {
label: `<div>
<img src="dist/img/bar-chart.png" height="60px" width="60px">
<div class="my-label-block">Test Chart Block</div>
</div>`,
category: 'Charts',
attributes: {},
content: {
content: `<canvas id="bar-chart"></canvas>`,
script: function () {
var ctx = document.getElementById("bar-chart");
new Chart(ctx, {
type: 'bar',
data: {
labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
datasets: [
{
label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
data: [2478,5267,734,784,433]
}
]
},
options: {
legend: { display: false },
title: {
display: true,
text: 'Predicted world population (millions) in 2050'
}
}
});
},
style: {
height: '350px',
width:'500px'
}
}
});
Now my problem is after dragging it I cannot update/edit the chart's data. How can I make it so that the data, options properties of the Chart is editable?
Thank you.
Answers (0)
No answers yet.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2596
[QUESTION] Add html, css and js to Block Manager
[QUESTION] Hi! I'm retrieving dynamic html,css and js codes from the database. How can I create Blocks with this? Currently, this is my cod...
Issue #1722
[QUESTION] how to make my custom tag as selectable and editable inside of canvas ?
Hi, I try to change my custom tag of ion-item has div in view properties but It doesn't work for me as I expected. my custom Blocks is my c...
Issue #1574
Question, Block content from file
Hi, this is not really an issue but more a question. I'm currently using custom blocks in my GrapesJS editor. This is how I create them : I...
Issue #2122
[Question] Adding script to content with chart js
Hello I am trying to add a Graph JS block with this code but whenever I would drag the new block I would get an error: How do I add a scrip...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.