Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Format chart with CSS file
Max Bo
<p>Hi,</p><p> </p><p>Is there anywhere an overview out there, that shows me, what format values of a chart I can set via a CSS file?</p><p>So far I have not found anything which seems to be complete.</p><p> </p><p>Max</p>
Find more posts tagged with
Comments
kclark
<p>You can apply some styles to the chart like a border but there currently isn't any way to style say the series colors or the legend. What properties were you wanting to style?</p>
Max Bo
<p>Series colors and legend are not the problem, I have found a script for that
</p><p> </p><p>What I want to style are for example title, gridlines, markers, borders (actually, everything besides series and legends
</p>
kclark
<p>You could write a class that parses a text file and then you could use this class in your chart script to get the style information and use it in your chart. Then you could use that class in each chart and point it at the text file you want to use to style it.</p><p> </p><p>Here's a small example of what you could do.</p><pre class="_prettyXprint">package org.birtexchange.chart.style;import java.io.IOException;import java.nio.ByteBuffer;import java.nio.charset.StandardCharsets;import java.nio.file.Files;import java.nio.file.Paths;import java.util.regex.Matcher;import java.util.regex.Pattern;public class ChartStyleParser { private static String seriesColor = null; private static String titleName = null; private static String titleColor = null; // Add more style variables here private static void parse(String style) { byte[] encoded; try { encoded = Files.readAllBytes(Paths.get(style)); String styleSource = StandardCharsets.UTF_8.decode(ByteBuffer.wrap(encoded)).toString(); Pattern p = Pattern.compile("seriesColor="(.*?)""); Matcher m = p.matcher(styleSource); if (m.find()) { seriesColor = m.group(1); } // Change the pattern and keep parsing for any other tags you want to have in your style file } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static String getSeriesColor() { return seriesColor; } // Add more getter methods for your style variables public static void main(String[] args) { parse("C:/Users/kclark/Desktop/chartStyle.txt"); System.out.println(seriesColor); }}</pre><p>Then in your chart you could do something like</p><pre class="_prettyXprint">importPackage(Packages.org.birtexchange.chart.style);test = new ChartStyleParser();test.parse();// Then use test.getSeriesColor() or any of your other methods in the chart script</pre>
Max Bo
<p>Ok, I think I get where you are going with this.
Guess, that should work although it is a little bit more complex than just adjusting a CSS file ...
</p><p> </p><p>Thanks for the help!</p>