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

Venu_Bachwale
edited February 11, 2022 in Analytics #1
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?

    Warning No formatter is installed for the format ipb
  • 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))
    }

    Warning No formatter is installed for the format ipb
  • jfranken
    edited November 14, 2019 #6

    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.

    Warning No formatter is installed for the format ipb
  • Venu_Bachwale
    edited November 28, 2019 #7

    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;

  • Hi Venu,

    One simple option is to set the viewer height to 0 first, run all of your code, then set the viewer height back to its normal setting. It will prevent the user from seeing the individual processing steps on the page. I don't think it will add significantly to the overall time because you are just resizing elements on the client, not hitting the server.

    Warning No formatter is installed for the format ipb