By now, we have seen that we can make minor changes to the Simple XML to create eye-catching visualizations of our data. We have also added JavaScript to our Splunk App to help us with our dashboard layouts. In the next section, we will also start to add CSS to help our JavaScript further manipulate the layout of our interface.
It may seem a little counter-productive, but we are going to duplicate the Cell Count Ranges chart that we just created. The reason behind this is that we want to show how we can provide the same data, and not just in a different format. We will combine a table and a chart using JavaScript and CSS. Although we are going to add some JavaScript and CSS, we are going to keep things pretty simple, so don't be too worried. In the following code, we are going to do this:
cd $SPLUNK_HOME/etc/apps/cell_biology/appserver/static
cell_layout.js
file with a text editor and move to the bottom of the file, as we are going to add another function to our code. We need a few more libraries in this function, so we are going to load them across multiple lines:8 require([ 9 'jquery', 10 'underscore', 11 'splunkjs/mvc', 12 'views/shared/results_table/renderers/ BaseCellRenderer', 13 'splunkjs/mvc/simplexml/ready!'
BaseCellRenderer
library, as this will be the library we will use to change the way our table displays.require
statement, and in this case we will also add the options of the libraries that we are going to extend:14 ], function($, _, mvc, BaseCellRenderer) {
BaseCellRenderer
library, specifically looking for the percent
field, which is going to be set up in our Simple XML table:15 var DataBarCellRenderer = BaseCellRenderer.extend({ 16 canRender: function(cell) { 17 return (cell.field === 'percent'); 18 },
data-bar-cell
) to the table cell:19 render: function($td, cell) { 20 $td.addClass('data-bar-cell').html(_.template('<div class="data-bar-wrapper"><div class="data-bar" style="width:<%- percent %>%"></div></div>', { 21 percent: Math.min(Math.max(parseFloat(cell.value), 0), 100) 22 })); 23 } 24 });
mvc
library is then used to run through the components of our dashboard, specifically the table with the id
of tableWithBar1
, which we will add to our Simple XML shortly:25 mvc.Components.get('tableWithBar1') .getVisualization(function(tableView) { 26 tableView.addCellRenderer(new DataBarCellRenderer()); 27 }); 28 });
cell_layout.css
. Add the following code, which will provide us with padding for the cell, height, width and background color of the bar chart in our table:1 td.data-bar-cell { 2 padding: 4px 8px; 3 } 4 td.data-bar-cell .data-bar-wrapper .data-bar { 5 height: 16px; 6 min-width: 1px; 7 background-color: #5479AF; 8 }
cell_counts.xml
. Start by changing the first line to include the new JavaScript and CSS files that we are using:1 <dashboard script="cell_layout.js" stylesheet="cell_layout.css" >
id
that we created in our JavaScript file called tableWithBar1
:62 <row> 63 <panel> 64 <table id="tableWithBar1">
65 <title>More Cell Count Ranges</title> 66 <search>
67 <query><![CDATA[index=main sourcetype=cellsimulation | eval data=_raw | rex field=data max_match=0 "(?<cells>@)" | stats count(cells) AS Count by _time | eval description=case(Count<=10 , "LOW", Count<=20, "MEDIUM", Count>20 , "HIGH") | top description ]]> </query>
search
, table
, panel
, and row
, and finally close off the entire dashboard with the ending dashboard element that we removed earlier:68 </search> 69 </table> 70 </panel> 71 </row> 72 </dashboard>
18.118.1.158