Chart Selection Handler

Home Forums SPJS Charts for SharePoint Chart Selection Handler

Viewing 1 reply thread
  • Author
    Posts
    • #7740
      HTIC
      Participant

        Hi Alex,

        I’m hoping you can help. I have my charts set up in my CEWP (shown below) and I’m using the ‘spjs_getFilterValue’ function to return custom filter values which is shared between multiple charts using the filterAdditionalCharts’ option, and the ‘spjs_chartSelectionHandler’ function is used to select and return the data in a new window.

        This works fine initially when I load the page and click on the chart data – the ‘spjs_chartSelectionHandler’ runs through and uses the URL to return the List data in a new window as expected. However, as soon as I select another value from the filter dropdown and repeat the same action (i.e. click on a chart item) the ‘spjs_chartSelectionHandler’ function seems to act like a loop which returns multiple instances of the same list data.

        I’m not sure if it’s something to do with how I’ve written my code or the function itself but I would really appreciate your assistance?

        <style type=”text/css”>
        font-style:italic;
        color:white;
        border:1px silver solid;
        background-color:#7DB0AF;
        line-height:250px;
        height:250px!important;
        width:350px!important;
        text-align:center;
        margin:2px;
        }
        </style>

        <div class=”spjs_chartPlaceholder_master”></div>
        <script type=”text/javascript”>
        // Set this to true to load the Google Visualization API release candidate
        var loadRC = false;
        // Set this to true to allow for the use of variables in the “Filter setup textarea”
        var allowEval = true;
        </script>
        <script type=”text/javascript” src=”http://restricted.sharepoint/sites/SPJQ/jquery-1.11.3.min.js”></script&gt;
        <script type=”text/javascript” src=”https://www.google.com/jsapi”></script&gt;
        <script type=”text/javascript” src=”http://restricted.sharepoint/sites/SPJQ/spjs-charts-v4.14_min.js”></script&gt;

        <script type=”text/javascript”>
        function spjs_getFilterValue(list,field){
        var q = “<Where><IsNotNull><FieldRef Name=’ID’ /></IsNotNull></Where><OrderBy><FieldRef Name='”+field+”‘ /></OrderBy>”;
        var res = spjs.charts.qItems({“listName”:list,”query”:q,”viewFields”:[field]});
        var b = [];
        var fObj = {};
        b.push({‘f’:’All’,’v’:’*’});
        $.each(res.items,function(i,item){
        if(fObj[item[field]] === undefined && fObj[item[field]] == null){
        fObj[item[field]] = 1;
        if(item[field] == “QF”){
        b.push({“f”:”QF”,”v”:”QF”,”selected”: “true”});
        } else {
        b.push({“f”:””+item[field]+””,”v”:””+item[field]});
        }
        }
        });
        return b;
        }
        var myCustomFilterOptions = spjs_getFilterValue(“List_BF”,”DT”);
        </script>

        <script type=”text/javascript”>

        function spjs_chartSelectionHandler(chartID, selection, data) {
        var message, item, value, x, y, z, x1, x2;

        if (selection.length > 0) {
        item = selection[0];
        message = “”;
        value = “”;
        switch (chartID) {
        case ‘69743111-c1d0-4562-99e8-f72a85697457’:
        if (item.row !== null) {
        x = data.getFormattedValue(item.row, 0);
        x = x.replace(” “, “%20”);
        x = x.replace(“,”, “%2C”);
        //console.log(x);
        if (item.column !== null) {
        z = data.getFormattedValue(item.row, item.column);
        //console.log(z);
        y = data.getColumnLabel(item.column);
        //console.log(y);
        }
        }
        if (x === undefined && y === undefined && z === undefined) {
        return;
        }
        if (confirm(“Open filtered list?”)) {
        window.open(‘http://restricted.sharepoint/***************************.aspx?&FilterField1=MOM&FilterValue1=&#8217; + x, ”, ‘width=1000’);
        return;
        }
        break;

        //case ‘b2bf592a-3c16-49dc-bae2-76d68b6e3d7a_0’:
        case ‘69743111-c1d0-4562-99e8-f72a85697457_0’:
        if (item.row !== null) {
        x2 = data.getFormattedValue(item.row, 2);
        x2 = x2.replace(” “, “%20”);
        x2 = x2.replace(“,”, “%2C”);
        //console.log(x2);

        if (x2 === undefined) {
        return;
        }
        }
        if (confirm(“Open filtered list?”)) {
        window.open(‘http://restricted.sharepoint/***************************.aspx?&FilterField1=Title&FilterValue1=&#8217; + x2, ”, ‘width=1000’);
        return;
        }
        break;
        default:
        if (item.row !== null && item.column !== null) {
        message = “{row:” + item.row + “,column:” + item.column + “,chart:” + chartID + “}”;
        value = data.getValue(item.row, item.column);
        if (message === “”) {
        message = “nothing”;
        }
        alert(“You selected ” + message + “, the value is: ” + value);
        }
        //console.log(“Chart selection not configured.”);
        break;
        }
        }
        }
        </script>

      • #8546
        Alexander Bautz
        Keymaster

          Sorry for not replying – There was a problem with notifications from the forum.

          Did you figure it out, or do you still need some guidance.

          Alexander

      Viewing 1 reply thread
      • You must be logged in to reply to this topic.