[Module] Chart - Gadget

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

[Module] Chart - Gadget

Post by Thorsten1867 »

Bar Chart Gadget - Module (all OS / 64Bit / DPI)

Creating pie, bar charts (vertical/horizontal), scatter plot and charts with data series:
  • automatic calculation of bar width (#PB_Default) and distance (#PB_Default) possible
  • automatic adjustment of maximum value (#PB_Default) possible
  • display of horizontal lines (Y-axis) possible
  • display of values, percentages or text in (or above) bar possible
  • support of left, right or double-click events for bars
  • automatic gadget size adjustments
Image

Code: Select all

; Chart::AddItem()             - similar to AddGadgetItem()
; Chart::AttachPopupMenu()     - attachs a popup menu to the chart
; Chart::DisableReDraw()       - disable/enable redrawing
; Chart::EventColor()          - returns the color after the event
; Chart::EventIndex()          - returns the item index after the event
; Chart::EventLabel()          - returns the item label after the event
; Chart::EventValue()          - returns the item value after the event
; Chart::Gadget()              - create a new gadget
; Chart::GetErrorMessage()     - get error message [DE/FR/ES/UK]
; Chart::GetItemColor()        - returns the color of the item
; Chart::GetItemLabel()        - get the label of the item
; Chart::GetItemState()        - similar to GetGadgetItemState()
; Chart::GetItemText()         - similar to GetGadgetItemText()
; Chart::GetLabelState()       - similar to GetGadgetItemState(), but 'label' instead of 'position'
; Chart::GetLabelColor()       - returns the color of the item
; Chart::RemoveItem()          - similar to RemoveGadgetItem()
; Chart::RemoveLabel()         - similar to RemoveGadgetItem(), but 'label' instead of 'position'
; Chart::SetAttribute()        - similar to SetGadgetAttribute()
; Chart::SetAutoResizeFlags()  - [#MoveX|#MoveY|#ResizeWidth|#ResizeHeight]
; Chart::SetColor()            - similar to SetGadgetColor()
; Chart::SetFlags()            - set flags for chart customization
; Chart::SetFont()             - similar to SetGadgetFont()
; Chart::SetItemState()        - similar to SetGadgetItemState()
; Chart::SetItemText()         - similar to SetGadgetItemText()
; Chart::SetLabelState()       - similar to SetGadgetItemState(), but 'label' instead of 'position'
; Chart::SetMargins()          - define top, left, right and bottom margin
; Chart::ToolTipText()         - defines the text for tooltips (#Percent$ / #Value$ / #Label$ / #Serie$)
; Chart::UpdatePopupText()     - updates the menu item text before the popup menu is displayed

; --- Data Series ---

; Chart::AddDataSeries()       - add a new data series
; Chart::AddSeriesItem()       - add a new item to the data series
; Chart::DisplayDataSeries()   - displays the data series
; Chart::EventDataSeries()     - returns the value of the item by index
; Chart::GetSeriesColor()      - returns the color of the data series
; Chart::GetSeriesItemState()  - returns the value of the item by index
; Chart::GetSeriesLabelState() - returns the value of the item by label
; Chart::RemoveSeriesItem()    - removes the item by index
; Chart::RemoveSeriesLabel()   - removes the item by label
; Chart::RemoveDataSeries()    - removes the data series
; Chart::SetSeriesItemState()  - sets the value of the item by index
; Chart::SetSeriesLabelState() 

; --- Scatter Plot ---

; Chart::AddScatterPlot()       - add a new scatter plot
; Chart::AddScatterItem()       - add a new item to the scatter plot
; Chart::DisplayScatterPlot()   - displays the scatter plot
; Chart::EventScatterPlot()     - returns the label of the scatter plot after the event
; Chart::EventDataX()           - returns dataX after the event 
; Chart::EventDataY()           - returns dataY after the event 
; Chart::GetScatterColor()      - returns the color of the scatter plot
; Chart::GetScatterItem()       - returns the value of the item by index [#DataX/#DataY]
; Chart::GetScatterLabelData()  - returns the value of the item by label [#DataX/#DataY]
; Chart::RemoveScatterPlot()    - removes the item by index
; Chart::RemoveScatterItem()    - removes the item by label
; Chart::RemoveScatterLabel()   - removes the data series
; Chart::SetScatterItem()       - sets the values of the item by index
; Chart::SetScatterLabelData()  - sets the values of the item by label
Download: ChartModule.pbi
Last edited by Thorsten1867 on Fri Dec 20, 2019 3:12 pm, edited 10 times in total.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 617
Joined: Mon May 09, 2011 9:36 am

Re: [Module] Bar Chart - Gadget

Post by VB6_to_PBx »

Thorsten1867 , thank you very much, your Bar Chart Gadget Module looks and works great ! :D
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: [Module] Bar Chart - Gadget

Post by Lord »

Hi!
automatic adjustment of maximum value (#PB_Default) possible
A "#PB_default" in "Chart::Gadget(") at "Maximum" doesn't show the first bar, when
a value of 135 is set for "Value" in "Chart::AddItem()".
Tried this with changing the values for the Gadget in your "CompilerDefault" part:

Code: Select all

      CompilerDefault
        Chart::Gadget(#Chart, 10, 10, 280, 180, 0, #PB_Default, Chart::#Border|Chart::#ShowLines|Chart::#ColoredLabels|Chart::#ShowValue|Chart::#AutoResize, #Window)
        Chart::SetAttribute(#Chart, Chart::#ScaleLines, 5)
and

Code: Select all

Chart::AddItem(#Chart, "Bar 1", 135, $FF901E):Debug chart::GetErrorMessage(#chart)
The error message is "Value greater than maximum" and the bar just disappears.
Isn't "#PB_default" meant to adjust the graph according to the maximum value?
Image
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Bar Chart - Gadget

Post by Thorsten1867 »

I just tried it again and it worked.

(Do you have the latest version? Is "#Example = 0" set?)
Last edited by Thorsten1867 on Wed Jun 12, 2019 1:12 pm, edited 1 time in total.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Bar Chart - Gadget

Post by Thorsten1867 »

Update:
  • Added: Attribute '#AdjustMaximum' (#True/#False) to adjust the maximum value, if necessary. (= Default)
If you use 'Chart::SetAttribute(#Chart, Chart::#AdjustMaximum, #False)', then only a percentage is displayed instead of the bar.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Bar Chart - Gadget

Post by Thorsten1867 »

Update:
  • Added: Support of negative values
  • Added: Attribute '#ScaleSpacing' (#Single/#Double) for the automatic calculation of the number of scale lines
Image
Last edited by Thorsten1867 on Fri Dec 20, 2019 3:14 pm, edited 4 times in total.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: [Module] Bar Chart - Gadget

Post by Lord »

Thorsten1867 wrote:...
(Do you have the latest version? Is "#Example = 0" set?)
I downloaded the modul just before I tried.
As CompilerDefault defaults to anything but not 1 to 6, a 0 was set for #Example.
Image
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Bar Chart - Gadget

Post by Thorsten1867 »

The new version should avoid this problem.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: [Module] Bar Chart - Gadget

Post by Lord »

Thorsten1867 wrote:The new version should avoid this problem.
Now it seems to work properly.
Image
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: [Module] Bar Chart - Gadget

Post by RSBasic »

Very nice, thank you! Good job!
Image
Image
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Bar Chart - Gadget

Post by Thorsten1867 »

Update:
  • Hinzugefügt: Pie Charts
Image

( Finding out whether the mouse clicked in a circle sector was a real mathematical challenge. 8) )
Last edited by Thorsten1867 on Fri Dec 20, 2019 3:15 pm, edited 1 time in total.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: [Module] Chart - Gadget

Post by Andre »

Well done, thank you! :D
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Chart - Gadget

Post by Thorsten1867 »

Update:
  • Diagram added for data series
  • Support for popup menus (Chart & Legend) with automatic update of menu item texts (e.g. #Label$ / #Series$)
  • Simplified supply of event data
  • SetAttribute() is partially replaced by SetFlags().
Image
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
zikitrake
Addict
Addict
Posts: 833
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: [Module] Chart - Gadget

Post by zikitrake »

Wow :shock: Another impressive module.
Do you plan to add linear charts to it?
I was thinking about using the fantastic @uwekel code: viewtopic.php?f=14&t=59038,
but yours, as it also has Pie charts, would be more useful to me.

Thanks!
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Chart - Gadget

Post by Thorsten1867 »

A chart with horizontal bars and a line chart are planned.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
Post Reply