Splunk Search

When I am adding panels and chart elements using JavaScript, why am I not able to edit panels?

Nisarg
New Member

When I click on Edit->Edit panels, It suddenly hides from the dashboard.

My code to add panels using javascript is as below:

var panel = mvc.Components.get('dashboard').createNewPanel();
var element1 = new ChartElement({
    "id": "element"+id,
    "managerid": "customsearch-"+id,
    "charting.drilldown": "all",
    "charting.chart": "line",
    "charting.chart.nullValueMode": "gaps",
    "charting.chart.sliceCollapsingThreshold": "0.01",
    "charting.layout.splitSeries": "0",
    "charting.axisTitleX.visibility": "visible",
    "charting.chart.style": "shiny",
    "charting.legend.labelStyle.overflowMode": "ellipsisMiddle",
    "charting.axisTitleY.visibility": "visible",
    "charting.axisX.scale": "linear",
    "charting.axisY.scale": "linear",
    "charting.legend.placement": "right",
    "resizable": true,
    //"el": $('#element'+id),
    "height": 250,
    "width": 250
});//.render();
panel.addChild(element1);
element1.render();
0 Karma

jeffland
SplunkTrust
SplunkTrust

I'd say using your method is completely ok, but you should be aware of what you're doing there. For one thing, you're no longer adding Splunkjs Stack Views to your dashboard, i.e. you're not using a ChartView. Instead, you're using the Simple XML Wrapper ChartElement (the same that is used in dashboards once converted to html, see here and here).

I'm surprised you still see the "Edit -> Edit Panels" option. It should only be available as long as there are strictly views on your dashboards, without any wrappers. As soon as you use those, the function "Edit Panels" offers is no longer applicable (because your views are no longer views, they are now elements with their own settings which you can't edit from the web view) and thus should not be displayed any more. Therefore, I'd say it is expected behavior that your elements disappear when you enter the "Edit Panels" mode - they do not correspond to the settings you set there.

Maybe you can find another way to solve your initial problem (adding panels dynamically). Did you know about the depends attribute of panels? They allow you to hide views based on the presence of tokens, see here for docs (search for depends). Alternatively, you could look into the inner workings of the web framework at %SPLUNK_BASE/share/splunk/search_mrsparkle/exposed/js/splunkjs/mvc (and subfolders) and from there figure out how to add your elements to the model of the dashboard so that they are editable from "Edit Panels" - unfortunately, for specific help on what exactly you need to do there you'll have to ask someone really knowledgeable about it, e.g. on the IRC channel.

Good Luck!

Nisarg
New Member

Just to clarify, default behavior of Splunk is not a problem. It lets me create panels and let me modify it using Edit->edit panels. But I have a requirement in my app, where I need to add panels dynamically based on user's input. So I used the above code in my own javascript so that when user selects some parameters from my fieldset in XML, I pass that to my javascript and use the above code to add panels to my dashboard.

Is it ok to use Splunk's internal MVC framework in our own javascript for doing some custom operation?

Thanks
Nisarg

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...