Sevral useful function you would like to want
Posted: Mon Dec 26, 2005 6:37 am
hi everybody
when we mouse the mouse ,we want to get the nearest point Value, however, we don't move the mouse on the seriesline.How can we do it.now ,you can use this function ,it's writted in vbsript,i think you can rewrite it in other language,like vb,vb and so on.
if there are some problems,please send e_mail to sx_qfh@hotmail.com
Check this code as next:
First ,Get the ValueIndex of the Xval ,used in the trend Chart
Second.Get YVal of the Current Xval between x1 and x2,used in the wave chart.
when we mouse the mouse ,we want to get the nearest point Value, however, we don't move the mouse on the seriesline.How can we do it.now ,you can use this function ,it's writted in vbsript,i think you can rewrite it in other language,like vb,vb and so on.
if there are some problems,please send e_mail to sx_qfh@hotmail.com
Check this code as next:
First ,Get the ValueIndex of the Xval ,used in the trend Chart
Code: Select all
Function GetSeriesIndex_XVal(seriesIndex,xvals)
dim i,ci
dim xv
xv=xvals
ci=0
for i=0 to TChart1.Series(seriesIndex).count-1
if xv<=TChart1.Series(seriesIndex).xvalues.value(i) then
Exit for
else
ci=i
end if
Next
if ci=-1 then
ci=0
ElseIF ci<TChart1.Series(seriesIndex).count-1 then
if abs(xv-TChart1.Series(seriesIndex).xvalues.value(ci))>abs(xv-TChart1.Series(seriesIndex).xvalues.value(ci+1)) then
ci=ci+1
end if
end if
GetSeriesIndex_XVal=ci
end Function
Code: Select all
Function GetSeriesYValByXVal(tmpindex,xval)
dim i,xi1,xi2,result
dim xv1,yv1,xv2,yv2
result=0
if TChart1.Series(tmpindex).count=0 then exit Function
xi1=0
xi2=0
for i=0 to TChart1.Series(tmpindex).count-1
if xval<=TChart1.Series(tmpindex).xvalues.value(i) then
Exit for
else
xi1=xi2
xi2=i
end if
Next
xv1=TChart1.Series(tmpindex).xvalues.value(xi1)
yv1=TChart1.Series(tmpindex).yvalues.value(xi1)
xv2=TChart1.Series(tmpindex).xvalues.value(xi2)
yv2=TChart1.Series(tmpindex).yvalues.value(xi2)
if xv2<>xv1 then
result=yv1+(xval-xv1)*(yv2-yv1)/(xv2-xv1)
else
result=yv1
end if
GetSeriesYValByXVal=result
end Function