Home Forums Chart Support Read extra data sent in the AJAX JSON string

Read extra data sent in the AJAX JSON string

Viewing 4 posts - 1 through 4 (of 4 total)
  • #42198

    I am using JSON to get chart data from MVC Controller to the charts View page. All is working fantastic.

    I decided to use the chart JSON thread to send some additional data to be used by the View page.

    I am unsure how to pickup this additional data once its in the View.

    Here is the first part of my code;

    			function addData(data) {
    				for (var i = 0; i < data.length; i++) {
    						label: data[i].label,
    						x: data[i].x,
    						y: data[i].y,
    						indexLabel: data[i].preLabel,
    						color: data[i].color,
    						periodName: data[i].periodName,
    						jobName: data[i].jobName,
    						z: data[i].z,
    						sortDate: data[i].sortDate,
    						extraData : data[i].extraData,

    I have tried the following in Javascript to pick up the extraData. This is obviously not correct. Can someone show me the correct syntax here?

    var pageName == extraData[0].value
    var alertMessage == extraData[1].value



    You can get your extra data passed to datapoints using chart object as shown below

    var pageName = chart.options.data[0].dataPoints[0].extraData[0].value
    var alertMessage = chart.options.data[0].dataPoints[0].extraData[1].value

    If you are still facing issue, kindly create a sample project reproducing the issue you are facing and share it with us over Google-Drive or Onedrive along with sample data so that we can look into your code, run it locally at our end to understand the scenario better and help you out?

    Manoj Mohan
    Team CanvasJS


    Thank you Manoj

    Your syntax didnt get me there but helped by giving me some more options to try. I suspect your solution needs to be placed in a exact location of the chart’s functions for it to work.

    This is what I would up with that is working by placing at the end of the function: function addData(data){}

    pageName = dataPoints[0].extraData;
    alertMessage = dataPoints[1].extraData;



    Glad that you were able to get the desired solution.

    Manoj Mohan
    Team CanvasJS

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

You must be logged in to reply to this topic.