ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Finance Chart (1) 的 setData failed
Posted by tallhill on Nov-01-2017 13:57
用chartDir 的com版本
用第三方语言运行Candlestick Chart 的例子是OK的
运行 Finance Chart (1)的就不行,提示setData 下标越界

我看了一下两个例子的差别。
一个是  c.addCandleStickLayer(highData, lowData, openData, closeData, &H00ff00, &Hff0000)

一个是c.setData(timeStamps, highData, lowData, openData, closeData, volData, extraDays)

我想问一下这两个函数的内部有什么差异吗?为什么同样的数据,上一个就可以赋值,下一个就下标越界呢?

  Re: Finance Chart (1) 的 setData failed
Posted by Peter Kwan on Nov-01-2017 20:13
Hi tallhill,

Is it possible the issue is caused by the "timeStamps", "volData" or "extraDays"? There 3 parameters are not in the XYChart.addCandleStickLayer.

The timeStamps and volData should be arrays, and they should be of the same size as closeData.

The timeStamps must contain date/time. Note that a text string is not a date in VB syntax. For example, "2017-1-1" is not a date (it is a text string). DateSerial(2017, 1, 1) is a date according to VB syntax.

The extraDays must be a number. For testing, you may set the extraDays to 0.

(Note: In the "CandleStick Chart" sample code, the x-axis contains "labels", which are an array of text strings. In the Finance Chart (1) sample code, the "timeStamps" are date/time, not labels. ChartDirector will automatically determine the labels using the date/time.)

If the above still cannot solve the problem, is it possible to provide me with the exact error message or provide a screen shot of the error?

Regards
Peter Kwan

  Re: Finance Chart (1) 的 setData failed
Posted by tallhill on Nov-02-2017 08:13
Attachments:
不是vb调用,是第三方支持com的软件。
我尝试几种方式,
t=cd.chartTime(2017,1,1)
tlist={t}
hlist={2017}
llist={2017}
olist={2017}
clist={2017}
dlist={2017}
vlist={2017}
c.setData(tlist, hlist, llist, olist, clist, vlist,0)

也是不行。

highData ={2043;2039;2076;2064;2048;2058;2070;2033;2027;2029;2071;2085;2034;
     2031;2056;2128;2180;2183;2192;2213;2230;2281;2272}
lowData = {1931;1921;1985;2028;1986;1994;1999;1958;1943;1944;1962;2011;1975;
     1962;1928;2059;2112;2103;2151;2127;2123;2152;2212}
openData = {2000;1957;1993;2037;2018;2021;2045;2009;1959;1985;2008;2048;2006;
     2010;1971;2080;2116;2137;2170;2172;2171;2191;2240}
closeData = {1950;1991;2026;2029;2004;2053;2011;1962;1987;2019;2040;2016;1996;
     1985;2006;2113;2142;2167;2158;2201;2188;2231;2242}
    volData = {1950;1991;2026;2029;2004;2053;2011;1962;1987;2019;2040;2016;1996;
     1985;2006;2113;2142;2167;2158;2201;2188;2231;2242}
timeStamps = {"Mon 1";"Tue 2";"Wed 3";"Thu 4";"Fri 5";"Mon 8";"Tue 9";"Wed 10";"Thu 11";
     "Fri 12";"Mon 15";"Tue 16";"Wed 17";"Thu 18";"Fri 19";"Mon 22";"Tue 23";"Wed 24";
     "Thu 25";"Fri 26";"Mon 29";"Tue 30";"Wed 31"}

c = cd.FinanceChart(640)

c.addTitle("Finance Chart Demonstration")

c.setData(timeStamps, highData, lowData, openData, closeData, volData, 0)

用demo里的数据也不行。

报错的信息就是 com exception,下标越界。
微信图片_20171102081201.png

  Re: Finance Chart (1) 的 setData failed
Posted by tallhill on Nov-03-2017 01:18
问题解决了。
我用comfinancechart 生成的custom.financechart 控件进行了调试。
第三方软件的array是从1开始,vb的array是从0开始,需要进行一下转换。
代码中的setdata函数修改了一下就可以了。
估计你们的comchartdir.dll是用vb生成的,所以存在这个问题。

Public Sub setData(timeStamps, highData, lowData, openData, closeData, volData, extraPoints)

Dim i As Integer
    Dim arrlen As Integer
    arrlen = UBound(highData)

    ReDim m_highData(arrlen - 1)
    ReDim m_timeStamps(arrlen - 1)
    ReDim m_lowData(arrlen - 1)
    ReDim m_openData(arrlen - 1)
    ReDim m_closeData(arrlen - 1)

    For i = 1 To arrlen
        m_highData(i - 1) = highData(i)
    Next i

    For i = 1 To arrlen
        'm_timeStamps(i - 1) = cd.CTime(timeStamps(i))
        m_timeStamps(i - 1) = timeStamps(i)

        Debug.Print timeStamps(i)
        Debug.Print m_timeStamps(i - 1)
    Next i

    For i = 1 To arrlen
        m_lowData(i - 1) = lowData(i)
    Next i

    For i = 1 To arrlen
        m_openData(i - 1) = openData(i)
    Next i

    For i = 1 To arrlen
        m_closeData(i - 1) = closeData(i)
    Next i
    If extraPoints > 0 Then
        m_extraPoints = extraPoints
    Else
        m_extraPoints = 0
    End If

  Re: Finance Chart (1) 的 setData failed
Posted by Peter Kwan on Nov-03-2017 02:03
Hi tallhill,

In ChartDirector, the array index starts from 0. For example, if the array contains 3 elements {111;222;333}, the array index should be 0, 1, and 2.

In COM technology, the array index can be configured to start from other values as well. For example, the array above can have index 1, 2, 3 or 99, 100, 101 or any 3 consecutive numbers. All these type of indexing are not common nowadays and are not supported by ChartDirector.

For your case, you are using something like "{111;222;333}". I assume your programming language will change it into a COM array. But is the array index begins from 0? Is it possible the array index starts from 1, which is not supported by ChartDirector and will cause "index out of bounds" exception?

If the array index starts from 1, is it possible to configure your language to make the array index starts from 0? (In VB, by default the array index starts from 0. You can also use "Option Base 0" to configure the array index starting value. I hope in your language this is also possible.)

Or it is possible for your language to do something equivalent to:

'Declare an array that starts from 0
Dim t(0 To 3)
t(0) = cd.chartTime(2017,1,1)
t(1) = cd.chartTime(2017,1,2)
t(2) = cd.chartTime(2017,1,3)
t(3) = cd.chartTime(2017,1,4)

Regards
Peter Kwan

  Re: Finance Chart (1) 的 setData failed
Posted by Peter Kwan on Nov-03-2017 04:11
Hi tallhill,

I wrote my last response without seeing your latest post. Since you have already found out the issue (which is the same as what I suspect), please ignore my message.

Regards
Peter Kwan

  Re: Finance Chart (1) 的 setData failed
Posted by tallhill on Nov-03-2017 06:42
同样的array,同样的从1开始,

这个就是支持的 c.addCandleStickLayer(highData, lowData, openData, closeData, &H00ff00, &Hff0000)

这个就是不支持的 c.setData(timeStamps, highData, lowData, openData, closeData, volData, extraDays)

我觉得还是支持比较好。

  Re: Finance Chart (1) 的 setData failed
Posted by tallhill on Nov-03-2017 07:08
Public Sub setData(timeStamps, highData, lowData, openData, closeData, volData, extraPoints)
'    m_timeStamps = cd.CTime(timeStamps)
'    m_highData = highData
'    m_lowData = lowData
'    m_openData = openData
'    m_closeData = closeData

    m_timeStamps = cd.ArrayMath(timeStamps).result()
    m_highData = cd.ArrayMath(highData).result()
    m_lowData = cd.ArrayMath(lowData).result()
    m_openData = cd.ArrayMath(openData).result()
    m_closeData = cd.ArrayMath(closeData).result()

这样修改就比较简单,希望能尽快修改这个问题吧。