Hello first of all thanks so much for creating phplot- it is a terrific libary!
What I'm trying to do is create a single y-axis data label for a candlestick chart similar to this pic: http://i.imgur.com/B4PCmLg.png where the axis data label of 628.00 represents the last closing price.
I need it to be an "axis data label", and not a "value data label" so that the positioning of the label should be on the y-axis and not within the plot itself like a custom value data label does.
The tick labels also need to be preserved, as in the chart. From reading phplot documentation I am realizing that in order for the tick labels to be preserved, that I may need to do a plot overlay (2 plots) so that the last closing price axis data label "paints over" the y-axis tick data labels, if necessary, in the appropriate position.
Is it possible to do this in phplot and if so what is the best way to do so? Thanks so much. :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Wow an amazing and elegant solution to a very tedious problem! I can't thank you enough lbayuk- you're the best! I would have never thought to use an annotation (still learning phplot) which as I understand it, is akin to drawing a string that paints over elements of the plot when necessary.
Although admittedly I've not yet delved into the specifics of your solution, I assume basically that you're determining the position of the last closing price based on the ratio of where it should fall within the y-axis plot area based on the range of data values in the array, if that makes sense.
And here I was trying to hack the protected function "CheckDataValueLabels" in the phplot core file a la changing it to this line: $this->GetTextAlignment(-$sin, $cos, $dvl['h_align'], $dvl['v_align']); and then using a hard-coded x-offset to horzontally shift the last y-data label onto the y-axis. And then of course writing a custom callback function to only display the last y-data label.
The problem with this approach is twofold:
1.) The x-offset distance required to get the label to the y-axis is dependent on the amount of candlesticks in the graph.
2.) It will paint over an existing tick label causing the display of the labels to appear jumbled as the y-value data label will appear right on top of an existing y-axis tick label.
Man I know it was a lot of code for such a seemingly simple result, but if it's any consolation I feel like you've brought some important new functionality to phplot! It is nice that there's now a way to highlight the most recent, and often times the most relevent data element in a chart this way.
Again thank you so much, I do really appreciate you rather elegant solution and I indebted to you for taking the time to help me! :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello first of all thanks so much for creating phplot- it is a terrific libary!
What I'm trying to do is create a single y-axis data label for a candlestick chart similar to this pic: http://i.imgur.com/B4PCmLg.png where the axis data label of 628.00 represents the last closing price.
I need it to be an "axis data label", and not a "value data label" so that the positioning of the label should be on the y-axis and not within the plot itself like a custom value data label does.
The tick labels also need to be preserved, as in the chart. From reading phplot documentation I am realizing that in order for the tick labels to be preserved, that I may need to do a plot overlay (2 plots) so that the last closing price axis data label "paints over" the y-axis tick data labels, if necessary, in the appropriate position.
Is it possible to do this in phplot and if so what is the best way to do so? Thanks so much. :)
It sounds more like a plot 'annotation' than an axis label. I'll give it a try and post back.
I used a callback to draw a label at the right position. It works, but it seems like a lot of code, for just one little label...
The script and image are here: [wiki:annotated_candlesticks]
Related
Wiki: annotated_candlesticks
Wow an amazing and elegant solution to a very tedious problem! I can't thank you enough lbayuk- you're the best! I would have never thought to use an annotation (still learning phplot) which as I understand it, is akin to drawing a string that paints over elements of the plot when necessary.
Although admittedly I've not yet delved into the specifics of your solution, I assume basically that you're determining the position of the last closing price based on the ratio of where it should fall within the y-axis plot area based on the range of data values in the array, if that makes sense.
And here I was trying to hack the protected function "CheckDataValueLabels" in the phplot core file a la changing it to this line: $this->GetTextAlignment(-$sin, $cos, $dvl['h_align'], $dvl['v_align']); and then using a hard-coded x-offset to horzontally shift the last y-data label onto the y-axis. And then of course writing a custom callback function to only display the last y-data label.
The problem with this approach is twofold:
1.) The x-offset distance required to get the label to the y-axis is dependent on the amount of candlesticks in the graph.
2.) It will paint over an existing tick label causing the display of the labels to appear jumbled as the y-value data label will appear right on top of an existing y-axis tick label.
Man I know it was a lot of code for such a seemingly simple result, but if it's any consolation I feel like you've brought some important new functionality to phplot! It is nice that there's now a way to highlight the most recent, and often times the most relevent data element in a chart this way.
Again thank you so much, I do really appreciate you rather elegant solution and I indebted to you for taking the time to help me! :)