I managed to create a pdf file that contains a histogram, which is stored on the server.
my problem is: I want to display the window "save as" in the browser to give customers the possibility to save the file locally and I do not know how
please help me
- Code: Select all
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import cm
from reportlab.graphics.charts.barcharts import VerticalBarChart
from reportlab.graphics.shapes import Drawing
from reportlab.platypus import *
from reportlab.lib import colors
elements = 
styles = getSampleStyleSheet()
doc = SimpleDocTemplate('C:/nombre_panne.pdf')
elements.append(box(Paragraph("Nombre de pannes",styles['Title'])))
# A Spacer, fairly intuitively, occupies a certain amount of Space
# in the document.
elements.append(Spacer(0, 0.5 * cm))
# Create a chart 'Drawing'
chart = VerticalBarChart()
# Set the starting point to be (0, 0). Changing this value changes
# the position that the chart is rendered at within it's 'Drawing'
# space, which we create below.
chart.x = 0
chart.y = 0
# This determines the width, in centimeters (you could use 'inch'
# as well) of the chart on the paper, as well as the height.
chart_width = 8*cm
chart_height = 3*cm
chart.height = chart_height
chart.width = chart_width
# The vertical ticks will be labeled from 0 with a value every
# 15 units, spaced so that the maximum value is 60.
chart.valueAxis.valueMin = 0
chart.valueAxis.valueMax = 60
chart.valueAxis.valueStep = 15
# Put the labels at the bottom with an interval of 8 units,
# -2 units below the axis, rotated 30 degrees from horizontal
chart.categoryAxis.labels.dx = 8
chart.categoryAxis.labels.dy = -2
chart.categoryAxis.labels.angle = 30
# The text box's NE corner (top right) is located at the above
chart.categoryAxis.labels.boxAnchor = 'ne'
# Our various horizontal axis labels
catNames = ['Jan-06', 'Feb-06', 'Mar-06', 'Apr-06', 'May-06','Jun-06', 'Jul-06', 'Aug-06']
chart.categoryAxis.categoryNames = catNames
# Some random data to populate the chart with.
chart.data = [(8, 5, 20, 22, 37, 28, 30, 47)]
# Since the 'Chart' class itself isn't a 'Flowable', we need to
# create a 'Drawing' flowable to contain it. We want the basic
# area to be the same size as the chart itself, so we will
# initialize it with the chart's size.
drawing = Drawing(chart_width, chart_height)
# Add the Chart containing Drawing to our elements list
elements.append(Spacer(0, 2 * cm))
# Write the document to disk