skip to main content
Charts > Programmer's documentation > Developing with the JViews Charts SDK > Styling > Styles
 
Styles
The appearance of a chart can be dynamically controlled with cascading style sheets (CSS). Cascading style sheets are introduced in the Using CSS Syntax in the Style Sheet.
Applying styles
The IlvChart class implements the IlvStylable interface, which defines several methods to control the styling.
Here is an example of the typical code involved when you apply style sheets to a chart:
 
try {
  chart.setStyleSheets(new String[]{“simple.css”});
} catch (IlvStylingException x) {
  System.err.println("Cannot load style sheets: " + x.getMessage());
}
The chart.setStyleSheets method expects an array of String objects, which can represent either a URL, a file name, or the style sheet string directly.
Before the style sheets are applied, the chart configuration is restored to a default state, which basically corresponds to the state of a default IlvChart instance. This ensures that the application of two consecutive sets of style sheets does not produce an undesired cascading of styles. For more information on the operations performed to restore the state of the chart, you can refer to the documentation of the resetStyles method in the Reference Manual. Please remember that some elements of the chart are re-created, such as grids or scales. As a consequence, to use Java™ code to customize your chart on top of CSS, you can:
*invoke the Java code after the style sheets are applied,
or
*override IlvChart.resetStyles, so that it restores the chart to a different state.
You can also integrate a style sheet generated with the Designer. For more information, see Integrating your development into an application in Using the Designer.
Disabling styling
To disable the styling, the chart component provides two different solutions:
*Globally disable the styling by passing null to the setStyleSheets method.
This tells the chart that no style is specified and removes any overhead related to the styling. Note that this is different from setting an empty style sheet, since in this case the chart will still try to match style rules.
*Disable the dynamic interpretation of style rules when the data model changes.
You can do this by means of the setDynamicStyling method. When the dynamic styling is turned off, the chart will not re-apply styles if the contents of a data set are modified (for example, when new data points are added or when the values of a data point change). For efficiency reasons, it is recommended to toggle off the dynamic styling if your style sheet does not contain any rule based on the attributes of a data point or if your data model is static.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.