Help with ChartView (Jeremy Leroy)

Hi,

I have an array with month names and corresponding values.

The array looks good in the debugger:

I use following code but nothing displays (only empty chart)

[code] ChartView1.Type = ChartView.TypeColumn

ChartView1.Freeze = True
ChartView1.LoadFromCSV(Join(GraphArray,EndOfLine), False,",", True, False)

ChartView1.setTransparency(10)
ChartView1.LegendPosition = ChartView.Position.Right[/code]

Two things. Your LoadFromCSV line can change to simply:

ChartView1.LoadFromCSV(Join(GraphArray, EndOfLine))

as the remaining parameters are all the defaults. That is not the problem though.

At the bottom of your code, simply add the line:

ChartView1.Redisplay

and all should be good.

Hi Jeremy,

thanks for your input, but the graph’s still empty.

Code:

[code]Sub Open()
'declare vars
Dim maandArray() As String
Dim valueArray() as String
Dim scoreArray() as String
Dim graphArray() as String
dim rs as recordset

'fill arrays
maandArray = Array(“jan”,“feb”,“mar”,“apr”,“mei”,“jun”,“jul”,“aug”,“sep”,“okt”, “nov”,“dec”)
scoreArray = Array(“0”,“0”,“0”,“0”,“0”,“0”,“0”,“0”,“0”,“0”,“0”,“0”)

'scoreArray corresponds with maandarray

'create recordset
rs = app.db.SQLSelect(“select * from LOG”)

while not rs.eof
'fill temporary array with date strings
'split on “-”
dim anArray() as String
anArray = Split(rs.field(“Entry”).StringValue, “-”)

'store the second string (the month) in the temporary array
valueArray.append(anArray(1))
rs.movenext

wend

'scan the values into a dictionary
'count the values of each month

dim dict As new Dictionary
dim s As String
for i As integer = 0 to valueArray.Ubound
s = valueArray(i)
dict.Value(s) = dict.Lookup(s, 0) + 1
next

'add the month values to the corresponding month

dim keys() as variant = dict.Keys
for i as integer = 0 to keys.Ubound
scoreArray(Val(keys(i))-1) = dict.value(keys(i))
next

graphArray.append(“Date, Score” + EndOfLine)
for i as integer = 0 to maandArray.Ubound
graphArray.append(maandArray(i) + “,” + scoreArray(i) + EndOfLine)
next

ChartView1.Type = ChartView.TypeColumn

ChartView1.Freeze = True
ChartView1.LoadFromCSV(Join(GraphArray,EndOfLine))

ChartView1.setTransparency(10)
ChartView1.LegendPosition = ChartView.Position.Right
ChartView1.Freeze = False

ChartView1.StartAnimation(True, ChartAnimate.kEaseOutBounce)
ChartView1.Redisplay
End Sub
[/code]

Here was the code I took from your previous example:

  Dim c As ChartView = PlotChartView
  
  c.Type = ChartView.TypeColumn
  c.LoadFromCSV("Date, Score" + EndOfLine + "jan,0" + EndOfLine + "feb,3" + EndOfLine + "mar,2", False, ",", True, False)
  c.setTransparency(10)
  c.LegendPosition = ChartView.Position.Right
  c.Redisplay

and that produces a graph. Does it produce a graph on your end?

Oh, I see the error w/your current chart. You are appending an EndOfLine to graphArray:

    graphArray.append(maandArray(i) + "," + scoreArray(i) + EndOfLine)

and then joining that array by an EndOfLine also.

  ChartView1.LoadFromCSV(Join(GraphArray,EndOfLine))

Try removing the + EndOfLine from your .Append line. Your chart code then works for me as posted above (well, I took out the database query and simply filled in some fake values in the = Array("2", "4", "6", ...) line towards the top.

Yes! That did the trick.

Many thanks. I must say that the ChartView component is great but the examples/documentation could us an overhaul.

Yeah, I am enjoying them quite a bit but your right. Talking with Jeremie, the product is only 1 yr old, so it still has some room to grow. Maybe as us users figure things out we can help each other. When evaluating the product he fixed a few bugs that I found rather quickly, which was nice. If you have the source version, I know he has no problems accepting bug fixes/patches as well. Seems the docs are generated from the source, so once something is figured out, one could add to the documentation so they don’t forget and so the next person doesn’t have to figure it out.

I think they will continue to mature rather quickly though. It is a pretty nice package.

I also have ChartView and was a bug tester for him. I found a few important bugs which he eventually corrected, but then I stopped getting responses?

I got responses pretty quickly and a few bugs I found were fixed within a day, by the end of the week a new release was made. Unsure of the difficulty you were having, hope it does not come around to that. I also submitted a bug fix that was applied.

I sent in a couple of support questions and never received any replies. After waiting a couple of weeks I gave up and pulled the controls from my project.

Me too. I had a problem and my support question was never answered, so I now do not use it at all.

I’d love to see some demo code how to add values to a serie or series. In his demo project it is always LoadFromCSV() but there are several alternative ways to do it. Hard to figure out.

One option is to have Jeremy update his Wiki as I there are a ton of items that are not documented. A second option is to purchase the unlock code to the source code which will give you a better idea of what is possible.

Here is a simple example:

  ChartView1.Type = ChartView.TypeLine
  ChartView1.Axes(0).Title = "Month"
  ChartView1.Axes(0).Label.Append "Jan"
  ChartView1.Axes(0).Label.Append "Feb"
  ChartView1.Axes(0).Label.Append "Mar"
  
  ChartView1.Axes(1).Title = "Inches"
  
  dim snow as new ChartSerie
  snow.Title = "Snow"
  snow.Values.Append 10.5
  snow.Values.Append 12.8
  snow.Values.Append 4.3
  
  ChartView1.Series.Append  snow
  
  ChartView1.Redisplay

I was trying to do that, but have no idea how to replace snow.Values.Append 10.5 for example, with a database result.
Would be great if I knew how to load the results from a database and display that as a chart.

I also could not work out how to make the springy animation effect work?

For animation, replace ChartView1.Redisplay with ChartView1.StartAnimation(True, ChartAnimate.kEaseOutBounce) for example.

As for loading from a database, that would largely depend on what type of data you are loading, but basically you’d do something like:

dim rs as RecordSet = db.SQLSelect("SELECT month, snow FROM data")
if db.Error Then
  // Handle the error
end if

while not rs.EOF
  ChartView1.Axes(0).Label.Append rs.Field("month").StringValue
  snow.Values.Append rs.Field("snow").DoubleValue

  rs.MoveNext
wend

Thank you very much Jeremy.
Do you mean something like this?:

[code]ChartView1.Type = ChartView.TypeLine

ChartView1.Axes(0).Title = “Month”
ChartView1.Axes(1).Title = “Inches”

dim snow as new ChartSerie
snow.Title = “Snow”

dim rs as RecordSet = db.SQLSelect(“SELECT month, snow FROM data”)
if db.Error Then
// Handle the error
end if

while not rs.EOF
ChartView1.Axes(0).Label.Append rs.Field(“month”).StringValue
snow.Values.Append rs.Field(“snow”).DoubleValue

rs.MoveNext
wend
ChartView1.StartAnimation(True, ChartAnimate.kEaseOutBounce)[/code]

If this looks correct - what version of ChartView does this code work on; is it only for the latest version - or do you have an older version?

[quote=130010:@Richard Summers]Thank you very much Jeremy.
Do you mean something like this?:

… snip …

If this looks correct - what version of ChartView does this code work on; is it only for the latest version - or do you have an older version?[/quote]

Yes, that looked good. I am using 1.4.5. That introduced a change to the Value settings. You may need to use getValue or setValue, I am not too sure about older versions of ChartView.

When you say - I may need to use getValue / setValue - where are you talking about?
Thanks.

[quote=130013:@Richard Summers]When you say - I may need to use getValue / setValue - where are you talking about?
Thanks.[/quote]

I forget what they were called before 1.4.5. But the .Values() was known by something different. I just don’t have enough experience with prior versions. Tab completion should bring up an obvious choice.

I will upgrade to the same version as you, as soon as I am fully confident that I can load listbox / database entries :slight_smile:
Thanks.