Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 54 lines (42 sloc) 1.772 kb
b8dc2ac more gchart update
lkcl authored
1 import math
2
3 from pyjamas.chart.GChart import GChart
4 from pyjamas.chart import GChartUtil
5
6 # GWT 1.4's Math class does not include JDK's
7 # Math.log10--so emulate it.
8 def log10(x):
9 return math.log(x)/math.log(10.0)
10
11 """*
12 * Defines a traditional "semi-log" chart by using custom
13 * ticks on the y axis, in conjunction with log-transformed
14 * y data.
15 """
16 class GChartExample04(GChart):
17 def __init__(self):
18 GChart.__init__(self, 300, 450)
19 self.setChartTitle("<h2>2<sup>x</sup> vs x</h2>")
20 self.addCurve()
21 self.getCurve().getSymbol().setHovertextTemplate(
22 GChartUtil.formatAsHovertext("${y}=2^${x}"))
23 self.getCurve().setLegendLabel("<b>2<sup>x</sup></b>")
24 self.getCurve().getSymbol().setBackgroundColor("red")
25 self.getCurve().getSymbol().setBorderColor("black")
26 self.getCurve().getSymbol().setWidth(9)
27 self.getCurve().getSymbol().setHeight(9)
28
29 # add (log10-transformed) powers of 2 from 1/4 to 8
30 for i in range(-2, 4):
31 self.getCurve().addPoint(i,log10(math.pow(2,i)))
32
33 # GChart's "=10^" NumberFormat prefix inverts the log10
34 # transform
35 self.getYAxis().setTickLabelFormat("=10^#.##")
36 # add conventional log-scaled ticks from .1 to 10
37 self.getYAxis().addTick(log10(0.1))
38 x = 0.1
39 while x < 10:
40 for y in range(2, 11):
41 self.getYAxis().addTick(log10(x*y))
42 x *= 10
43
44 self.getXAxis().setAxisLabel("<b>x</b>")
45 self.getXAxis().setHasGridlines(True)
46 self.getXAxis().setTickCount(6)
47
48 self.getYAxis().setAxisLabel("<b>2<sup>x</sup></b>")
49 self.getYAxis().setHasGridlines(True)
50
51
52
53
Something went wrong with that request. Please try again.