[Module] Chart - Gadget

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Ajm
Enthusiast
Enthusiast
Posts: 234
Joined: Fri Apr 25, 2003 9:27 pm
Location: Kent, UK

Re: [Module] Chart - Gadget

Post by Ajm »

Hi Thorsten,

Is there any chance you could add a stacked bar chart to this module?

Regards
Andy
Regards

Andy

Image
Registered PB & PureVision User
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Module] Chart - Gadget

Post by mk-soft »

Update for C-BackEnd :wink:

Part of ChartModule.pbi

Bugfix
Update PB v6.0 Alpha 3

Code: Select all

  ;- ============================================================================
  ;-   Module - Internal
  ;- ============================================================================   
  
  CompilerIf Not Defined(PB_Compiler_Backend, #PB_Constant)
    #PB_Compiler_Backend = 0
    #PB_Backend_C = 1
    #PB_Backend_Asm = 0
  CompilerEndIf
  
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    ; Addition of mk-soft
    
    Procedure OSX_NSColorToRGBA(NSColor)
      Protected.cgfloat red, green, blue, alpha
      Protected nscolorspace, rgba
      nscolorspace = CocoaMessage(0, nscolor, "colorUsingColorSpaceName:$", @"NSCalibratedRGBColorSpace")
      If nscolorspace
        CocoaMessage(@red, nscolorspace, "redComponent")
        CocoaMessage(@green, nscolorspace, "greenComponent")
        CocoaMessage(@blue, nscolorspace, "blueComponent")
        CocoaMessage(@alpha, nscolorspace, "alphaComponent")
        rgba = RGBA(red * 255.9, green * 255.9, blue * 255.9, alpha * 255.)
        ProcedureReturn rgba
      EndIf
    EndProcedure
    
    Procedure OSX_NSColorToRGB(NSColor)
      Protected.cgfloat red, green, blue
      Protected r, g, b, a
      Protected nscolorspace, rgb
      nscolorspace = CocoaMessage(0, nscolor, "colorUsingColorSpaceName:$", @"NSCalibratedRGBColorSpace")
      If nscolorspace
        CocoaMessage(@red, nscolorspace, "redComponent")
        CocoaMessage(@green, nscolorspace, "greenComponent")
        CocoaMessage(@blue, nscolorspace, "blueComponent")
        rgb = RGB(red * 255.0, green * 255.0, blue * 255.0)
        ProcedureReturn rgb
      EndIf
    EndProcedure
    
  CompilerEndIf
  
  CompilerIf Defined(ModuleEx, #PB_Module)
    
    Procedure.i GetGadgetWindow()
      ProcedureReturn ModuleEx::GetGadgetWindow()
    EndProcedure
    
  CompilerElse  
    
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      ; Thanks to mk-soft
      Import ""
        PB_Object_EnumerateStart(PB_Objects)
        PB_Object_EnumerateNext(PB_Objects, *ID.Integer)
        PB_Object_EnumerateAbort(PB_Objects)
      EndImport
      
      CompilerIf #PB_Compiler_Backend = #PB_Backend_C
        Global PB_Window_Objects
        Procedure _WindowObjects()
          !extern integer PB_Window_Objects;
          !return PB_Window_Objects;
        EndProcedure
        
        PB_Window_Objects = _WindowObjects()
        
      CompilerElse
        Import ""
          PB_Window_Objects
        EndImport
      CompilerEndIf
      
      
    CompilerElse
      ImportC ""
        PB_Object_EnumerateStart(PB_Objects)
        PB_Object_EnumerateNext(PB_Objects, *ID.Integer)
        PB_Object_EnumerateAbort(PB_Objects)
        PB_Window_Objects.i
      EndImport
    CompilerEndIf
    
    Procedure.i GetGadgetWindow()
      ; Thanks to mk-soft
      Define.i WindowID, Window, Result = #PB_Default
      
      WindowID = UseGadgetList(0)
      
      PB_Object_EnumerateStart(PB_Window_Objects)
      
      While PB_Object_EnumerateNext(PB_Window_Objects, @Window)
        If WindowID = WindowID(Window)
          Result = Window
          Break
        EndIf
      Wend
      
      PB_Object_EnumerateAbort(PB_Window_Objects)
      
      ProcedureReturn Result
    EndProcedure
    
  CompilerEndIf	
  
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: [Module] Chart - Gadget

Post by blueznl »

Oh... very nice. I need to have a good look at this, see if I can stop working on my own graph_lib routines :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
ruslanx
User
User
Posts: 46
Joined: Mon Jun 06, 2011 8:28 am

Re: [Module] Chart - Gadget

Post by ruslanx »

How can I use line-chart for as live chart ... realtime data insert ... I need multiline chart ... ??
User avatar
jacdelad
Addict
Addict
Posts: 1432
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: [Module] Chart - Gadget

Post by jacdelad »

Realtime? I don't think this is possible (and intended) with this module...
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: [Module] Chart - Gadget

Post by Caronte3D »

Can be used, but is very slow and have huge flicker. Not the best solution.
ruslanx
User
User
Posts: 46
Joined: Mon Jun 06, 2011 8:28 am

Re: [Module] Chart - Gadget

Post by ruslanx »

Caronte3D wrote: Tue Feb 21, 2023 8:35 amCaronte3D
can you suggest better? Thank you!
jacdelad wrote: Mon Feb 20, 2023 10:28 pm Realtime? I don't think this is possible (and intended) with this module...
Hi, perhaps, but some flickering persists... here is how I did it:
Image

Code: Select all

CompilerIf #PB_Compiler_IsMainFile
  
  Enumeration 
    #Window
    #Chart
  EndEnumeration
  
  If OpenWindow(#Window, 0, 0, 700, 500, "Example", #PB_Window_SystemMenu|#PB_Window_Tool|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
    SmartWindowRefresh(#Window,1)
    
    Chart::Gadget(#Chart, 10, 10, 680, 480, Chart::#LineChart|Chart::#DataSeries, #Window)
    Chart::SetFlags(#Chart, Chart::#Legend, Chart::#Hide)
    Chart::SetFlags(#Chart, Chart::#LineChart, Chart::#BezierCurve|Chart::#NoAutoAdjust) ; |Chart::#Descending|Chart::#NoAutoAdjust
    Chart::SetAttribute(#Chart, Chart::#Maximum, 100)
    Chart::SetAttribute(#Chart, Chart::#FontSize, 10)
    Chart::SetFlags(#Chart, Chart::#LineChart, Chart::#OutOfRange)
    Chart::SetAutoResizeFlags(#Chart, Chart::#ResizeWidth)
    
    Chart::SetColor(#Chart, Chart::#BackColor, $ffffff)
    Chart::SetColor(#Chart, Chart::#AxisColor, $ffffff)
    
    Chart::AddDataSeries(#Chart, "1", $FF901E)
    Chart::AddDataSeries(#Chart, "2", $0000FF)
    Chart::AddDataSeries(#Chart, "3", $00D7FF)
    
    
    AddWindowTimer(#Window, 123, 1000)
    
    Define i.i = 0
    
    Repeat
      Event = WaitWindowEvent(1)
      
      If Event = #PB_Event_Timer And EventTimer() = 123        
        i + 1
        
        Chart::DisableReDraw(#Chart, #True)        
       
        Chart::AddSeriesItem(#Chart, "1", Str(i), Random(80, 60))      
        Chart::AddSeriesItem(#Chart, "2", Str(i), Random(60, 40))
        Chart::AddSeriesItem(#Chart, "3", Str(i), Random(40, 20))    
        
        Chart::DisplayDataSeries(#Chart, "1")
        Chart::DisplayDataSeries(#Chart, "2")
        Chart::DisplayDataSeries(#Chart, "3")
        
        If i > 30        
          Chart::RemoveSeriesItem(#Chart, "1", 0)
          Chart::RemoveSeriesItem(#Chart, "2", 0)
          Chart::RemoveSeriesItem(#Chart, "3", 0)
        EndIf
        
        Chart::DisableReDraw(#Chart, #False)
      EndIf  
      
    Until Event = #PB_Event_CloseWindow
    
    CloseWindow(#Window)
    End 
  EndIf
  
CompilerEndIf  
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: [Module] Chart - Gadget

Post by Caronte3D »

I don't know a complete solution like this Chart, but may be you can adapt and extend some of the various examples on this forum.
Example:
viewtopic.php?f=13&t=75772
User avatar
jacdelad
Addict
Addict
Posts: 1432
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: [Module] Chart - Gadget

Post by jacdelad »

@ruslanx: I mean, yes, you can use it for realtime chart creating, but each time the whole picture is rendered completely new, so you'll encounter a lot of flickering, cpu consumption and maybe some more side effects.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Module] Chart - Gadget

Post by mk-soft »

Can't you do this optimised with an OpenGLGadget?
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
jacdelad
Addict
Addict
Posts: 1432
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: [Module] Chart - Gadget

Post by jacdelad »

@Thorsten: Do you still work on this module (in case of a minor error)?
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Post Reply