Guidance Needed for Implementing Chart Copy Feature

Posted by: ajha on 8 December 2025, 2:23 am EST

    • Post Options:
    • Link

    Posted 8 December 2025, 2:23 am EST

    Hello Support Team,

    I am currently working on a project using SpreadJS and need to implement a feature to copy existing charts from one location to another via the context menu of the charts. Right now, Ctrl + C is working fine, but I would like to implement it through the context menu as well.

    So far, I have explored the sheet.charts API and attempted selecting the chart and creating a new chart with the same properties, but I haven’t found a straightforward or recommended way to clone or duplicate charts while preserving their data, formatting, and series mappings.

    Could you please provide guidance on:

    The recommended approach or API for copying a chart in SpreadJS.

    Any examples or best practices for duplicating charts while maintaining all configurations (series, chart type, formatting).

    Potential caveats to consider when copying charts across sheets or workbooks.

    Thank you for your assistance!

  • Posted 8 December 2025, 7:52 am EST - Updated 8 December 2025, 7:58 am EST

    Hi,

    Based on my understanding, you want to copy a shape via the context menu using existing APIs.

    You can achieve this by using the copyShapes command, which allows copying shapes within the same workbook (cross-workbook copying and pasting is not supported).

    To add the option in the context menu, you can refer to this demo:

    https://developer.mescius.com/spreadjs/demos/features/worksheet/context-menu/extend-context-menu/purejs

    Please see the attached GIF and the snippet below where I added a Copy shape option in the chart context menu:

     // adding option in context menu for copy shape
     var copyShapeMenu = {
         text: 'Copy shape',
         name: 'copyShape',
         command: copyShapeHelper,
         workArea: 'shape'
     };
     spread.contextMenu.menuData.push(copyShapeMenu);
    
     function copyShapeHelper() {
         spread.commandManager().execute({ cmd: "copyShapes", sheetName: spread.getActiveSheet().name() });
     }

    GIF:

    Sample: Sample.zip

    Regards,

    Priyam

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels