How Bar Chart fx Client script to handle multiple charts via jsapi script?

Chart.setChartTitle("Analysis for : "+categoryData);
Chart.setFilters(new actuate.data.Filter(filterQ, actuate.data.Filter.EQ, stage_id));
Chart.show();
Chart.submit();

Above Is working for me
But I have to handle multiple related chart (right side ) on clicking left side bar
for that I am trying below function; it is working on one chart only; looping happening for all chart, meaning, submition is happening on multiple charts
but only a chart displays
var i = 0;
myFunction(chartsTodisplay, i);
console.log("end........ ");
function myFunction( chartsTodisplay, i)
{
console.log(chartsTodisplay.length +"..inside loop i =.."+i)
if(i < chartsTodisplay.length)
{ var Chart = chartsTodisplay[i];
console.log(Chart.getType() +"..chart for i.."+i)
Chart.submit(myFunction(chartsTodisplay,++i))
}
}

Comments

  • I also tried static two charts
    using function(){chart1.submit(function(){chart2.submit()})}
    or chart1.submit(function(){chart.submit()});
    but both behaves same; only a chart displays

  • What is in the chartsToDisplay[] array? What is the visibility setting for the charts that do not display?

    Jeff F.
    Customer Support Engineer I
    OpenText
  • list of charts elements, I created depends on selection... I do show() on each of chart; but still one chart is visible using
    chart1.submit(function(){chart2.submit()});

    .........................
    var chartsTodisplay = [];
    for(j;j<5;j++)
    {
    chartName = stage_id+""+j;
    filterQ = "custom_analysis
    "+j+"/"+firstLevelValue+"/stage_id"
    Chart = viewer.getCurrentPageContent( ).getChartByBookmark(chartName );
    //console.log(" loop chartName "+chartName +" filterQ "+filterQ +" Chart "+Chart );
    if(Chart != null)
    {
    Chart.setChartTitle("Stage Analysis for : "+categoryData);
    Chart.setFilters(new actuate.data.Filter(filterQ, actuate.data.Filter.EQ, stage_id));
    Chart.show();
    chartsTodisplay.push(Chart );
    console.log(" inside chartName "+chartName +" filterQ "+filterQ +" Chart "+Chart );
    }
    }
    var i = 0;
    myFunction(chartsTodisplay, i);
    function myFunction( chartsTodisplay, i)
    {
    console.log(chartsTodisplay.length +"..inside loop i =.."+i)
    if(i < chartsTodisplay.length)
    { var Chart = chartsTodisplay[i];
    console.log(Chart.getType() +"..chart for i.."+i)
    Chart.submit(myFunction(chartsTodisplay,++i))
    }
    }
    .........
    I do see loop is executing 2 times and two charts coming in the list as per console

  • The callback should work, but I think it is worth testing with an extra delay like below to see if there is an issue with the timing:

    setTimeout(mySubmit, 2000);

    function mySubmit() {
    Chart.submit(myFunction(chartsTodisplay,++i))
    }

    Jeff F.
    Customer Support Engineer I
    OpenText
  • edited November 14

    It turns out that the following line is causing the issue:

    Chart.submit(myFunction(chartsTodisplay,++i))

    The reason for using the callback function inside the submit() is to ensure that the next loop does not begin processing until the current submit() is complete. However, the syntax above causes the inner function to evaluate immediately and pass the results back to the submit() before the submit() runs. Because the callback isn't working, the submit() for the chart is happening before its display property is modified.

    The solution is to use the code:

    Chart.submit( function(){myFunction(chartsTodisplay,++i)} )

    This creates a reference to the inner function that does not run until the outer function is complete.

    Jeff F.
    Customer Support Engineer I
    OpenText
  • edited November 28

    Hi @jfranken
    Thanks for help!
    but it is taking significant time repainting those charts using above script; noticeable behavior!
    ex. if I want to hide one chart and show other one using above; I can see clearly something hiding and something showing and mouse busy during that time;

Sign In or Register to comment.