skip to main content
Charts > Developing with design tools > Using the Designer > Next steps after the Designer > Styling: CSS versus API
 
Styling: CSS versus API
The CSS styling allows you to change many graphical parameters. The Java™ API of JViews Charts also allows you to change graphical parameters. In the following sections you are going to see what their peculiarities are and how they can be used together.
Relationship between CSS and API
The CSS uses the JavaBeans™ setter methods of IlvChart and its associated objects. Therefore, what can be implemented through CSS can also be implemented through explicit API calls. If you use both of them, you have to be aware that loading a CSS file erases all the bean property values that were set since the CSS was last applied. This means that the API changes made after loading a CSS file will override the CSS settings; however, it is not recommended to reload a CSS file after applying API changes to the same properties.
Available graphical parameters
All graphical parameters that are available through the CSS are also available in the API. Some customizations are only available through the API; this is the case for the treemap renderer. Moreover, the API allows you to use your own custom instances of Paint, Stroke, and IlvStyle, while the CSS offers a broad but predefined set of parameterizations of Paint, Stroke and IlvStyle.
Computed graphical parameters
When the values of graphical parameters depend on other variables in your application, you may need to define CSS functions (subclasses of IlvCSSFunction ) and register them through IlvChart.registerFunction, so that they can be used in CSS style sheets. Since this is not immediate to do, it might be easier to do the corresponding styling in Java.
Ease of development
The Designer and the Styling Customizer allow you quickly try out various parameters (or combination of parameters) until you obtain the desired graphical effect. It might be more tedious to do this at the API level.
If you decide to customize your chart through the API rather than through CSS, you can still make limited use of the Designer to implement graphical effects. You can use the Designer to discover the right graphical parameters and then transpose them from CSS to Java code. For example, if the CSS is as follows
 
chartArea {
  foreground : black;
}
the API call will be:
 
chart.getChartArea().setForeground(Color.black);
Debugging
Debugging CSS is not easy. Sometimes a CSS rule hides part of another CSS rule, or you may not be aware of some of the complexities of CSS processing. On the other hand, styling code written in Java is more immediate to understand and can be debugged with the usual Java IDE features (such as breakpoints).
Interactions
Interactions are usually defined through an interactor class. Since you cannot test it in the Designer environment, you can usually add such an interactor class through the API, not through CSS.

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