|
Area charts with vertical X-axis labels |
Posted by ernie on Feb-18-2012 02:52 |
|
When generating an area chart with vertical X-axis labels, the left and right edges of the graph are padded - this appears to be to accommodate the table used to rotate the axis labels.
A demo of the issue is generated using this modified simplearea.py (added line 23):
#!/usr/bin/python
from pychartdir import *
# The data for the area chart
data = [30, 28, 40, 55, 75, 68, 54, 60, 50, 62, 75, 65, 75, 89, 60, 55, 53, 35, 50,
66, 56, 48, 52, 65, 62]
# The labels for the area chart
labels = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"]
# Create a XYChart object of size 250 x 250 pixels
c = XYChart(250, 250)
# Set the plotarea at (30, 20) and of size 200 x 200 pixels
c.setPlotArea(30, 20, 200, 200)
# Add an area chart layer using the given data
c.addAreaLayer(data)
# Set the labels on the x axis.
c.xAxis().setLabels(labels)
c.xAxis().makeLabelTable().getStyle().setFontAngle(90)
# Display 1 out of 3 labels on the x-axis.
c.xAxis().setLabelStep(3)
# Output the chart
c.makeChart("simplearea.png")
Is there anyway to have vertical x-axis labels and avoid the padding on the left and the right?
|
Re: Area charts with vertical X-axis labels |
Posted by ernie on Feb-18-2012 02:58 |
|
Whoops, here'e the same chart using my license . . .
|
Re: Area charts with vertical X-axis labels |
Posted by Peter Kwan on Feb-20-2012 23:41 |
|
Hi ernie,
The padding is not actually due to label rotation, but is due to the label table. If you look at the "Data Table (1)" sample code in ChartDirector, you can see that the chart is padded even the labels are not rotated.
For your chart, the data is from 0 to 24 in the x-direction. So the distance between the first and last data point is 24. However, there are 25 labels on the x-axis (0, 1, 2, ... 24). If you use an axis table, there must be 25 equally sized cells in the table for the 25 labels, no matter the labels are rotated or not. So the table length will be longer than the data length, and some padding are needed to synchronize the data with the table.
If your intention is to rotate the labels, you may consider the following methods, which rotates the labels but do not put them into a table.
c.xAxis().setLabels(labels)
c.xAxis().setLabelStyle("arial.ttf", 8, 0x000000, 90)
Hope this can help.
Regards
Peter Kwan |
Re: Area charts with vertical X-axis labels |
Posted by ernie on Feb-22-2012 01:45 |
|
I figured the padding was due to the table, but wasn't sure how to rotate the labels without using a table.
I hadn't realized there was a rotation parameter for the setLabelStyle method - thanks for the example! |
|