Page 7 of 7

Re: [Module] Chart - Gadget

Posted: Fri Dec 25, 2020 8:45 pm
by Ajm
Hi Thorsten,

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

Regards
Andy

Re: [Module] Chart - Gadget

Posted: Sun May 30, 2021 11:01 am
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	
  

Re: [Module] Chart - Gadget

Posted: Sun Feb 12, 2023 4:30 pm
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 :-)

Re: [Module] Chart - Gadget

Posted: Mon Feb 20, 2023 2:48 pm
by ruslanx
How can I use line-chart for as live chart ... realtime data insert ... I need multiline chart ... ??

Re: [Module] Chart - Gadget

Posted: Mon Feb 20, 2023 10:28 pm
by jacdelad
Realtime? I don't think this is possible (and intended) with this module...

Re: [Module] Chart - Gadget

Posted: Tue Feb 21, 2023 8:35 am
by Caronte3D
Can be used, but is very slow and have huge flicker. Not the best solution.

Re: [Module] Chart - Gadget

Posted: Tue Feb 21, 2023 10:11 am
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  

Re: [Module] Chart - Gadget

Posted: Tue Feb 21, 2023 11:08 am
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

Re: [Module] Chart - Gadget

Posted: Tue Feb 21, 2023 9:38 pm
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.

Re: [Module] Chart - Gadget

Posted: Tue Feb 21, 2023 11:12 pm
by mk-soft
Can't you do this optimised with an OpenGLGadget?

Re: [Module] Chart - Gadget

Posted: Fri Jun 23, 2023 8:25 am
by jacdelad
@Thorsten: Do you still work on this module (in case of a minor error)?