Search XML Attributes PowerShell XPath

In this Powershell tutorial on XML, we will discuss how to search XML and extract specific nodes, by searching XML attributes. We will use the select-Xml cmdlet for doing this, however the XPath query would be at an attribute level. Using the examples provided in this tutorial, you should be able to easily query XML data in Powershell and use the output values.

1.Input XML with Attributes


Use the following input XML for this tutorial
<Details>
        <department count="10">
                <ID>10</ID>
                <dname>Administration</dname>
                <manager>200</manager>
                <location>1700</location>
                <revenue>77</revenue>
        </department>
        <department count="20">
                <ID>20</ID>
                <dname>Marketing</dname>
                <manager>201</manager>
                <location>1800</location>
                <revenue>50</revenue>
        </department>
</Details>


2.  Load the XML in PowerShell


We will load the XML directly in PowerShell as shown in the illustration below:
PS C:\> $xml_attributes=@"
>> <Details>
>>     <department count="10">
>>         <ID>10</ID>
>>         <dname>Administration</dname>
>>         <manager>200</manager>
>>         <location>1700</location>
>>         <revenue>77</revenue>
>>     </department>
>>     <department count="20">
>>         <ID>20</ID>
>>         <dname>Marketing</dname>
>>         <manager>201</manager>
>>         <location>1800</location>
>>         <revenue>50</revenue>
>>     </department>
>> </Details>
>> "@
>>
PS C:\>

The variable xml_attributes contains the XML data that we can search upon using select-Xml cmdlet.

3. Search XML by Attributes in PowerShell - XPath


If you want to list all the "count" attribute values as an example, you can do this as per the command below.
C:\>powershell
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\> Select-Xml -Content $xml_attributes -XPath '//@count' | foreach {$_.node
}

#text
-----
10
20

Here, we use '//' to directly query the XML attribute and use the 'foreach' statement to print the value in Powershell.

4.List XML Nodes Matching Attribute Value - Example


In this case, the requirement is to list all the department details where the count matches 10. You can do this easily by matching the attribute value to 10 in the XPath and printing the output. The Powershell command to do this is provided below:
PS C:\> Select-Xml -Content $xml_attributes -XPath '//department[@count="10"]' |
 foreach {$_.node}


count    : 10
ID       : 10
dname    : Administration
manager  : 200
location : 1700
revenue  : 77

Once you know how to search attributes, it will be a cakewalk for you to extend this to any complex XMLs. Hope you liked this powershell tip. If you are stuck, post us your XML and question, we will solve it for you.

Powershell Search XML Attributes Example - Part 3

We have been discussing about the Search-Xml cmdlet in depth so far, and in this part of the series, we will see some more advanced XPath examples in Powershell. When you run through these, you will appreciate the great flexibility that you have in this command line utility to search and process XML data. We will be using a slightly different XML for this example, one with attributes. So you need to change your input XML and load it in Powershell to use the examples below.

PowerShell - Input XML for Search


We will use the sample XML as shown below. This XML has attribute information injected. I have reduced the number of "department" nodes to keep things easy.
<Details>
        <department count="10">
                <ID>10</ID>
                <dname>Administration</dname>
                <manager>200</manager>
                <location>1700</location>
                <revenue>77</revenue>
        </department>
        <department count="20">
                <ID>20</ID>
                <dname>Marketing</dname>
                <manager>201</manager>
                <location>1800</location>
                <revenue>50</revenue>
        </department>
</Details>

Advanced XML XPath Search Examples - PowerShell


I have not covered loading of this XML in powershell. If you are jumping straight from the internet, make sure you read part 1 of the tutorial here. Our requirement is to select "dname" where revenue is greater than 70. Here is how you can do this using Powershell.
PS C:\> Select-Xml -Content $xmltest -XPath '/Details/department/dname [../revenue>70]'

Node                       Path                       Pattern
----                       ----                       -------
dname                      InputStream                /Details/department/dn...


PS C:\> Select-Xml -Content $xmltest -XPath '/Details/department/dname [../reven
ue>70]'| foreach {$_.node}

#text
-----
Administration

In first case, marked in green, we get an object returned back. In the second case, we use "foreach" to get the actual dname value. We use ".." during our search on the XML to go one level up and search for the revenue node under "department".

Using AND logic in XPath to Query XML in PowerShell


We will now run a simple example to select the complete node where manager is greater than 200 and revenue is greater than 70. This is a composite AND logic that we need to use in the XPath in PowerShell. Here is how you can do this. The output for the same input XML user earlier is also provided below:

PS C:\> Select-Xml -Content $xmltest -XPath '/Details/department[manager >= 200
and revenue>70]'| foreach {$_.node}


count    : 10
ID       : 10
dname    : Administration
manager  : 200
location : 1700
revenue  : 77

You can also get a single tag value for this case, but following the example earlier. That completes part 3 of the XPath tutorial in PowerShell. This is getting interesting now. We will cover more XML search capabilities in Powershell in the next part of this series. Stay Connected.

PowerShell XML XPath Examples - 2

In the last article, we gave a simple introduction on Select-XML cmdlet  and its importance in querying XML data in Powershell. We explained this cmdlet with basic XPath example, with our sample XML. 

This tutorial focuses on some advanced examples of this cmdlet. We will use the same XML that we used in the last scenario. So, make sure you have a copy of the XML and you have loaded the XML in Powershell. You may not get the right results if you have not loaded the XML properly. So, make sure you follow the steps right. We will see two more interesting ways to use Select-XML cmdlet in this post.

Select-Xml Query Specific Node in PowerShell


In the previous example, we managed to get all the values listed by using foreach cmdlet. That throws an interesting question. How to get all department name (dname) in the XML as a list, instead of getting the full set of values? Is there a way this can be done using Select-Xml cmdlet? The simple answer is yes. And doing this is much simpler. Here the code fragment that selects only the “dname” tag across the full XML:
PS C:\> Select-Xml -Content $xmltest -XPath /Details/department|
>> foreach {$_.node.dname }
>>
Administration
Marketing
Purchasing
Human Resources
Shipping
PS C:\>

As expected, we were able to select specific node name across the full XML in the output. Handy!.

XML – Add Where Clause in PowerShell – Where-Object Cmdlet


We are going to discuss an advanced option here. How to get all the nodes in the XML where the revenue is greater than 50, in PowerShell? You can do this easily by using Where-Object cmdlet in PowerShell. Note that if you are a super fluent XPath user, you can do this in XPath itself. We will show both the methods now.

Option 1: Using Where-Object Cmdlet – Example

The syntax and an example output is provided below: [ “where” clause is highlighted in yellow. We check if revenue is greater than 50 by using –gt tag.

PS C:\> Select-Xml -Content $xmltest -XPath /Details/department|
>> foreach {$_.node} | where { [double] ($_.revenue) -gt 50 }
>>


ID       : 10
dname    : Administration
manager  : 200
location : 1700
revenue  : 77

ID       : 30
dname    : Purchasing
manager  : 114
location : 1700
revenue  : 68

Option 2: Using XPath in PowerShell

You can also get the same output by framing your XPath bit more smartly. Here is how to get the same result in XPath. Note that we have put the condition directly in the XPath in this example.
PS C:\> Select-Xml -Content $xmltest `
>> -XPath '/Details/department[revenue >50 ]' |
>> foreach {$_.node}
>>


ID       : 10
dname    : Administration
manager  : 200
location : 1700
revenue  : 77

ID       : 30
dname    : Purchasing
manager  : 114
location : 1700
revenue  : 68

That completes part 2 of the tutorial on Select-XML cmdlet in Powershell. We introduced you to some advanced data selection methods in Powershell to query XML data. In the next example, we will discuss some more data extract approaches.  Meanwhile, if you have a question on the samples provided here, post it as a comment back to us.

PowerShell Select-Xml Cmdlet XPath Example

In this example, we are going to explain how to select data from XML over an XPATH in PowerShell with some basic examples. We have discussed how to read XML data in Powershell, print data on the screen and update XML data earlier. XPATH gives an administrator more power to apply conditional logic on XML and select specific data that you are searching for. We will use Select-XML cmdlet to query XML and will provide some interesting examples as we move on this tutorial.

The test XML that we will use for the XPATH query in Powershell is provided below:

Search XML – PowerShell Xpath Example


<Details>
        <department>
                <ID>10</ID>
                <dname>Administration</dname>
                <manager>200</manager>
                <location>1700</location>
                <revenue>77</revenue>
        </department>
        <department>
                <ID>20</ID>
                <dname>Marketing</dname>
                <manager>201</manager>
                <location>1800</location>
                <revenue>50</revenue>
        </department>
        <department>
                <ID>30</ID>
                <dname>Purchasing</dname>
                <manager>114</manager>
                <location>1700</location>
                <revenue>68</revenue>
        </department>
        <department>
                <ID>40</ID>
                <dname>Human Resources</dname>
                <manager>203</manager>
                <location>2400</location>
                <revenue>30</revenue>
        </department>
        <department>
                <ID>50</ID>
                <dname>Shipping</dname>
                <manager>121</manager>
                <location>1500</location>
                <revenue>37</revenue>
        </department>
</Details>


Load XML Data into a PowerShell Variable


The second step is to load the XML into a powershell variable. This is done using the command as shown below:

PS C:\> $xpath_example=[xml] (Get-Content  c:\test.xml)
PS C:\> $xpath_example

Details
-------
Details



Using Select-XML cmdlet in PowerShell


We are now ready to use Select-XML cmdlet and query the XML we just loaded in Powershell. To select the first “department” node in Powershell and XPATH, you run a command like the one shown below:

PS C:\> (Select-Xml -Content $xmltest -XPath /Details/department)[0].Node


ID       : 10
dname    : Administration
manager  : 200
location : 1700
revenue  : 77

This command extracts the values of the first node, with the XPath you have provided and dumps the result back to the screen.


Using Select-XML to select all the Nodes of XML in PowerShell


If you want to select all the nodes under Details, and print them in the output, you cannot repeat the command we saw above with repeating node numbers. One way to do this would be to pipe the output of Select-XML to a “foreach” cmdlet. This is illustrated below:

PS C:\> Select-Xml -Content $xmltest -XPath /Details/department|
>> foreach {$_.node }
>>


ID       : 10
dname    : Administration
manager  : 200
location : 1700
revenue  : 77

ID       : 20
dname    : Marketing
manager  : 201
location : 1800
revenue  : 50

ID       : 30
dname    : Purchasing
manager  : 114
location : 1700
revenue  : 68

ID       : 40
dname    : Human Resources
manager  : 203
location : 2400
revenue  : 30

ID       : 50
dname    : Shipping
manager  : 121
location : 1500
revenue  : 37

This should give you a very good introduction in using Powershell to query XML with XPATH expressions. We will see some more complex XPATH examples to select XML data in the next post.

JFreeChart Chart Width Superscript Kerning Example

This is the last set in the tutorial series on formatting chart titles in JFreeChart API using Java. We have been discussing most of the formatting options in length so far, and we will cover a few other things in this tutorial. The options we will be covering in this tutorial are listed below:

1) Extending the width of Chart Title
2) Superscript based chart titles
3) Kerning of chart title text
4) Combining multiple attributes into Chart title


Extended width for Chart title


You can have an extended width on the chart title by using the attribute WIDTH with a value WIDTH_EXTENDED. An example code and the output you get on the chart title in this case is provided below

Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
map.put(TextAttribute.WIDTH, TextAttribute.WIDTH_EXTENDED);
TextTitle my_Chart_title=new TextTitle("Chart Title with Extended Width", new Font (map));
BarChartObject.setTitle(my_Chart_title);

JFreeChart - Chart Title-Extended Width - Example Output
JFreeChart - Chart Title-Extended Width - Example Output
And, WIDTH_CONDENSED on the same line will give you a condensed version of the title. Here is a code fragment and output;

Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
map.put(TextAttribute.WIDTH, TextAttribute.WIDTH_CONDENSED);
TextTitle my_Chart_title=new TextTitle("Chart Title with Condensed Width", new Font (map));
BarChartObject.setTitle(my_Chart_title);

JFreeChart - Chart Title - Condensed Width - Example
JFreeChart - Chart Title - Condensed Width - Example

There are also options like SEMI_EXTENDED and SEMI_CONDENSED that provide a semi expanded and condensed version of the chart title respectively. Example code fragment and output are shown below
Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
map.put(TextAttribute.WIDTH, TextAttribute.WIDTH_SEMI_EXTENDED );
TextTitle my_Chart_title=new TextTitle("Chart Title with semi extended Width", new Font (map));
BarChartObject.setTitle(my_Chart_title);

JFreeChart - Chart Title - Semi Extended - Example
JFreeChart - Chart Title - Semi Extended - Example

Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
map.put(TextAttribute.WIDTH, TextAttribute.WIDTH_SEMI_CONDENSED );
TextTitle my_Chart_title=new TextTitle("Chart Title with semi condensed Width", new Font (map));
BarChartObject.setTitle(my_Chart_title);

JFreeChart - Chart Title - Semi Condensed width - Example
JFreeChart - Chart Title - Semi Condensed width - Example

Chart Title SuperScript Example


You can set the title to be of superscript type by using the code fragment below:
Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
map.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER);
TextTitle my_Chart_title=new TextTitle("Chart Title - Superscript example", new Font (map));
BarChartObject.setTitle(my_Chart_title);

You use SUPERSCRIPT property with a value of SUPERSCRIPT_SUPER for this purpose. A sample output is shown below

JFreeChart - Chart Title - Superscript Example
JFreeChart - Chart Title - Superscript Example

The core Java API is so powerful that the options are virtually unlimited. You can also combine multiple options instead of specifying only one at a time. A complete set of attributes that you can use to format your chart title is available in the Oracle Documentation.As a last leg to this tutorial series, we will provide an example to set kerning on the font. You can use the code as below for that. Output with and without kerning applied is shown below

Chart Title - Kerning Example


/* Modifying chart title in JFreeChart Examples*/               
Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
map.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
map.put(TextAttribute.SIZE, new Double("19.0"));
TextTitle my_Chart_title=new TextTitle("Chart Title - Kerning and Size example", new Font (map));
BarChartObject.setTitle(my_Chart_title);
  /* Modifying chart title in JFreeChart Examples*/

This example also illustrates how to set multiple font attributes against the title. We have set both SIZE and Kerning attributes in this case. The output produced with kerning is shown below:

JFreeChart - Kerning Example (Kerning ON)
JFreeChart - Kerning Example (Kerning ON)
The same code with Kerning turned off is provided below:

Chart Title without Kerning
Chart Title without Kerning
If you have a specific requirement towards chart title, that you want us to cover, post it in the comments section of this post. We will have a look.

JFreeChart Chart Title Bold Font Color Example

In the last tutorial, we discussed briefly on some of the chart formatting options in JFreeChart, that included underline / strikethrough of chart title. In this tutorial, we will focus on some more chart title formatting options. Precisely, we will be looking at the following chart title options:

1) Making Chart title bold
2) Changing the chart title foreground color
3) Changing the chart title background color
4) Modifying chart title posture

This is an extension of the previous tutorial. Please make sure you read that first before reading on. The previous tutorial describes some theory if you are keen to understand how different formatters work on the JFreechart library.

JFreeChart – Making Chart Title Bold


We have already seen how to bold chart title in JFreeChart. Here we describe one other way to make the chart title bold by using a different constructor in java.awt.Font class.  An example code fragment and the chart produced by the example is given below:
Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
map.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
TextTitle my_Chart_title=new TextTitle("Chart Title  Bold Title Font Example", new Font (map));
BarChartObject.setTitle(my_Chart_title);

JFreeChart-WEIGHT_BOLD-Example Output
JFreeChart-WEIGHT_BOLD-Example Output
Instead of specifying WEIGHT_BOLD, you can also specify the following, WEIGHT_DEMIBOLD, and this produces an output as provided below (this is a moderately ligher weight that WEIGHT_BOLD)
Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
map.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
TextTitle my_Chart_title=new TextTitle("Chart Title  DemiBold Title Font Example", new Font (map));
BarChartObject.setTitle(my_Chart_title);

JFreeChart - WEIGHT_DEMIBOLD-Example Output
JFreeChart - WEIGHT_DEMIBOLD-Example Output
If you want the heaviest bold value, you have to use WEIGHT_ULTRABOLD, an example is provided below:

JFreeChart - WEIGHT_ULTRABOLD-Example
JFreeChart - WEIGHT_ULTRABOLD-Example
There are also other options like WEIGHT_REGULAR, WEIGHT_MEDIUM, WEIGHT_LIGHT, WEIGHT_HEAVY, WEIGHT_EXTRABOLD, WEIGHT_EXTRA_LIGHT ..more than what you would require to set the weight on a chart title. You can try out all these options against your chart to see how it works.


JFreechart - Chart foreground and background colors on Title 


This one is interesting. You can change the chart title foreground and background colors by using FOREGROUND and BACKGROUND properties of TextAttribute class respectively. As an example, we are providing a code that sets chart title background to red, and foreground to white color.  The color you pass into the chart is of type java.awt.Paint. You can virtually set any color as your foreground and background.Code fragment and output is provided below:
Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
map.put(TextAttribute.BACKGROUND, Color.RED);
map.put(TextAttribute.FOREGROUND, Color.WHITE);
TextTitle my_Chart_title=new TextTitle("Chart Foreground and Background Title - Example", new Font (map));
BarChartObject.setTitle(my_Chart_title);


JFreeChart - Chart Title Foreground and background colors - Example
JFreeChart - Chart Foreground and background colors - Example

JFreeChart – chart posture example


You can change the chart title posture by using POSTURE property in TextAttribute class. Here is a code fragment that sets the posture to OBLIQUE, a sample output is also provided for this example.

Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
map.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
TextTitle my_Chart_title=new TextTitle("Chart Title Posture Example", new Font (map));
BarChartObject.setTitle(my_Chart_title);

JFreeChart - Chart Title Posture Example
JFreeChart - Chart Title Posture Example

That completes our third set of formatting options tutorial. We covered making chart title bold (with different options), changing chart foreground and background colors and changing chart posture in this post. We will cover some more formatting options in the next post. Stay connected.

JFreeChart Chart Title Underline StrikeThrough Example

We saw a quick introduction to chart title formatting options in the previous example. This tutorial is an extension of the previous one where we will cover more advanced chart title formatting options. We will discuss various options that are available in JFreechart for decorating your chart title with examples. It is good to learn that these customization options do exist for us on the chart, and keep these tricks in your backpack for ready usage. As per the earlier exercise, we are not going to provide full code program and you need to get it from our JDBC tutorial. The JAR files you require to run this example are unchanged from the previous one.

The base for this tutorial is from the setTitle method offered by org.jfree.chart.JFreeChart class, which can take an input of the type org.jfree.chart.title.TextTitle. You can send in a object of type java.awt.Font when you create a TextTitle object. That opens up a very wide range of formatting options that you can apply to the chart title.We will cover a few of them with code fragments in this section.

java.awt.Font - Format options


There exists a constructor in this class that can take a map of Font attributes. [ that belongs to java.awt.font.TextAttribute ] . We can set this map with the format options, that will in turn get applied to our chart. You will need to add the following import declarations to the class to get this working:
import java.awt.Font;
import java.util.Map;
import java.util.Hashtable;
import org.jfree.chart.title.TextTitle;
import java.awt.font.TextAttribute;
import java.awt.Color;

JFreeChart - How to underline chart title?


Use the following code fragment along with the main chart program, to underline the chart title.

                Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
                map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
                TextTitle my_Chart_title=new TextTitle("Chart Title - Underline Example", new Font (map));
                BarChartObject.setTitle(my_Chart_title);

This program produces a chart with title of the chart underlined. The output is shown below:

JFreeChart - Chart Title - Underline - Example
JFreeChart - Chart Title - Underline - Example
Different Underline Options

Instead of passing UNDERLINE_ON, you can pass the following also to get the outcome as listed below:


  • UNDERLINE_LOW_DASHED : chart underline of single pixel, dashed low.
  • UNDERLINE_LOW_DOTTED: dotted underline of chart title.
  • UNDERLINE_LOW_GRAY: Double pixel underline in the heading
You can also use UNDERLINE_LOW_ONE_PIXEL or UNDERLINE_LOW_TWO_PIXEL to get a single or double pixel solid underline output respectively.

JFreeChart - How to strike-through chart title?


If you want to strike-through the title of your chart (don't know why you want to do this), you can follow the code fragment listed below:

                Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
                map.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
                TextTitle my_Chart_title=new TextTitle("Chart Title  Strikethrough Example", new Font (map));
                BarChartObject.setTitle(my_Chart_title);


This code produces a chart title with strike through effect, as shown below

JFreeChart - Chart Title - Strike through Example
JFreeChart - Chart Title - Strike through Example
By default, strikethrough will be off. You can turn it off by using the code above if required.

That covers some of the formatting options available for chart title in JFreechart. In the next tutorial, we will cover some more examples of chart formatting that includes setting / changing kerning, posture, foreground color and background color. Stay connected for more on this shortly.

JFreeChart Chart Title setTitle Example Program

In this tutorial, we will explain how to add chart title to a chart using JFreechart, using example Java code. You may be wondering, what is there in a chart title. In plain simple language, it is a string added to JFreechart object. However, there is a wide range of customization options available for the chart title. You many not have a real requirement to customize chart title, but this exercise will give you a head start if you really want to do one. It is always good to know that such options are available for your chart, thanks to JFreechart, a very powerful library.

I'm going to split this tutorial into multiple parts and focus on two key options on chart title in this post. As we move on, I will be taking some complex customization options like vertical alignment of title etc. By default, a chart title is positioned at the top of the chart, in the middle. (we will cover alignment options also later). To execute the examples that I'm going to provide here, you will need the following JAR files:

  • jfreechart-1.0.14.jar
  • jcommon-1.0.17.jar
  • ojdbc6.jar
  • Base code from the tutorial, JDBC JFreeChart Example. We will discuss only modifications required.

JFreeChart - Available Methods to Modify Chart Title

If you refer to the API documentation, there are two methods available in org.jfree.chart.JFreeChart to modify chart title. Both methods carry the same name, setTitle. This method can take a plain string as input or an object of type org.jfree.chart.title.TextTitle (to be discussed in depth later). Let us discuss two options in this tutorial viz using plain string as title and specifying a title with a fixed font.

Plain string as Chart title

This is the most simple and basic approach. You call setTitle method directly be passing a string. The code example snippet is given below:

/* Modifying chart title in JFreeChart Examples*/
BarChartObject.setTitle("Title modified by setTitle method ");
/* Modifying chart title in JFreeChart Examples*/

The output chart produced by this approach is given below:
JFreeChart - setTitle Method - Example Output
JFreeChart - setTitle Method - Example Output

Specify a different font for Chart title

Now, the interesting part. How to specify a different font for Chart title? We need to set the specifications in the object org.jfree.chart.title.TextTitle and pass this object to setTitle method. The TextTitle class has multiple constructors. One of the constructor accepts chart tile as a string, and a font object of type java.awt.font. Wow, using java.awt.font opens up a plethora of customization options on the chart title for us. We are going to discuss all of them later. Simple things first. Here is an example to set chart title font to Verdana with size 17.
                TextTitle my_Chart_title=new TextTitle("Title With new Font", new Font ("Verdana", Font.PLAIN , 17));
                BarChartObject.setTitle(my_Chart_title);

We pass a Font object and specify three parameters. Type of font, which is a string and we say it is Verdana, style of the font - which is set to PLAIN and size of the font - which we set as 17. Simple. The output chart produced by this method is given below.

JFreeChart - Chart Title with Custom Font Example
JFreeChart - Chart Title with Custom Font Example

That closes this part of the tutorial. It is not done yet. In the next part of this tutorial, we are going to discuss how to customize the title even further. Make the title bold, italic and so on. The easiest way to make sure you don't miss a tutorial is to subscribe to our blog. Stay connected for another example, on your way soon.