示例#1
0
# We will cover these years
startyear = 1981
endyear = 2012

# We will make charts for 3 major Canadian cities
cities = [
	{'name': "Montreal", 'fillColor': "rgba(100,50,200,0.25)", 'strokeColor': "rgba(100,50,200,0.75)", 'pointColor': "rgba(100,50,200,0.75)"},
	{'name': "Toronto", 'fillColor': "rgba(200,100,100,0.25)", 'strokeColor': "rgba(200,100,100,0.75)", 'pointColor': "rgba(200,100,100,0.75)"},
	{'name': "Vancouver", 'fillColor': "rgba(100,200,100,0.25)", 'strokeColor': "rgba(100,200,100,0.75)", 'pointColor': "rgba(100,200,100,0.75)"},
]

# 3 of the charts will cover all 12 months
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]

# The first chart will show median temperatures over the years
global_chart = chartjs.chart("Temperature medians for 1981 - 2012 in Celsius<br><font color='#6432C8'>Montreal</font>, <font color='#B1846B'>Toronto</font>, <font color='#6CCB6C'>Vancouver</font>", "Line", 1200, 600)
global_chart.set_params(JSinline = False)

# Each city will have a chart showing each month's median temperature
montreal_chart = chartjs.chart("Montreal temperatures for 2012 in Celsius", "Line", 390, 200)
montreal_chart.canvas = "montreal"
montreal_chart.set_labels(months)
toronto_chart = chartjs.chart("Toronto temperatures for 2012 in Celsius", "Line", 390, 200)
toronto_chart.canvas = "toronto"
toronto_chart.set_labels(months)
vancouver_chart = chartjs.chart("Vancouver temperatures for 2012 in Celsius", "Line", 390, 200)
vancouver_chart.canvas = "vancouver"
vancouver_chart.set_labels(months)

_startyear = startyear
# Loop one city at a time
示例#2
0
import chartjs

# Make a pie chart
mychart = chartjs.chart("Sample pie chart", "PolarArea")

# Add labels, colors, highlights and data values
mychart.set_labels(["Apple", "Orange", "Banana"])
mychart.set_colors(["#E24736", "#FF9438", "#FFF249"])
mychart.set_highlights(["#E07369", "#FFAC68", "#FFF293"])
mychart.add_dataset([5,2.3,10])

# Make the HTML file
f = open("sample2.html", 'w')
f.write(mychart.make_chart_full_html())
f.close()
示例#3
0
文件: sample.py 项目: dendory/chartjs
import chartjs
import csv

# Create a new chart object and set some values
mychart = chartjs.chart("Wind energy visualization (in million KW/h) for 2010-2012", "Line", 1600, 800)

# Set some basic options
mychart.set_params(barValueSpacing = 100)

# Labels will be countries
countries = []

# We will make 3 datasets for the last 3 years available in our CSV file
values2012 = []
values2011 = []
values2010 = []
value = {'2010': 0, '2011': 0, '2012': 0}

# Read data from sample.csv
f = open("data/sample.csv", 'r', newline='')
data = csv.reader(f, delimiter=',')
next(data) # Skip headers

# Iterate through the file, then add datasets every time the country name changes
for line in data:
	if len(line) > 4 and float(line[4]) > 100:
		if line[0] not in countries:
			# Place the values of the last country in our lists
			if countries != []:
				values2012.append(value['2012'])
				values2011.append(value['2011'])
示例#4
0
文件: sample.py 项目: dendory/chartjs
import chartjs
import csv

# Create a new chart object and set some values
mychart = chartjs.chart(
    "Wind energy visualization (in million KW/h) for 2010-2012", "Line", 1600,
    800)

# Set some basic options
mychart.set_params(barValueSpacing=100)

# Labels will be countries
countries = []

# We will make 3 datasets for the last 3 years available in our CSV file
values2012 = []
values2011 = []
values2010 = []
value = {'2010': 0, '2011': 0, '2012': 0}

# Read data from sample.csv
f = open("data/sample.csv", 'r', newline='')
data = csv.reader(f, delimiter=',')
next(data)  # Skip headers

# Iterate through the file, then add datasets every time the country name changes
for line in data:
    if len(line) > 4 and float(line[4]) > 100:
        if line[0] not in countries:
            # Place the values of the last country in our lists
            if countries != []:
示例#5
0
import chartjs
import time

# Create a new chart object and set some values
mychart = chartjs.chart("Performance Matrix", "Line", 1600, 800)

# Set some basic options
mychart.set_params(barValueSpacing=100)

actions = ['login', 'fileupload', 'logout']

timestamp = [1, 5, 3]

print(timestamp)

# Set labels to be the countries found in our file
mychart.set_labels(actions)

# Add three datasets for the three years
mychart.add_dataset(timestamp)
mychart.set_params(fillColor="rgba(100,200,200,0.25)",
                   strokeColor="rgba(100,200,200,0.75)",
                   pointColor="rgba(100,200,200,0.75)")
'''mychart.add_dataset(values2011)
mychart.set_params(fillColor = "rgba(200,100,100,0.25)", strokeColor = "rgba(200,100,100,0.75)", pointColor = "rgba(200,100,100,0.75)")
mychart.add_dataset(values2010)'''

# Write sample.html
f = open("sample.html", 'w')
f.write(mychart.make_chart_full_html())
f.close()
示例#6
0
        'name': "Vancouver",
        'fillColor': "rgba(100,200,100,0.25)",
        'strokeColor': "rgba(100,200,100,0.75)",
        'pointColor': "rgba(100,200,100,0.75)"
    },
]

# 3 of the charts will cover all 12 months
months = [
    "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
    "Nov", "Dec"
]

# The first chart will show median temperatures over the years
global_chart = chartjs.chart(
    "Temperature medians for 1981 - 2012 in Celsius<br><font color='#6432C8'>Montreal</font>, <font color='#B1846B'>Toronto</font>, <font color='#6CCB6C'>Vancouver</font>",
    "Line", 1200, 600)
global_chart.set_params(JSinline=False)

# Each city will have a chart showing each month's median temperature
montreal_chart = chartjs.chart("Montreal temperatures for 2012 in Celsius",
                               "Line", 390, 200)
montreal_chart.canvas = "montreal"
montreal_chart.set_labels(months)
toronto_chart = chartjs.chart("Toronto temperatures for 2012 in Celsius",
                              "Line", 390, 200)
toronto_chart.canvas = "toronto"
toronto_chart.set_labels(months)
vancouver_chart = chartjs.chart("Vancouver temperatures for 2012 in Celsius",
                                "Line", 390, 200)
vancouver_chart.canvas = "vancouver"