Category Plots, aka Bar Charts


In [1]:
def bars = new CategoryBars(value: [[1, 2, 3], [1, 3, 5]])
new CategoryPlot() << bars


Out[1]:


In [2]:
def cplot = new CategoryPlot(initWidth: 400, initHeight: 200)
def bars = new CategoryBars(value:[[1, 2, 3], [1, 3, 5]])
cplot << bars


Out[2]:


In [3]:
def cplot = new CategoryPlot(title: "Hello CategoryPlot!",
                             xLabel: "Categories",
                             yLabel: "Values")
cplot << new CategoryBars(value:[[1, 2, 3], [1, 3, 5]])


Out[3]:


In [4]:
def cplot = new CategoryPlot(categoryNames: ["Helium", "Neon", "Argon"])
cplot << new CategoryBars(value: [[1, 2, 3], [1, 3, 5]])


Out[4]:


In [5]:
new CategoryPlot() << new CategoryBars(value: [[1, 2, 3], [1, 3, 5]],
                                       seriesNames: ["Gas", "Liquid"])


Out[5]:


In [6]:
def bars = new CategoryBars(value: [[1, 2], [3, 4], [5, 6], [7, 8]],
                            seriesNames: ["Gas", null, "", "Liquid"])
new CategoryPlot() << bars


Out[6]:


In [7]:
def plot = new CategoryPlot(showLegend: true) // force legend display
def bars = new CategoryBars(value: [[1, 2, 3], [1, 3, 5]])
// since no display names were provided, default names "series0" etc will be used.
plot << bars


Out[7]:


In [8]:
def plot = new CategoryPlot(orientation: PlotOrientationType.HORIZONTAL)
plot << new CategoryBars(value:[[1, 2, 3], [1, 3, 5]])


Out[8]:


In [9]:
def plot = new CategoryPlot(categoryNames: ["Acid", "Neutral", "Base"], 
                            categoryNamesLabelAngle: -1/4 * Math.PI)
plot << new CategoryBars(value: [[1, 2, 3], [4, 5, 6]])


Out[9]:


In [10]:
new CategoryPlot(categoryMargin: 2) << new CategoryBars(value: [[1, 2, 3], [4, 5, 6]])


Out[10]:


In [11]:
def bars = new CategoryBars(value: (1..4) + 2)
new CategoryPlot() << bars


Out[11]:


In [12]:
def bars = new CategoryBars(value: [[1, 2], [3, 4], [5, 6]], color: Color.pink)
new CategoryPlot() << bars


Out[12]:


In [13]:
def colors = [Color.red, Color.gray, Color.blue]
def bars = new CategoryBars(value: [[1, 2], [3, 4], [5, 6]], color: colors)
new CategoryPlot() << bars


Out[13]:


In [14]:
def colors = [[Color.red, Color.gray],
              [Color.gray, Color.gray],
              [Color.blue, Color.pink]]
def bars = new CategoryBars(value: [[1, 2], [3, 4], [5, 6]], color: colors)
new CategoryPlot() << bars


Out[14]:


In [15]:
def colors = [Color.pink, [Color.red, Color.gray, Color.blue]]
def bars = new CategoryBars(value: [[1, 2, 3], [4, 5, 6]], color: colors)
new CategoryPlot() << bars


Out[15]:


In [16]:
def bars = new CategoryBars(value: [[1, 2, 3], [4, 5, 6]], base: -2)
new CategoryPlot() << bars


Out[16]:


In [17]:
def bars = new CategoryBars(value: [[1, 2,  3], [4, 5, 4]], base: [-1, -3])
new CategoryPlot() << bars


Out[17]:


In [18]:
def bars = new CategoryBars(value: [[1, 2, 3], [4, 5, 6]],
                            base: [[0, 1, 1], [-4, -5, -6]])
new CategoryPlot() << bars


Out[18]:


In [19]:
def bars = new CategoryBars(value: [[1, 2, 3], [4, 5, 6]],
                            width: [[0.3, 0.6, 1.7], 1.0])
new CategoryPlot() << bars


Out[19]:


In [20]:
def bars = new CategoryBars(value: [[1, 2, 3], [4, 5, 6]],
                            fill: [[true, true, false], [true, false, true]],
                            drawOutline: [[true, false, true], [true, true, false]],
                            outlineColor: [Color.black, Color.red])
new CategoryPlot() << bars


Out[20]:


In [21]:
def bars = new CategoryBars(value: [[1, 2, 3], [4, 5, 8], [10, 9, 10]],
                           base: [0, [1, 2, 3], [4, 5, 8]],
                           centerSeries: true,
                           itemLabel: {value, base-> Math.abs(value-base)})
new CategoryPlot() << bars


Out[21]:


In [22]:
def ss = [StrokeType.DASH, StrokeType.LONGDASH]
def cs = [Color.black, Color.red]
new CategoryPlot() << new CategoryStems(value: [[1, 2, 4], [4, 5, 8]], color: cs, style: ss)


Out[22]:


In [35]:
new CategoryPlot() << new CategoryPoints(value: [[1, 2, 4], [4, 5, 8]])


Out[35]:


In [36]:
def ss = [StrokeType.DASH, StrokeType.DOT]
new CategoryPlot() << new CategoryLines(value: [[1, 2, 4], [4, 5, 8]], style: ss,
                                        seriesNames:["Lanthanide", "Actinide"])


Out[36]:


In [37]:
def s1 = [1, 2, 4]
def s2 = [4, 5, 8]
def lines = new CategoryLines(value: [s1, s2], centerSeries: true)
def points = new CategoryPoints(value: [s1, s2], centerSeries: true)
def stems = new CategoryStems(value:[s1], base: [s2], style: StrokeType.DOT, color: Color.gray)
new CategoryPlot() << lines << points << stems


Out[37]:


In [38]:
def plot = new CategoryPlot(initWidth: 500, initHeight: 400,
                            title: "Bar Chart Demo",
                            xLabel: "Alkali", yLabel: "Temperature ° Celcius",
                            categoryNames:["Lithium", "Sodium", "Potassium", "Rubidium"])
def s1 = [[10, 15, 13, 7], [22, 18, 28, 17]]
def high = [[12.4, 19.5, 15.1, 8.2], [24.3, 23.3, 30.1, 18.2]]
def low = [[7.6, 10.5, 10.9, 5.8], [19.7, 12.7, 25.9, 15.8]]
def color = [new Color(247, 150, 70), Color.orange, new Color(155, 187, 89)]
plot << new CategoryBars(value: s1, color: color, seriesNames: ["Solid", "Liquid"])
plot << new CategoryStems(value: high, base: low, color: color[2])
plot << new CategoryPoints(value: high, outlineColor: color[2], size:12)
plot << new CategoryPoints(value: low, outlineColor: color[2], size:12)


Out[38]:


In [51]:
def p = new CategoryPlot(title: "Multiple Y Axes Demo",
                         yLabel: "Price",
                         categoryNames: ["Q1", "Q2", "Q3", "Q4"])
p << new YAxis(label: "Volume", upperMargin: 1)
p << new CategoryBars(value: [[1500, 2200, 2500, 4000]], width: 0.6,
                      color: Color.PINK, yAxis: "Volume", showItemLabel: true,
                      labelPosition: LabelPositionType.VALUE_INSIDE)
p << new CategoryLines(value: [[5, 2, 3.5, 4]], color: Color.GRAY,
                       showItemLabel:true)
p << new CategoryPoints(value:[[5, 2, 3.5, 4]], color:Color.GRAY)


Out[51]:


In [40]:
new CategoryPlot() << new CategoryStems(value:[[-3, 2, 4], [4, 5, 8]],
                                        width: 10, showItemLabel: true)


Out[40]:


In [42]:
def bars = new CategoryBars(value: [[-5, 2, 3], [1, 3, 5]],
                            showItemLabel: true)
new CategoryPlot() << bars


Out[42]:


In [43]:
def bars = new CategoryBars(value: [[-5, 2, 3], [1, 3, 5]],
                            labelPosition: LabelPositionType.BASE_OUTSIDE,
                            showItemLabel: true)
new CategoryPlot() << bars


Out[43]:


In [44]:
def plot = new CategoryPlot(title: "Move mouse cursor over bars")
def bars = new CategoryBars(value: [[-5, 2, 3], [1, 3, 5]], useToolTip: false)
plot << bars


Out[44]:


In [45]:
def input = [[1,2,3],[1,3,5]].transpose() // == [[1,1], [2,3], [3,5]]
def bars = new CategoryBars(value: input)
new CategoryPlot() << bars


Out[45]:


In [53]:
table = [[close:11.59, high:13.15, low:11.92, open:11.92],
         [close:12.76, high:15.44, low:11.88, open:12.42],
         [close:18.19, high:20.96, low:17.93, open:18.56]]
def v = table.collect { it.values().toList() }
def p = new CategoryPlot(categoryNames: table[0].keySet().toList())
p << new CategoryBars(value: v, seriesNames: ["A", "B", "C"])


Out[53]:


In [ ]: