Page 1 of 1

Graph details

Posted: Wednesday 20th June 2018 11:00am
by westconn
here is my new problem, i have created a graph for my data, i am reasonably happy with the result for the data, but i would like to fix some labels and the legend, here is the code i have to date
 hChart = New Chart
 
  hChart.YAxe.ShowIntervalLines = False
  hchart.ShowLabels = True
 hChart.Legend.Position = Align.Right
 hChart.Legend.Visible = True
 hChart.Legend.Title = "Legend"
   hchart.type = ChartType.ColumnsStacked

  hchart.headers.values = ["Uploads", "Downloads"]
  cntofdays = DateDiff(Date, DateAdd(Date, gb.Month, 1), gb.Day)
  hchart.CountDataSets = cntofdays

  hchart.YAxe.MaxValue = 20

  hchart.Colors.Values = [Color.green, Color.Red]
    hchart[0].Text = "Downloads"
  hchart[0].values = [(500 / 30), 0]
  hchart.FirstColumnAsLabel = True
  hchart.Labels   '  i can't seem to do anything at all with the chart labels class
  hchart.Labels[0] = "text"

  sfile = File.Load(smyfile)
  sfile = Trim(sfile)
  afile = Split(sfile, gb.NewLine)
    adt.Resize(32)For i = 0 To Day(Date) - rollover - 1
  aln = Split(afile, gb.Tab)
  adt.Push(Val(aln[0]))
  s = [aln[2], aln[1]]

  hchart[i + 1].Values = s
  Next


the main things i want to fix are the legend text is correct, but the colour boxes do not match the colours used in the graph, and i would like to put a label or similar on the yaxes, i guess i could use a label control over the drawing area, but figure there should be someway to do that within the graph

any help would be appreciated

Re: Graph details

Posted: Thursday 21st June 2018 1:19pm
by cogier
First you need to note that the Chart command has a comment of "This component is not stable yet". I agree that the 'Labels' command seems to do nothing, in fact the syntax 'help' says it is 'Read only'!

I could not get your code to run as it was missing bits, but I took what I could and made effort to get it running and came up with the attached.
but the colour boxes do not match the colours used in the graph
I don't quite understand what the problem is here as it seems to work OK for me.
i guess i could use a label control over the drawing area, but figure there should be someway to do that within the graph
It would be nice but I can't find out how to do this. You might try creating a new Class and add the Labels or hack the Gambas source code and see if you can understand how the Labels are supposed to work.

I expect you have looked at the Chart Example I put on the Gambas Farm.

From what I can work out from your code you seem to have worked out how to use this.

If you could upload a working program including a sample data file that might help.
ChartTest.tar.gz
(13.47 KiB) Downloaded 143 times

Re: Graph details

Posted: Friday 22nd June 2018 11:48am
by westconn
First you need to note that the Chart command has a comment of "This component is not stable yet"
that was about 5 years ago, it looks like the programmer has lost interest in this

here is my code, obviously some stuff is nothing to do with the graph, i will probably move the graphing into a separate procedure later, some comments to explain code for other components not required for testing graph, the code is still a bit messy as i keep trying different things, then do not always remember to remove
Public Sub Form_Open()

 Dim s As Float[]
Dim i As Integer, m As Integer
Dim f As File
Dim sfile As String
Dim afile As String[]
Dim aln As String[]
Dim adt As New Date[]
Dim cntofdays As Integer   ' number of days in month
Dim rollover As Integer = 3  ' first day of month

cntofdays = DateDiff(Date(Year(Date), Month(Date), rollover), DateAdd(Date(Year(Date), Month(Date), rollover), gb.Month, 1), gb.Day)

' probably comment out the tray stuff for testing
htray = New TrayIcon As "myapp"
htray.Visible = True
htray.PopupMenu = Menu1.Name
htray.Show

'timer at this stage only to hide the form to the tray, later to update the data file
timer1.enabled = True
timer1.Trigger

 hchart = New Chart
 
  hchart.YAxe.ShowIntervalLines = False
  hchart.ShowLabels = True
 hchart.Legend.Position = Align.Right
 hchart.Legend.Visible = True
 hchart.Legend.Title = "Legend"
   hChart.type = ChartType.ColumnsStacked
  hChart.Legend
  hChart.headers.values = ["Uploads", "Downloads"]
   hchart.CountDataSets = cntofdays

  hchart.Colors.Values = [Color.green, Color.red]
  
  hchart[0].Text = "Ave. Daily"
  hchart[0].values = [500 / cntofdays, 0]
  hchart.FirstColumnAsLabel = True

  sfile = File.Load("/home/pete/code/abbdaily")  ' see below
  sfile = Trim(sfile)
  afile = Split(sfile, gb.NewLine)
For i = 0 To Day(Date) - rollover - 4 ' the data file should always go to todays date, but for testing purposes it is 3 or 4 days old already, will error if dates run out
  aln = Split(afile, gb.Tab)
  adt.Push(Val(aln[0]))
  s = [aln[2], aln[1]]
  hchart[i + 1].Values = s
  
Next
End
Public Sub DrawingArea1_Draw()
' drawing area on fmain
  hchart.Width = Draw.Width
  hchart.Height = Draw.Height
  hchart.Draw()
End


content of data file

03-06-2018 0.24 4.34
04-06-2018 0.25 3.13
05-06-2018 0.63 6.77
06-06-2018 0.47 6.89
07-06-2018 0.58 6.13
08-06-2018 0.60 7.56
09-06-2018 0.79 4.00
10-06-2018 0.29 2.85
11-06-2018 0.20 3.81
12-06-2018 0.42 6.78
13-06-2018 0.59 6.40
14-06-2018 0.28 5.10
15-06-2018 0.47 3.85
16-06-2018 0.21 3.82
17-06-2018 0.22 4.97
18-06-2018 0.28 12.48
19-06-2018 0.47 3.17

Total Used 6.99 92.04
Used Combined 99.03
Data Left 400.97

Data Left 400.97


on another note, what is maximum delay for timer?

Re: Graph details

Posted: Friday 22nd June 2018 12:10pm
by westconn
I don't quite understand what the problem is here as it seems to work OK for me.
i am not sure why mine do not match, as i see yours are perfect, i will post a screen shot
Screenshot from 2018-06-22 21-58-25.png
Screenshot from 2018-06-22 21-58-25.png (13.78 KiB) Viewed 3924 times
also i note that the screenshot above, the uploads legend looks similar to the data color, on one monitor. on the other screen it looks more like yellow, though the data columns look green, the downloads legend looks purple on the other monitor, data green
your sample matches on both monitors
For Each aln In adt
If Not aln Then Continue
Chart[i + 1].Values = [Val(Split(aln)[0]), Val(Split(aln)[1])]
Inc i
Next
i had not seen this continue before, thanks for that

Re: Graph details

Posted: Friday 22nd June 2018 1:44pm
by stevedee
westconn wrote:
Friday 22nd June 2018 11:48am

...on another note, what is maximum delay for timer?
Timer Delay is an Integer, so max value is 2147483647ms

Re: Graph details

Posted: Saturday 23rd June 2018 1:40pm
by cogier
Two of us have worked on the colour problem and discovered how to get the correct colours to display. In the 'DrawingArea_Draw' routine you need to add a line, see below: -
Public Sub DrawingArea1_Draw()

  Chart.Colors.Values = hChart1.Colors.values ''THIS SEEMS TO BE THE TRICK FOR KEEPNG THE COLOURS CORRECT
  hChart1.Width = Draw.Width
  hChart1.Height = Draw.Height
  hChart1.Draw()

End
The attached program shows two charts, using the same data, but with different colours.
Image
Hope this helps.
take21.tar.gz
(14.74 KiB) Downloaded 146 times

Re: Graph details

Posted: Sunday 24th June 2018 3:49am
by Matthew-Collins
I’ve submitted a Gambas bug see bugtracker 1354

Re: Graph details

Posted: Tuesday 26th June 2018 10:11am
by westconn
Two of us have worked on the colour problem
thank you both, it works for me too, though why did your sample work correctly without?

also thanks to stevedee

is there any way to have vertical text?

Re: Graph details

Posted: Tuesday 26th June 2018 2:16pm
by cogier
though why did your sample work correctly without?
The reason for this is that I used 'Chart' on its own and did not create a new instance. Your code had: -
hChart1 As New Chart
My original code didn't. Have a look at ChartExample on the Farm. I did not create a new instance in that code either. You should only need to do that if you need more that one chart.
is there any way to have vertical text?
Not that I am aware of but I found the attached code written by the original author that you might like to pick apart and see if you can improve it or add extra components.
gb.chart.tar.gz
(57.96 KiB) Downloaded 151 times

Re: Graph details

Posted: Saturday 30th June 2018 12:38pm
by cogier
is there any way to have vertical text?
Have a look at the attached.

Image
Public Sub DrawingArea1_Draw()

Chart.Height = Me.Height - 5
Chart.Width = Me.Width - 5
Chart.Draw

Paint.Translate(128, 128)
Paint.Rotate(Rad(Slider1.Value))
Paint.Translate(-128, -128)

Paint.Font.Name = "Sans"
Paint.Font.Size = 90
Paint.Font.Bold = True
Paint.MoveTo(-250, 135)
Paint.Text("Hello")
Paint.Fill

End
ChartTest.tar.gz
(13.77 KiB) Downloaded 156 times