com.arsdigita.acs.html
Class SidewaysBarChart

java.lang.Object
  |
  +--com.arsdigita.acs.html.SidewaysBarChart

public class SidewaysBarChart
extends Object

SidewaysBarChart.java Java port of Eve Andersson's tcl proc, gr_sideways_bar_chart creates bar charts in plain html with 1x1 pixel gifs stretched to the right width and height. It will work on any browser that supports tables (i.e., pretty much all of them). This package relies on a few gifs being present in /graphics/graphing-package/. For a full-featured graphing package written in Java, see ArsDigita JPlot.


Constructor Summary
SidewaysBarChart()
           
 
Method Summary
 void addValue(String subCategory, String category, int value)
          Call addValue once for each bar in the chart.
 void setbarColorList(String[] barColorList)
          There is a default list of colors with which the values will be displayed if there is more than one value per subcategory, but if those colors don't meet your design needs, go ahead and supply your own color list.
 void setBarHeight(int barHeight)
          By default, the height of each bar is 15 pixels.
 void setCompareNonPercentsAcrossCategories(boolean compareNonPercentsAcrossCategories)
          This is only relevant if you are graphing values that are not percentages.
 void setDefaultDrilldownUrl(String defaultDrilldownUrl)
          If supplied, should be a URL to which the numeric value (if being displayed) will be linked.
 void setDisplayScale(boolean displayScale)
          By default, there's a scale displayed at the top of the chart that goes from 0% to 100%, but if you don't want that scale there, set display_scale_p to "f".
 void setDisplayValues(boolean displayValues)
          By default, the values (like 60%) aren't displayed after the bars, but if you want them to be, set this to "t".
 void setLeftHeading(String leftHeading)
          Stuff (text/pictures/whatever) that goes above the items on the left of the chart (i.e.
 void setLegend(String[] legend)
           
 void setMinLeftColumnWidth(int minLeftColumnWidth)
          If you are going to stack charts, set the min_left_column_width to be the same for each of them so that they will line up.
 void setNonPercentValues(boolean nonPercentValues)
          Set this to "t" if the numbers you're charting are not percentages.
 void setReplaceNullSubcategoryWithNone(boolean replaceNullSubcategoryWithNone)
          Set this to "t" to have "[none]" be displayed as the subcategory if the subcategory is the empty string.
 void setRightHeading(String rightHeading)
          Stuff that goes above the items on the right of the chart (i.e.
 void setSubcategorySpacing(int subcategorySpacing)
          By default, the spacing between each subcategory is 7 pixels.
 String toString()
          Generates the HTML bar chart, according to the values set up by calling the addValue method.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SidewaysBarChart

public SidewaysBarChart()
Method Detail

addValue

public void addValue(String subCategory,
                     String category,
                     int value)
Call addValue once for each bar in the chart. The subcategory and category parameters determine the grouping that will be used.

To create a graph like this:

Dogs
Samoyed    xxxxxxxxxxx 45%
Black Lab  xxxx 20%
Terrier    xxxxxxxxxxxxxxxxxxxx 66%
Cats
Calico     xxxxxxxx 39%
Persian    xx 10%
call addValue 5 times, as follows:
SidewaysBarChart sbc = new SidewaysBarChart();
sbc.addValue("Samoyed", "Dogs", 45);
sbc.addValue("Black Lab", "Dogs", 20);
sbc.addValue("Terrier", "Dogs", 66);
sbc.addValue("Calico", "Cats", 39);
sbc.addValue("Persian", "Cats", 10);

You can have multiple values per subCategory, in which case you should call addValue once for each value, without changing the subCategory or category parameters.


toString

public String toString()
Generates the HTML bar chart, according to the values set up by calling the addValue method.
Overrides:
toString in class Object

setLegend

public void setLegend(String[] legend)

setbarColorList

public void setbarColorList(String[] barColorList)
There is a default list of colors with which the values will be displayed if there is more than one value per subcategory, but if those colors don't meet your design needs, go ahead and supply your own color list.

setDisplayValues

public void setDisplayValues(boolean displayValues)
By default, the values (like 60%) aren't displayed after the bars, but if you want them to be, set this to "t".

setDisplayScale

public void setDisplayScale(boolean displayScale)
By default, there's a scale displayed at the top of the chart that goes from 0% to 100%, but if you don't want that scale there, set display_scale_p to "f". It doesn't make sense to have the scale if the values that are being charted are not percentages.

setDefaultDrilldownUrl

public void setDefaultDrilldownUrl(String defaultDrilldownUrl)
If supplied, should be a URL to which the numeric value (if being displayed) will be linked. This variable will undergo variable expansion, so $category, $subcategory, and $value may be referenced.

setNonPercentValues

public void setNonPercentValues(boolean nonPercentValues)
Set this to "t" if the numbers you're charting are not percentages. Then this procedure will, instead of creating bars that are a fixed number times the value, display the values relative to each other (it will, in essence, pretend that the highest value within a category is 100%, and then display the other values in that category relative to each other).

setMinLeftColumnWidth

public void setMinLeftColumnWidth(int minLeftColumnWidth)
If you are going to stack charts, set the min_left_column_width to be the same for each of them so that they will line up. Otherwise, the left column, which contains the categories and subcategories, probably won't be the same for successive charts.

setBarHeight

public void setBarHeight(int barHeight)
By default, the height of each bar is 15 pixels.

setSubcategorySpacing

public void setSubcategorySpacing(int subcategorySpacing)
By default, the spacing between each subcategory is 7 pixels.

setCompareNonPercentsAcrossCategories

public void setCompareNonPercentsAcrossCategories(boolean compareNonPercentsAcrossCategories)
This is only relevant if you are graphing values that are not percentages. Usually (as explained above for non_percent_values_p), the bars are drawn so that they are relative only to other bars in the same category. This makes sense if one category has values like 900, 854, 942, and another totally unrelated category has values like 2.5, 3, 3.27. You wouldn't want the bars in the second category to be drawn relative to the ones in the first category because they would be very small and, besides, they're not even related. But, if the numbers ARE related across categories, then set compare_non_percents_across_categories to "t".

setLeftHeading

public void setLeftHeading(String leftHeading)
Stuff (text/pictures/whatever) that goes above the items on the left of the chart (i.e. above the categories and subcategories).

setRightHeading

public void setRightHeading(String rightHeading)
Stuff that goes above the items on the right of the chart (i.e. above the values).

setReplaceNullSubcategoryWithNone

public void setReplaceNullSubcategoryWithNone(boolean replaceNullSubcategoryWithNone)
Set this to "t" to have "[none]" be displayed as the subcategory if the subcategory is the empty string.