Hacking the default SPSS chart template

In SPSS charts, not every element of the chart is accessible through syntax. For example, the default chart background in all of the versions I have ever used is light grey, and this can not be specified in GPL graphing statements. Many of such elements are specified in chart template files (.sgt extension). Chart template files are just a specific text format organized using an xml tag structure. Below is an example scatterplot with the default chart template for version 19.

You can manually edit graphics and save chart templates, but here I am going to show some example changes I have made in the default chart template. I do this because when you save chart templates by manually editing charts, SPSS has defaults for many different types of charts (one example when it changes are if the axes are categorical or numeric). So it is easier to make widespread changes by editing the main chart template.

The subsequent examples were constructed from a chart template originally from version 17, and I will demonstrate 3 changes I have made to my own chart template.

1) Change the background color from grey to transparent.
2) Make light grey, dashed gridlines the default.
3) Change the font.

Here I just copied and saved my own version of the template renamed in the same folder. You can then open up the files in any text editor. I use Notepad++, and it has a nice default plug-in that allows me to compare the original template file with my updated file. Moving on to how to actually make changes.

1) Change the background color.

The original chart color (in RGB hexidecimal code) is "F0F0F0" (you can open up a default chart to see the decimal representation, 240-240-240). Then I just used this online tool to convert the decimal to hexidecimal, and then you can search the template for this color. The background color is only located in one place in the template file, in a tag nested within an tag. I changed "F0F0F0" to "transparent" as oppossed to another RGB color. One might want to use white for the background as well ("FFFFFF").

2) Make light grey, dashed gridlines the default

Sometimes I can’t figure out how to exactly edit the original template to give me what I want. One way to get the “right” code is to manually apply the edits within the output, and save the chart template file to demonstrate how specific tag elements are structured. To get the gridlines I did this, and figured out that I needed to insert a set of tag with my wanted aesthetic specifications within the tag (that is within a tag). So, in my original chart template file the code was;

and below is what I inserted;

I then inserted the gridlines tag within all of the tags (you have several for different axis’s and whether the axis’s are cateogorical or numeric).

3) Change the font

This one was really easy to change. The default font is Sans-Serif. I just searched the file for Serif, and it is only located within one place, within a tag nested within an tag (near, but not within, the same place as the bacground color). Just change the "SansSerif" text to whatever you prefer, for example "Calibri". I don’t know what fonts are valid (if it is dependent on your system or on what is available in SPSS).

Here is what the same scatterplot at the beginning of the post looks like with my updated chart template.

Besides this my only other advice is combing through the original chart template and using trial and error to change items. For example, for many bar charts the default RGB color is tan (D3CE97). You can change that to whatever you want by just doing a find and replace of that hexidecimal code with another valid hexidecimal color code (like BEBEBE for light grey).

These changes are all arbitrary and are just based on personal preference, but should be enlightening as to how to make such modifications. Other ones I suspect people may be interested in are the default color or other aesthetic schemes (such as point shapes). These are located at the end of my original chart template file within the tags. One for instance could change the default colors to be more printer friendly. It would be easier to save a set of different templates for color schemes (either categorical or continuous) than doing the map statements within GPL all the time (although you would need to have your categories ordered appropriately). Other things you can change are the font sizes, text alignment, plot margins, default pixel size for charts, and probably a bunch of other stuff I don’t know about.

I’ve saved my current chart template file at this Google code site for anyone to peruse (for an updated version see here). I’ve made a few more changes than I’ve listed here, but not many. Let me know in the comments if you have any examples of changing elements in your chart template file!

Below is some quick code that sets the chart templates to the file I made and produces the above scatterplots.

*original template location.
FILE HANDLE orig_temp /name = "C:\Program Files\IBM\SPSS\Statistics\19\template\".
*updated template location.
FILE HANDLE update_temp /name = "E:\BLOG\SPSS\GRAPHS\Hacking_Chart_Template\".
*making fake, data, 100 cases.
input program.
loop #i = 1 to 100.
compute V1 = RV.NORM(0,1).
compute V2 = RV.NORM(0,1).
end case.
end loop.
end file.
end input program.
*original template.
SET CTemplate='orig_temp\chart_style.sgt'.
SOURCE: s=userSource(id("graphdataset"))
DATA: V1=col(source(s), name("V1"))
DATA: V2=col(source(s), name("V2"))
GUIDE: axis(dim(1), label("V1"))
GUIDE: axis(dim(2), label("V2"))
ELEMENT: point(position(V1*V2))
*My updated template.
SET CTemplate='update_temp\chart_style(AndyUpdate).sgt'.
SOURCE: s=userSource(id("graphdataset"))
DATA: V1=col(source(s), name("V1"))
DATA: V2=col(source(s), name("V2"))
GUIDE: axis(dim(1), label("V1"))
GUIDE: axis(dim(2), label("V2"))
ELEMENT: point(position(V1*V2))

Leave a comment


  1. Don’t forget that some of these changes such as the default font, marker, and graphic element color can be made systemwide via Edit>Options>Charts. You can also designate alternate templates in that panel. But having the default and other templates in xml makes it easy or at least easier to make the kinds of changes you discuss.

    Jon Peck

  2. Markus

     /  February 10, 2015

    Dear Andrew!

    This is of enormous help! Thanks!

    I would be interested to fix the x tick and y tick labels at Arial 16 pt, in order to have it nicely visible. The Arial is easy when following your description. But could you point me to the place where the 16pt need to be? I have exchanged all 11pt in your file, but no change was visible…

    Thanks in advance!

  3. Mike

     /  May 7, 2015

    Chart templates have been bumming me out. I have been using SPSS curve estimation and using the save chart template option to apply to multiple charts that are similar with scatter plot of observations, linear, quadratic and cubic line fits. When I fix up one chart to the way I like, save it as a chart template and then attempt to apply the chart to others nothing happens at all. It only works if I save the reference line data for a single chart (which will have totally difference linear, quadratic and cubic line fits to the charts I am trying to apply them to). What a bunch of ****. I’ll try your method.

    • Yeah they can be difficult to work with. If I want to use a template in addition to the default, I try to make it as minimal as possible. But it is hard because of the lack of documentation.

  4. Hi Andrew – Love this page and happy to find a fellow XML hacker-about.

    I am having a weird issue with the setAxisMargin tag in my sgt files — it doesn’t seem to do anything!

    I have been trying to modify the margin for my clustered horizontal bar charts, but no change I make to the XML setting seems to have any effect on the output. Consequently, the value labels (positioned positive/outside) are sometimes lopped off on the longest data bar in a chart.

    Any thoughts? I really don’t relish modifying the margins by hand for every chart of this type.

    • If you got that far not sure if I can give much helpful advice. (I have also found all sorts of things do not behave as expected, and sometimes change behavior in different versions.)

      My tags for that look like (hopefully HTML does not eat it):

      and a bunch of those tags for different categorical true/false and role (x,y,x2,y2). It is also specified at the beginning of my sgt file (some things seem to take precedence if they are specified in different order in the sgt file, so experiment with the order).

      About the only other piece of advice I can think to give is that I am not 100% sure of what is exactly cut off in your chart. For long labels you can sometimes insert line breaks into the string via “\n”, so it may be the best solution is to script up something to prevent really long strings for labels here, and not worry about putzing with the finicky sgt file.

      • Thanks! The html monster did eat whatever you were trying to share, but I saw the setAxisMargin lines in your template file, so I can riff on those — perhaps mine needs some combination of axis characteristics other than the obvious one (categorical FALSE role Y) — I’ll try popping some other lines in as well.

        I’ve tried different positions, nothing changed, but I’ll pop the new set to the top just in case.

        Again, thanks!

  5. Jim Flewelling

     /  June 21, 2021

    Very helpful post! Is there any way to take a Chart Template, and have SPSS show the equivalent GPL code? Your comment on GPL not being able to change the background color suggests that this is unlikely. Thanks

    • It isn’t a perfect separation, but they mostly do different things. The GPL deals with the actual data in the chart, whereas the template deals with visual aspects of the chart (such as fonts, background color, etc.) And the template typically does not contain the data itself, so there wouldn’t be anything to reverse engineer.

  1. Bean plots in SPSS « Andrew Wheeler
  2. Visualization techniques for large N scatterplots in SPSS « Andrew Wheeler
  3. My experience blogging in 2012 « Andrew Wheeler
  4. My Blogging in Review in 2013 | Andrew Wheeler
  5. Labeling tricks in SPSS plots | Andrew Wheeler
  6. The Junk Charts Challenge: Remaking a great line chart in SPSS | Andrew Wheeler
  7. Blogging in review 2015 | Andrew Wheeler
  8. Updated SPSS Chart Template (V26) and Chart Notes | Andrew Wheeler

Leave a Reply to Markus Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: