Home Forums Chart Support adding data fields to chart at initialization time

adding data fields to chart at initialization time

Viewing 5 posts - 1 through 5 (of 5 total)
  • #35707

    I am wondering if there is a way to add information to a chart when it is initialized?
    For example :
    var stackChart = new CanvasJS.Chart(“<SUB containerName>”, {
    exportFileName: “StackByProject”,
    myVariable: {information about chart},

    I have added an option to the export toolbar using :
    var toolBar = document.getElementsByClassName(“canvasjs-chart-toolbar”)[0];

    I have a dashboard of charts (each of which use this option) and want to have information about each so that I know what is selected when they choose a particular chart. I am using exportFileName right now but would like to have something a bit more complicated. I suppose I could push information to a separate array or something with reference to unique chart names, but would like to know if this is possible.

    #35715

    @pworthing,

    Can you kindly create JSFiddle and share it with us (or a sample project and share it with us over Google-Drive or OneDrive) along with further briefing about the issue you are facing so that we can look into code / chart-options being used, understand the scenario better and help you out?


    Adithya Menon
    Team CanvasJS

    #35729

    Thanks for reply. I have added an option to add a chart to a favourites list after the user has created it. I then want to know information about the chart that a user created (ie: field they are looking at), so I can reproduce.

    I have created the following:
    https://jsfiddle.net/j5c0s3d6/

    I was trying to create myField1 in the chart yesterday, during initialization. (or was going to use the exportFileName variable if I had to)

    Thinking about it today, I may just add after the chart is created (where I have added myField2 now). I assume this will stick around even if things are resized?
    Still curious if it is possible to do as I tried yesterday with myField1?

    Thanks

    #35739

    @pworthing,

    The get and set methods of chart are used to access and/or change the available chart properties present in the library once the chart is rendered. However, methods don’t support reading custom properties passed in the chart-options. You can access them using chart.options as shown in the code-snippet below.

    chart.options.myField1;
    chart.options.myField2;

    Kindly take a look at this updated JSFiddle for an example on reading custom properties using chart.options.


    Adithya Menon
    Team CanvasJS

    #35742

    thanks

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.