Applying a Style to a Graph

The Graph bean includes several different styles, which you can apply to change the appearance of the graph. A style is a collection of property settings. The Graph bean defines several styles. These styles are defined in the JAR file for the Graph bean, in the oracle/dss/graph/styles folder.

Styles are defined in XML files. When you apply a style, the graph reads the XML file and sets its properties from attribute settings in the XML. In general, the style properties are those that affect the appearance of the graph and that are not tied to data. For example, the FillColor property settings for the graph background, plot area, and for the markers in different series are included in graph styles. Line colors and font sizes are also included in styles. Axis end points, which depend on the data that appears in the graph, are not included in the styles.

If you set a style property and then apply a style, then the style overrides the property that you set. If you set the property after you apply a style, then the property setting takes effect, overriding any settings for that property in the style XML.

The easiest way to apply a style is to use the Graph Style panel in JDeveloper. To set a style programmatically, call the setStylePath method of the graph, as shown in the example in this topic.

Example: Applying the Earth style to a graph

The following code applies the Earth style to a graph.


Graph graph = new Graph(); //setting a style property here has no effect graph.getPlotArea().setFillColor(Color.pink); try{ graph.setStylePath("/oracle/dss/graph/styles/earth.xml"); } catch (BIIOException biioex){ System.out.println("BIIOException"); biioex.printStackTrace(); } catch (BISAXException bisaxex){ System.out.println("BISAXException"); bisaxex.printStackTrace(); } catch(BIParseException bipex){ System.out.println("BIParseException"); bipex.printStackTrace(); } catch(IOException ioex){ System.out.println("IOException"); ioex.printStackTrace(); } //setting a style property here does have an effect graph.getY1MajorTick().setColor(Color.pink);