User Tools

Site Tools


gdchartexample

GdChart, PyGDChart2 examples

Bar3D

Source code:

#!python
import cgitb; cgitb.enable()
import gdchart
import sys
gd = gdchart.Bar3D()
gd.width = 250
gd.height = 250
gd.xtitle = "Weekday"
gd.ytitle = "Percentage"
gd.title = "Example Graph"
gd.ext_color = [ "white", "yellow", "red", "blue", "green"]
gd.setData([20, 100, 80, 30, 50])
gd.setLabels(["Mon", "Tue", "Wed", "Thu", "Fri"])
print 'Content-Type: image/png\n'
sys.stdout.flush()
gd.draw(sys.stdout)
sys.stdout.flush()

Scatter, Line

Source code:

import cgitb; cgitb.enable()
import random
import gdchart
import sys
 
sgraph = gdchart.Line()
sgraph.width = 250
sgraph.height = 250
sgraph.xtitle = "Weekday"
sgraph.ytitle = "Percentage"
sgraph.title = "Scatter"
sgraph.plot_color = "red"
sgraph.xtitle_color = "white"
sgraph.ytitle_color = "white"
sgraph.setData(range(100))
sgraph.setLabels(range(100))
 
scats = []
for i in range(150):
    x = random.randrange(30, 80)
    y = random.randrange(30, 80)
    s = gdchart.Scatter(x, y, "CIRCLE", 100, "blue")
    scats.append(s)
 
sgraph.setScatter(scats)
 
print 'Content-Type: image/png\n'
sys.stdout.flush()
sgraph.draw(sys.stdout)
sys.stdout.flush()

Pie3D

Source code:

import cgitb; cgitb.enable()
import gdchart
import sys
 
myPie = gdchart.Pie3D()
myPie.width = 250
myPie.height = 250
myPie.title = "Pie3D"
myPie.setData(1, 2, 3, 4, 5)
myPie.setLabels(["One", "Two", "Three", "Four", "Five"])
myPie.color = ["red", "green", "yellow", "orange", "blue"]
myPie.explode = [0, 0, 20, 0, 0]
 
print 'Content-Type: image/png\n'
sys.stdout.flush()
myPie.draw(sys.stdout)
sys.stdout.flush()

HLC3D

Source code:

import cgitb; cgitb.enable()
import gdchart
import sys
 
data1 = (0.5, 0.09, 0.3, 0.75, 0.0, 0.90)
data2 = (1.9, 1.3, 1.2, 0.75, 0.1, 2.0)
data3 = (62, 71, 71, 52, 55, 48)
data4 = (42, 62, 52, 37, 52, 50)
cities = ('Chicago', 'New York', 'L.A.', 'Atlanta', 'Paris, MD\n(USA)', 'London')
days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
 
# Hi-lo-close chart
# Other style: GDC_HILOCLOSE.
dates = ('Jan 1', 'Jan 8', 'Jan 15', 'Jan 22', 'Jan 29', 'Feb 5')
h1=(28,30,32,33,36,35)
l1=(24,27,28,30,31,24)
c1=(27,29,30,31,33,26)
 
h2=map(lambda x:0.8*x, h1); h2.reverse()
l2=map(lambda x:0.6*x, l1); l2.reverse()
c2=map(lambda x:0.7*x, c1); c2.reverse()
 
gd = gdchart.HLC3D()
gd.title = 'Hi-Lo-Close Chart'
gd.yaxis = 1
gd.ylabel_fmt = '$%.0f '
gd.set_color = (0x80ff80, 0x8080ff, 0xff8080, 0x80c080, 0x8080c0, 0xc08080)
gd.hlc_style = ("I_CAP", "CONNECTING")
gd.setLabels(dates)
gd.width = 250
gd.height = 250
 
gd.setData((h1,l1,c1), (h2, l2, c2))
 
print 'Content-Type: image/png\n'
sys.stdout.flush()
gd.draw(sys.stdout)
sys.stdout.flush()

HLCAreaCombo

Source code:

import cgitb; cgitb.enable()
import gdchart
import sys
 
data1 = (0.5, 0.09, 0.3, 0.75, 0.0, 0.90)
data2 = (1.9, 1.3, 1.2, 0.75, 0.1, 2.0)
data3 = (62, 71, 71, 52, 55, 48)
data4 = (42, 62, 52, 37, 52, 50)
cities = ('Chicago', 'New York', 'L.A.', 'Atlanta', 'Paris, MD\n(USA)', 'London')
days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
 
# Hi-lo-close chart
# Other style: GDC_HILOCLOSE.
dates = ('Jan 1', 'Jan 8', 'Jan 15', 'Jan 22', 'Jan 29', 'Feb 5')
h1=(28,30,32,33,36,35)
l1=(24,27,28,30,31,24)
c1=(27,29,30,31,33,26)
 
h2=map(lambda x:0.8*x, h1); h2.reverse()
l2=map(lambda x:0.6*x, l1); l2.reverse()
c2=map(lambda x:0.7*x, c1); c2.reverse()
 
gd = gdchart.HLCAreaCombo3D()
 
gd.title = 'Hi-Lo-Close Chart'
gd.yaxis = 1
gd.ylabel_fmt = '$%.0f '
gd.set_color = (0x80ff80, 0x8080ff, 0xff8080, 0x80c080, 0x8080c0, 0xc08080)
gd.hlc_style = ("I_CAP", "CONNECTING")
gd.yaxis2 = 1
gd.vol_color = 0x808080
# Combo hi-lo-close chart
 
gd.setData((h1,l1,c1))
gd.setComboData(data3)
gd.setLabels(dates)
gd.width = 250
gd.height = 250
 
print 'Content-Type: image/png\n'
sys.stdout.flush()
gd.draw(sys.stdout)
sys.stdout.flush()
gdchartexample.txt · Last modified: 2014/09/17 06:43 by wikiadmin