Duplicate a visualization programmatically


#1

Hi guys, In my web application, I am building an interface that has some visualizations. The thing is that I am creating some custom functionalities, and in one of them what I intend to do is duplicate a certain visualization, to obtain its current configuration, and then modify some of its properties like the filters for example and then execute it.

When I was exploring ChartFactor Studio, widgets have the option to create a duplicate to an exact copy of the old one. I want to do the same but dynamically via javascript code.

What would be the best practice to do this, other than cloning the entire Aktive object?


#2

Hi @dev.tree, thanks for reaching out. Yes, as you say, ChartFactor Studio has the functionality to duplicate visualizations or widgets, in an efficient way. The good news is that ChartFactor Toolkit allows you to do the same functionality via code as I show you below:

const currentAktive = cf.getVisualization('current-visualization-id');
const newAktive = currentAktive.duplicate();

// Assigning a new element id
newAktive.element('my-new-element-id');

// Now change all the properties as needed
// ...

Please try this and tell me how it went.

Best regards.


#3

Oh @juan.dominguez, that solution is pretty neat :grinning:. I already tried it and the truth is that it works wonders, and quickly. Thanks a lot.