Recent

Author Topic: charting line and bar with 2 seperate y axis  (Read 11353 times)

jw

  • Full Member
  • ***
  • Posts: 126
charting line and bar with 2 seperate y axis
« on: January 31, 2012, 10:58:03 pm »
plotting stock price and volume.

1) need to know howto associate stock_price (line series) with the left axis  and the volume (bar series) with the right axis and not have the volume with very large values of 10000 resize the chart so that the stock price is so small it cannot be found.

2)the x axis bottom axis is DateTimeIntervalChartSource1 in this I have set datetimeformat as  dd:mm:yyyy = 31/1/2012.  Can this be altered to accept date formats as month day year like so mmm/dd/yyyy = jan/31/2012 or even dateimes of     
tuesday, January 18, 2012

3)while zooming reguardless of fixedpoint being set true or false it still zooms relative to the mouse click shouldn't fixedpoint=false zoom to the center if the plot?

4)how do I limit zoom to actual data on the chart currently it will zoom out and zoom in forever and setting only to dtsmonth, dtsday,dtsyear true and all other false crashes the running program and the ide and doesn't give the tahart an idea of when the start point an endpoint is nor that I don't have datapoints for hours mins seconds so don't keep zooming.


5) I'm lost on the idea of having marks and source for each axis and having the same properties available to the line series and bar series What do the marks and source properties do in the lineseries and barseries everytime I try and mess with them is makes things worse.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: charting line and bar with 2 seperate y axis
« Reply #1 on: February 01, 2012, 03:37:22 pm »
Quote
need to know howto associate stock_price (line series) with the left axis  and the volume (bar series) with the right axis
Use AxisIndexY property

Quote
Can this be altered to accept date formats as month day year like so mmm/dd/yyyy
I do not understand -- did you try it? What did not work?

Quote
shouldn't fixedpoint=false zoom to the center if the plot?
Yes, it moves the point you clicked to the center of the plot.

Quote
how do I limit zoom to actual data
Hm, currently there is no built-in way to do this.
You can, however, handle OnExtentChanged event and limit the extent
by your code.

Quote
What do the marks and source properties do in the lineseries and barseries
"Marks" property describes the marks which may be displayed for each point.
"Source" property describes the data which series represents.
Basic series have built-in sources, so you need not concern yourself
with this property for simple cases.

I advise you to look at the various demo programs --
you can find them in the "demo" folder.

jw

  • Full Member
  • ***
  • Posts: 126
Re: charting line and bar with 2 seperate y axis
« Reply #2 on: February 01, 2012, 08:04:51 pm »
1) I'm still working out axisindexy added tchartaxistransformation gave it auto.  went to the left axis added the tchartaxisstransformation to it.  My left axis is 0 when I set the barseries axisindexy to 0 the ide throws foating point error ignore and risk data corruption so I'm still working that out

2)yes I tried different date formats dd:mm:yyyy = 31/1/2012 works setting the datetimeformat property to dd:mmm:yyyy = 31-jan-2012 at runtime I get the error invalid datetime.  Excel has a ton of different datetime settings since I have data for 1 day I thought it would be nice if while zooming in I could use a datetime format of tuesday, January 18, 2012.  Of course I can see where that format may not be supported.  So basically I would go into excel and format all my datetimes to different types and see if I could get the chart to display them.  It refuses the datetime where the month is in the form jan feb mar .... but is ok with month values of numerical form.  However it could also be the code is fine with slashes / but not dashes - 
dd:mmm:yyyy may work for 01/feb/2012
dd:mmm:yyyy but not for 01-feb-2012
I'll continue looking at this..



3) from the wiki
If FixedPoint is true, the location of the mouse click is used as a fixed point for zooming, otherwise chart image center is used instead.

I'm saying fixpoint true or false still set's the mouselick point to the center of the chart.


4) ok will look try it when I get to that point

5) so these properties have to do with showpoints = true and when the mouse hovers it's popup box displays axis info?



jw

  • Full Member
  • ***
  • Posts: 126
Re: charting line and bar with 2 seperate y axis
« Reply #3 on: February 01, 2012, 09:13:58 pm »
1) changing just the axisindexy does nothing using the tchartaxistransformation and setting everything causes the flaoting point error then unassigning the axis and removing tchartaxistransformation doesn't allow the series to be displayed it corrupts the entire project somehow.

2) After playing with the datetime it appears it's not the dash or slash, it just doesn't like strings for months ie 12/jan/2012 won't work nor will 12-jan-2010 so I assume the jan is considered an invalid datetime.


version 09.30.3
date 2011-12-16
fpc 2.4.4
svn 33536

I couldn't find the tachartlazaruspkg in the svn anywhere to backport to a more stable IDE so the other day I downloaded the current svn IDE.

 

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: charting line and bar with 2 seperate y axis
« Reply #4 on: February 05, 2012, 03:54:58 pm »
Quote
1) changing just the axisindexy does nothing using the tchartaxistransformation and setting everything causes the flaoting point error then unassigning the axis and removing tchartaxistransformation doesn't allow the series to be displayed it corrupts the entire project somehow.
Sorry, I can not parse this sentence. Please post example project if you want further help on this.

Quote
2) After playing with the datetime it appears it's not the dash or slash, it just doesn't like strings for months ie 12/jan/2012 won't work nor will 12-jan-2010 so I assume the jan is considered an invalid datetime.
Hm. Are you sure you understand the difference between date parsing
(which has nothing to do with TAChart) and date display (which works
for me, including "dd-mmm-yyyy" format)?

Quote
version 09.30.3
This is the not the latest version, this is "fixes" branch.
Use "trunk" version to get the latest code.

Quote
Quote
how do I limit zoom to actual data
Hm, currently there is no built-in way to do this.
You can, however, handle OnExtentChanged event and limit the extent
by your code.
Since r35141 you can use ExtentSizeLimit property for this.

jw

  • Full Member
  • ***
  • Posts: 126
Re: charting line and bar with 2 seperate y axis
« Reply #5 on: February 07, 2012, 08:53:38 pm »
Ask I do thank you for you help, but let me start again.


I grabbed the svn trunk version using tortoisesvn however I can not varify what version it is because I do not know how.  How can I prove it's version r35141


>Are you sure you understand the difference between date >parsing (which has nothing to do with TAChart) and date display >(which works for me, including "dd-mmm-yyyy" format)?


here I can say I surely do not understand.  How can a date being represented as a string be converted to double in order to get addxy to work without using strtodatetime which is what you are saying is at fault.

here's some code

Code: [Select]
var
  date:string;       // this is read from a csv text file assigned as text
                            // but for this example it's just a string
begin
  date:='7-feb-2010';
  datetimeintervalchartsource1.DateTimeFormat := 'dd-mmm-yyyy';
  chart.addxy(date,5);
end;


this will fail at compile time with got ansistring expected Double

currently my code looks like

Code: [Select]
var
  date:tdatetime;
begin
  date:=strtodatetime('7/2/2010');
  datetimeintervalchartsource1.DateTimeFormat := 'dd-mm-yyyy';
  chart.addxy(date,5);
end



this works but then fails not because of tachart but because of the limiting factor of the datetimeformat command. So how should I be doing this.


also if i'm plotting dates and I have a point for 1/1/2012 then the next point isn't until 3/1/2010 the axis fills in the DateTimeIntervalChartSource1 with dates for 1/2/2013 when I need it to not display that date.  When plotting stocks the market is closed weekends and holidays therefore the chart should not put those dates on the axis and currently it does.

the rest of the questions still have to do with me failing to plot a tbarseries and a tlineseries on 2 seperate y axis on the same chart.  However your axisdemo does something like what I need so I'm thinking I want to leave that question until I uninstall and reinstall lazarus and backport the newest tachart.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: charting line and bar with 2 seperate y axis
« Reply #6 on: February 08, 2012, 06:38:54 pm »
Quote
I can not varify what version it is because I do not know how
After performing svn update the last line in the update dialog contains the revision number.
The important point is to make sure you are using trunk and not fixes branch.

Quote
here I can say I surely do not understand.  How can a date being represented as a string be converted to double in order to get addxy to work without using strtodatetime which is what you are saying is at fault.

What I am saying is that to learn how to control format
of the parsed date you need to read documentation on StrToDateTime
(or StrToDate which seems sufficient in your case).
Setting "datetimeintervalchartsource1.DateTimeFormat" does not have any
influence on StrToDate.

As for month names, they are indeed not supported by StrToDate --
so your options are to either parse such dates yourself or ask
FPC developers to improve StrToDate.

Quote
also if i'm plotting dates and I have a point for 1/1/2012 then the next point isn't until 3/1/2010 the axis fills in the DateTimeIntervalChartSource1 with dates for 1/2/2013 when I need it to not display that date.

If you only want to hide the axis mark, you can do this
from OnGetMarkText event handler.
If, however, you want to create truly non-linear timeline, then it is more complex.
Basically, you can either abandon DateTimeIntervalChartSource and format
axis marks yourself, or implement custom axis transformation which
"compresses" weekend intervals to near-zero width.

jw

  • Full Member
  • ***
  • Posts: 126
Re: charting line and bar with 2 seperate y axis
« Reply #7 on: February 08, 2012, 07:37:19 pm »
At this point it seems the best way to do it would be to format
axis marks myself. 

pulling apart the axisdemo it looks like all I need is a tlistchartsource.  Drop the addxy commands and load all data to the tlistchartsource using

tlistchartsource.datapoints.Append('7|60000|?|nextpoint'); 

the question I have is what's the ? in the above string do.  what's the idea behind string formatting for the tlistchartsource?
« Last Edit: February 08, 2012, 09:18:24 pm by jw »

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: charting line and bar with 2 seperate y axis
« Reply #8 on: February 09, 2012, 12:20:16 am »
See http://wiki.lazarus.freepascal.org/TAChart_documentation#List_source

Quote
what's the ? in the above string do
It is a point color.

Quote
what's the idea behind string formatting for the tlistchartsource?
The idea is to allow design-time editor for the data points.
It is not recommended to use DataPoints property at run-time.
tlistchartsource.datapoints.Append('7|60000|?|nextpoint');
is just a slower version of
tlistchartsource.Add(7, 60000, 'nextpoint');

jw

  • Full Member
  • ***
  • Posts: 126
Re: charting line and bar with 2 seperate y axis
« Reply #9 on: February 09, 2012, 04:03:42 am »
ok I've recoded with custom axismarks along the xaxis that solves alot of the problems.

Now I'm left with associating volume with the right yaxis and price with the left yaxis.   I did try assiciating left and right axis to the custom axises of price and volume but it looks like the ophideneighbor is not working on the y axis also the chart is rescaled to volume and the price is so small compared to the volume it plots a line for it.

Also I don't understand the difference between the bottom and left axis as part of the tchart properties and the axislist where more axis can be added.  Why is there a permanant bottom and left axis on the tchart.   


At this point the program can be gotten at the link

http://jwfiledump.webuda.com/jwstock.zip

also !!!

how does one use code to say
chart.bottomaxis.Marks.overlappolicy:=opHideNeighbor;
or
chart.bottomaxis.Marks.overlappolicy:=opIgnore;

CM630

  • Hero Member
  • *****
  • Posts: 1652
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: charting line and bar with 2 seperate y axis
« Reply #10 on: September 12, 2012, 01:46:27 pm »
how does one use code to say
chart.bottomaxis.Marks.overlappolicy:=opHideNeighbor;
or
chart.bottomaxis.Marks.overlappolicy:=opIgnore;
I came to that, too. Overlap policy is adjustabel trough the IDE, but when I try to do in in the source editor, opHideNeighbor and opIgnore are not recognized?
opIgnorea=0 and opHideNeighbor=1, but
Code: [Select]
chart.bottomaxis.Marks.overlappolicy:=1 returns an error.
« Last Edit: September 12, 2012, 02:11:42 pm by paskal »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: charting line and bar with 2 seperate y axis
« Reply #11 on: September 12, 2012, 03:12:06 pm »
Add TATextElements unit to the "uses" clause

CM630

  • Hero Member
  • *****
  • Posts: 1652
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: charting line and bar with 2 seperate y axis
« Reply #12 on: September 13, 2012, 07:40:47 am »
Fatal: Can not find unit tatextelements used by unit 1
There is no file tatextelements in the entire Lazarus folder, not a file, containing that string.
« Last Edit: September 13, 2012, 09:07:01 am by paskal »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: charting line and bar with 2 seperate y axis
« Reply #13 on: September 13, 2012, 09:58:55 am »
Oh, you are using 1.0, not trunk.
Add "TATypes" unit instead.

 

TinyPortal © 2005-2018