Archive
Highlighted

Sparkline Format

Engager

Hello

Does anyone know of a way to change the default line format on a Sparkline eg from the default line to bar.

I can change the format by altering the JS file directly.

I was wondering if it can be changed via the advanced XML.

On the simpleResultsTable module there is the following reference but i am not sure how to use it.

FieldFormats

Override presentation options for specific fields. This is currently used to specify display options for sparklines.

Default value: none

Thanks in Advance

Deacon

Highlighted

Re: Sparkline Format

Splunk Employee
Splunk Employee

You can pass options to the sparkline renderer from both simple and advanced xml.

For example, to simply render the sparklines as bar charts in simple XML you can use the following (assuming your sparkline field is called "sparkline" as it is by default):

<?xml version='1.0' encoding='utf-8'?>
<dashboard>
  <label>Sample sparkline table</label>
  <row>
    <table>
      <searchName>a saved search with sparklines</searchName>
      <title>sparklines</title>
      <format field="sparkline" type="sparkline">
        <option name="type">bar</option>
      </format>
    </table>
  </row>
</dashboard>

Most options listed in the jQuery Sparkline documentation can be passed to the format tag so colours, sizes, scale options, etc can all be controlled. Compound settings for options like colour maps can also be supplied using list or option sub-tags (which can be nested if required).

Eg to set the default bar colour to green and to make bars between 5 and 9 yellow and values of 10 and higher red:

<format field="sparkline" type="sparkline">
  <option name="type">bar</option>
  <option name="barColor">green</option>
  <option name="colorMap">
    <option name="5:9">yellow</option>
    <option name="10:">red</option>
  </option>
</format>

Or to specify a list of colours to apply to values in sequence:

<format field="sparkline" type="sparkline">
  <option name="type">bar</option>
  <option name="barColor">green</option>
  <option name="colorMap">
    <list>blue</list>
    <list>yellow</list>
    <list>red</list>
  </option>
</format> 

Generally its better to use hex colours instead of names (eg. "#ce1a1d" instead of "red") as they will then highlight when moused over, but not required. The sparklines home page has a "try it now" tool that can be used to come up with pleasing values or play with other options.

View solution in original post

Highlighted

Re: Sparkline Format

Engager

Thanks Gareth

Just what I needed thanks again for your assistance

Regards

Deacon

0 Karma
Highlighted

Re: Sparkline Format

Path Finder

Wow! I never would have guessed to use list for a series of colors. Thank you so much.

0 Karma
Highlighted

Re: Sparkline Format

Explorer

For anyone trying to do this in advanced XML:

Do it in simple XML, then load the page with a "?showsource=true" query param on the end. At the bottom of that page you can see the simple XML converted to advanced XML.

Highlighted

Re: Sparkline Format

Communicator

This helped me - thanks for the suggestion. I added the advanced XML output for others to reference below...

0 Karma
Highlighted

Re: Sparkline Format

Communicator

Here is the example of formatting a Sparkline field in Advanced XML for those not wanting to have to create a disposable dashboard then convert it to Advanced XML...

   <module name="SimpleResultsTable">
        <param name="fieldFormats">
            <param name="sparkline">
              <list>
                <param name="options">
                  <param name="barColor">green</param>
                  <param name="height">30</param>
                  <param name="colorMap">
                    <param name="10:">red</param>
                    <param name="5:9">yellow</param>
                  </param>
                  <param name="type">bar</param>
                </param>
                <param name="type">sparkline</param>
              </list>
            </param>
          </param>
       </module>
Highlighted

Re: Sparkline Format

Communicator

I tried sparkline for capturing server status. For Green, I could see the bar. But for red, I could see only dotted lines.. what could be the issue..? can some on please help?

0 Karma