|
Revision 172, 1.6 kB
(checked in by lgs, 3 years ago)
|
|
Initial implementation of the interval option. Based on a patch by Nicolas. See #28
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | import cairo |
|---|
| 19 | |
|---|
| 20 | import pycha.line |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | def intervalExample(): |
|---|
| 24 | surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 400, 200) |
|---|
| 25 | |
|---|
| 26 | dataSet = ( |
|---|
| 27 | ('dataset 1', [(0, 10), (1, 20), (2, 45), (3, 33)]), |
|---|
| 28 | ('dataset 2', [(0, 14), (1, 18), (2, 32), (3, 21)]), |
|---|
| 29 | ) |
|---|
| 30 | |
|---|
| 31 | options = { |
|---|
| 32 | 'axis': { |
|---|
| 33 | 'x': { |
|---|
| 34 | 'interval': 0.5, |
|---|
| 35 | }, |
|---|
| 36 | 'y': { |
|---|
| 37 | 'interval': 5, |
|---|
| 38 | }, |
|---|
| 39 | }, |
|---|
| 40 | 'legend': { |
|---|
| 41 | 'hide': True, |
|---|
| 42 | }, |
|---|
| 43 | 'title': 'Interval example', |
|---|
| 44 | 'background': { |
|---|
| 45 | 'baseColor': '#f0f0f0', |
|---|
| 46 | }, |
|---|
| 47 | 'shouldFill': False, |
|---|
| 48 | } |
|---|
| 49 | chart = pycha.line.LineChart(surface, options) |
|---|
| 50 | |
|---|
| 51 | chart.addDataset(dataSet) |
|---|
| 52 | chart.render() |
|---|
| 53 | |
|---|
| 54 | surface.write_to_png("interval.png") |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | if __name__ == '__main__': |
|---|
| 58 | intervalExample() |
|---|