PureBasic Forum
https://www.purebasic.fr/english/

[Module] Chart - Gadget
https://www.purebasic.fr/english/viewtopic.php?f=27&t=73000
Page 1 of 6

Author:  Thorsten1867 [ Tue Jun 11, 2019 7:20 pm ]
Post subject:  [Module] Chart - Gadget

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:
; 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

Author:  VB6_to_PBx [ Wed Jun 12, 2019 8:22 am ]
Post subject:  Re: [Module] Bar Chart - Gadget

Thorsten1867 , thank you very much, your Bar Chart Gadget Module looks and works great ! :D

Author:  Lord [ Wed Jun 12, 2019 11:45 am ]
Post subject:  Re: [Module] Bar Chart - Gadget

Hi!

Quote:
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:
      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:
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?

Author:  Thorsten1867 [ Wed Jun 12, 2019 12:16 pm ]
Post subject:  Re: [Module] Bar Chart - Gadget

I just tried it again and it worked.

(Do you have the latest version? Is "#Example = 0" set?)

Author:  Thorsten1867 [ Wed Jun 12, 2019 1:11 pm ]
Post subject:  Re: [Module] Bar Chart - Gadget

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.

Author:  Thorsten1867 [ Wed Jun 12, 2019 4:49 pm ]
Post subject:  Re: [Module] Bar Chart - Gadget

Update:
  • Added: Support of negative values
  • Added: Attribute '#ScaleSpacing' (#Single/#Double) for the automatic calculation of the number of scale lines
Image

Author:  Lord [ Wed Jun 12, 2019 6:24 pm ]
Post subject:  Re: [Module] Bar Chart - Gadget

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.

Author:  Thorsten1867 [ Wed Jun 12, 2019 6:57 pm ]
Post subject:  Re: [Module] Bar Chart - Gadget

The new version should avoid this problem.

Author:  Lord [ Wed Jun 12, 2019 7:17 pm ]
Post subject:  Re: [Module] Bar Chart - Gadget

Thorsten1867 wrote:
The new version should avoid this problem.
Now it seems to work properly.

Author:  RSBasic [ Wed Jun 12, 2019 8:03 pm ]
Post subject:  Re: [Module] Bar Chart - Gadget

Very nice, thank you! Good job!

Author:  Thorsten1867 [ Sun Jun 16, 2019 6:27 pm ]
Post subject:  Re: [Module] Bar Chart - Gadget

Update:
  • HinzugefĆ¼gt: Pie Charts
Image

( Finding out whether the mouse clicked in a circle sector was a real mathematical challenge. 8) )

Author:  Andre [ Sun Jun 16, 2019 10:11 pm ]
Post subject:  Re: [Module] Chart - Gadget

Well done, thank you! :D

Author:  Thorsten1867 [ Tue Jun 18, 2019 10:45 am ]
Post subject:  Re: [Module] Chart - Gadget

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

Author:  zikitrake [ Tue Jun 18, 2019 11:46 am ]
Post subject:  Re: [Module] Chart - Gadget

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!

Author:  Thorsten1867 [ Tue Jun 18, 2019 12:26 pm ]
Post subject:  Re: [Module] Chart - Gadget

A chart with horizontal bars and a line chart are planned.

Page 1 of 6 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/