I've been playing with custom datalabels (which are a great inclusion BTW).
The charts I generate are over a period of 70 days, and when I apply a custom data label function to display only the first and last data label, it appears out of the plot area.
I imagine is partly due to the number of data points (I tried another chart with fewer data points and it works OK). What is the best way to approach this so that the data labels appear within the plot area?
I read the section on data label tuning and I will increase the spacing to 10 pixels, but I assume data labels will still appear out of the area, but may appear more readable.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Are we talking about the "0.5" and "1.5" labels at the start and end of the red plot line? Those are appearing 5 pixels (by default) above (90 degrees) those data points, by default, with bottom/center alignment. And the issue is that they are partly off the left and right sides of the plot area, correct?
No, I don't think we are going to fix it by adjusting the label tuning parameters. If you change the angle, one will be in and the other further out. Increasing the label distance is just going to move them up.
Probably you need a little more space along the X axis at both ends. You don't have X axis labels on the plot so I don't know what you are working with now. Are you setting the X scale with SetPlotAreaWorld() or is PHPlot calculating it? If you are setting it, can you make it bigger? This leaves more room for labels. If PHPlot is automatically calculating the range, it is still possible to adjust it (with PHPlot-6.0 and up), but if the left side is x=0 that makes it harder.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just to see what it does, before trying SetPlotAreaWorld() to manually set the range, you might try:
$plot->TuneXAutoRange(NULL, NULL, 0.05);
This should make sure there is a space of at least 5% of the axis range between the maximum X value and the tick mark at the end of the X axis. You can adjust that number up or down as needed.
It won't help on the left side of the axis, though. I need to think about that one some more.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you are already using SetPlotAreaWorld() to set Xmin and Xmax along the axis (1st and 3rd arguments), then TuneXAutoRange() does not apply. You are telling PHPlot what limits to use for X, so there is nothing for it to tune or calculate. If this is the case, I think you just need to increase your Xmax and decrease Xmin to leave a little more room on the sides.
Or, if you are using SetPlotAreaWorld() but only to set Y limits, not X, then TuneXAutoRange() should have changed the result.
All this assumes your data array has X values. If not, and you are using text-data as the data type (implied X values), then the range for X will simply be 0 to N, where N is the number of rows (number of X values). In this case, the extra margin space on each end will decrease as the number of rows increases. You can increase this margin space along X with SetPlotAreaWorld(-K, NULL, N+K). Again - this is only for 'text-data' data type.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I've been playing with custom datalabels (which are a great inclusion BTW).
The charts I generate are over a period of 70 days, and when I apply a custom data label function to display only the first and last data label, it appears out of the plot area.
http://imageshack.us/a/img827/1087/datalabels.png
I imagine is partly due to the number of data points (I tried another chart with fewer data points and it works OK). What is the best way to approach this so that the data labels appear within the plot area?
I read the section on data label tuning and I will increase the spacing to 10 pixels, but I assume data labels will still appear out of the area, but may appear more readable.
Are we talking about the "0.5" and "1.5" labels at the start and end of the red plot line? Those are appearing 5 pixels (by default) above (90 degrees) those data points, by default, with bottom/center alignment. And the issue is that they are partly off the left and right sides of the plot area, correct?
No, I don't think we are going to fix it by adjusting the label tuning parameters. If you change the angle, one will be in and the other further out. Increasing the label distance is just going to move them up.
Probably you need a little more space along the X axis at both ends. You don't have X axis labels on the plot so I don't know what you are working with now. Are you setting the X scale with SetPlotAreaWorld() or is PHPlot calculating it? If you are setting it, can you make it bigger? This leaves more room for labels. If PHPlot is automatically calculating the range, it is still possible to adjust it (with PHPlot-6.0 and up), but if the left side is x=0 that makes it harder.
Thanks for the prompt reply.
Yes, the data labels are the ones you mentioned at default settings.
The X axis is based on date, and calculated automatically. I shall have a look at the manual re SetPlotAreaWorld()
Last edit: Mark 2013-06-05
Just to see what it does, before trying SetPlotAreaWorld() to manually set the range, you might try:
This should make sure there is a space of at least 5% of the axis range between the maximum X value and the tick mark at the end of the X axis. You can adjust that number up or down as needed.
It won't help on the left side of the axis, though. I need to think about that one some more.
Nothing apppears to happen to the axis when I add TuneXAutoRange.
I believe this is because, and is complicated by, the fact that I overlay plots? I utilise multiple SetPlotAreaWorld() to reset the plot area.
Last edit: Mark 2013-06-08
If you are already using SetPlotAreaWorld() to set Xmin and Xmax along the axis (1st and 3rd arguments), then TuneXAutoRange() does not apply. You are telling PHPlot what limits to use for X, so there is nothing for it to tune or calculate. If this is the case, I think you just need to increase your Xmax and decrease Xmin to leave a little more room on the sides.
Or, if you are using SetPlotAreaWorld() but only to set Y limits, not X, then TuneXAutoRange() should have changed the result.
All this assumes your data array has X values. If not, and you are using text-data as the data type (implied X values), then the range for X will simply be 0 to N, where N is the number of rows (number of X values). In this case, the extra margin space on each end will decrease as the number of rows increases. You can increase this margin space along X with SetPlotAreaWorld(-K, NULL, N+K). Again - this is only for 'text-data' data type.