Dashboards & Visualizations

Can one dynamically set 'managerid' value in a given ChartView?

pgoldweic
Communicator

In an app outside of Splunk that uses the splunkjs stack, I have a default view that displays a few visualizations that use PostProcessSearchManagers within ChartView instances. These panels display reasonably fast, since they're using saved searches.

However, I'm also being asked to provide an optional time range widget, which, if used to select a particular time range, will 'convert' all the previous panels to use the given time range in the query (instead of the saved searches, which do not take time ranges).

It occurred to me that I could possibly do this if I dynamically set the 'managerid' value in one of the original ChartView instances to a particular SearchManager (which I'd also define, and would not depend on the saved search). However, is this even possible?
If not, how can I achieve this goal? (of (re) charting the results of a 'regular' search instead of those of a 'saved + post process search', in one of my ChartView instances).

0 Karma
1 Solution

pgoldweic
Communicator

OK, I finally resolved the problem partially using one of the suggestions by @gaurav_maniar (thanks again for providing that answer) . The solution for me was to use the following syntax for updating the parameter in charview:

chart.settings.set("managerid","new_value");

instead of using:

chart.set("managerid", "new_value");

as suggested in the reply.

View solution in original post

pgoldweic
Communicator

OK, I finally resolved the problem partially using one of the suggestions by @gaurav_maniar (thanks again for providing that answer) . The solution for me was to use the following syntax for updating the parameter in charview:

chart.settings.set("managerid","new_value");

instead of using:

chart.set("managerid", "new_value");

as suggested in the reply.

woodcock
Esteemed Legend

OK, come back and click Accept on your answer to close the question.

0 Karma

gaurav_maniar
Builder

Hi @pgoldweic,

If you can provide the code sample and exactly than it would be better.
Check the below solution for your issues,

  • you can change time range of saved searches

    var savedsearch = new SavedSearchManager({
    id: "example-saved-report",
    searchname: "Report - Top Pageview",
    cache: true,
    preview: true,
    "dispatch.earliest_time": "-24h@h",
    "dispatch.latest_time": "now",
    app: "search"
    });
    Now if you want to change the timerange,

    savedsearch.set("dispatch.earliest_time","new_value");
    savedsearch.set("dispatch.latest","new_value");
    Now, the same way you can change any parameter in manager, and change managerid in ChartView as well.

    var chart = new ChartView({
    id: "example-saved-report",
    managerid: "mysearch1",
    type: "line",
    data: "preview",
    el: $("#previewchart")
    }).render();

    chart.set("managerid", "new_value");
    If you are updating any parameter in manager, call the startSearch() function.
    Or if your updating any parameter in chartview, call the render() function

Accept & up-vote the answer if it helps.

pgoldweic
Communicator

Thanks for replying!. A couple of comments regarding your suggestions:
1- I have already tried calling render() on the charview after making re-setting its 'managerid' but nothing happens on the screen unfortunately, so your second suggestions does not appear to work well (or is incomplete perhaps?)

2- In terms of updating the time range of the saved search, I'm somewhat confused as to why you'd be able to do this, given that the search represents a report (which, in my understanding, won't even accept a time-range picker when you create it, by nature of being a report -so the time is fixed to whatever you chose at creation time-). So I concluded logically that you should not, in fact, be able to change the time range on a saved search. I could certainly try this out, and perhaps I'd be nicely surprised if it works though :-).

0 Karma

pgoldweic
Communicator

More on (2) above: my desired goal, as stated, is not to change the time range of a saved search (note that this would have undesirable consequences, as stated in the answer to https://answers.splunk.com/answers/562526/changing-time-range-in-saved-report-utilized-in-da.html), but also would not work well for my case because my saved searches are very expensive, since they span a large subset of events, so it would be totally impractical to run one of those searches in real time. However, I can create a more targeted real time search that depends on a newly selected time range, so it is in fact to my advantage to use a plain search manager with a real-time search associated with it, and not try to mess up with the expensive saved searches. Hope this makes some sense.
So, I still need a way to switch search managers dynamically within a given chart. Would be great if your second suggestion worked well, but as indicated earlier, it did not work for me :-(.

0 Karma
Get Updates on the Splunk Community!

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...