Stylesheets allow a fine-grain configuration of every chart output aspect. Every view and chart object has its own stylesheet, which refers to the stylesheet of the parent view object. This way a hierarchy of stylesheets is formed. The default system stylesheet is at the root of the hierarchy. If no properties are set for individual view stylesheets, all properties are set to default stylesheet values.
The default stylesheet is fine-tuned for best quality output and performance on the available platform.
Most chart objects and views have methods for easy stylesheet configuration. But only the most frequently used methods are provided. All other settings have to be applied by modifying the stylesheet directly. It is possible to change the default stylesheet (Stylesheet.defaultStylesheet) or the object’s local stylesheet:
<object>.style........ |
By changing the stylesheet all related views are automatically updated and repainted.
However, it is recommended to use TextStyle and PaintStyle objects (getTextStyle() and getPaintStyle() methods) to set properties for each charts objects. For example:
1 | //sets BarSeries object, named series, background color to red series.getPaintStyle().setBackground(Color.red); //sets font and size of axis title of Axis object, named axisX axisX.getTextStyle().setFont(AxisTextTags.TITLE,new Font("Verdana",Font.PLAIN,16)); |
Stylesheet file can be loaded:
1 | m_chartPanel = new JChartPanel(m_chart); // Load stylesheet from file StyleLoader loader = new StyleLoader(); loader.loadStyles("RedChartStyle.mchs", m_chartPanel, null); |