[Module] Chart - Gadget

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
cyril
User
User
Posts: 15
Joined: Sun Feb 23, 2020 4:28 pm

Re: [Module] Chart - Gadget

Post by cyril »

Thanks Thorsten1867

Your help is appreciated ;)
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Chart - Gadget

Post by Thorsten1867 »

I took a look at the code and actually it should already work.
Have you ever tried this:

Code: Select all

Chart::SetAttribute(#Chart, Chart::#Decimals, 2)
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
cyril
User
User
Posts: 15
Joined: Sun Feb 23, 2020 4:28 pm

Re: [Module] Chart - Gadget

Post by cyril »

Yes, i used it in my ChartCreate code posted previously.

but I still get rounded value for the YAxis in my charts.

I'm using this test code, and the value are rounded too

Code: Select all

XIncludeFile "ChartModule.pbi"

Enumeration 
  #Window
  #Chart
EndEnumeration

If OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 400, 200, "Chart decimal test", #PB_Window_ScreenCentered)
        Chart::Gadget(#Chart, 10, 10, 295, 180, Chart::#ScatterPlot|Chart::#Border|Chart::#ToolTips|Chart::#AutoResize|Chart::#ShowLines, #Window)
        Chart::SetAttribute(#Chart, Chart::#MaximumY, 50)
        Chart::SetAttribute(#Chart, Chart::#MinimumY, 40)
        Chart::SetAttribute(#Chart, Chart::#MinimumX, Date(2019, 1, 1, 8, 0, 0))
        Chart::SetAttribute(#Chart, Chart::#MaximumX, Date(2019, 1, 1, 13, 0, 0))
       
        Chart::AddAxisLabel(#Chart,  "8:00", Date(2019, 1, 1,  8, 0, 0))
        Chart::AddAxisLabel(#Chart,  "9:00", Date(2019, 1, 1,  9, 0, 0))
        Chart::AddAxisLabel(#Chart, "10:00", Date(2019, 1, 1, 10, 0, 0))
        Chart::AddAxisLabel(#Chart, "11:00", Date(2019, 1, 1, 11, 0, 0))
        Chart::AddAxisLabel(#Chart, "12:00", Date(2019, 1, 1, 12, 0, 0))
        Chart::AddAxisLabel(#Chart, "13:00", Date(2019, 1, 1, 13, 0, 0))
        Chart::SetFlags(#Chart, Chart::#AxisX, Chart::#Time|Chart::#Labels)

        Chart::SetAttribute(#Chart, Chart::#Decimals, 2)
        Chart::ToolTipText(#Chart, Chart::#Scatter$ + ": " + Chart::#Value$)
        
        
        If Chart::AddScatterPlot(#Chart, "Scatter 1", $FF901E)
          Chart::AddScatterItem(#Chart, "Scatter 1", "08:30",  Date(2019, 1, 1,  8, 30, 0), 45.33)
          Chart::AddScatterItem(#Chart, "Scatter 1", "10:30",  Date(2019, 1, 1,  10, 30, 0), 46.55)
          Chart::AddScatterItem(#Chart, "Scatter 1", "11::30", Date(2019, 1, 1,  11, 30, 0), 46.27)
          Chart::AddScatterItem(#Chart, "Scatter 1", "12::30", Date(2019, 1, 1,  12, 30, 0), 46.77)
        EndIf
        Chart::DisplayScatterPlot(#Chart, "Scatter 1", #True)
        
        Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
The tooltip show rounded value too. And the chart seems to be using rounded value too.

Am I doing something wrong ?
cyril
User
User
Posts: 15
Joined: Sun Feb 23, 2020 4:28 pm

Re: [Module] Chart - Gadget

Post by cyril »

I've updated my test code to show the rounding more clearly ;)
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Chart - Gadget

Post by Thorsten1867 »

Code: Select all

Chart::SetAttribute(#Chart, Chart::#MaximumY, 48.5)
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] Chart - Gadget

Post by Thorsten1867 »

Bugfixes
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
cyril
User
User
Posts: 15
Joined: Sun Feb 23, 2020 4:28 pm

Re: [Module] Chart - Gadget

Post by cyril »

Code: Select all

XIncludeFile "ChartModule.pbi"

Enumeration 
  #Window
  #Chart
EndEnumeration

If OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 400, 200, "Chart decimal test", #PB_Window_ScreenCentered)
        Chart::Gadget(#Chart, 10, 10, 295, 180, Chart::#ScatterPlot|Chart::#Border|Chart::#ToolTips|Chart::#AutoResize|Chart::#ShowLines, #Window)
        Chart::SetAttribute(#Chart, Chart::#MaximumY, 47)
        Chart::SetAttribute(#Chart, Chart::#MinimumY, 45)
        Chart::SetAttribute(#Chart, Chart::#MinimumX, Date(2019, 1, 1, 8, 0, 0))
        Chart::SetAttribute(#Chart, Chart::#MaximumX, Date(2019, 1, 1, 13, 0, 0))
       
        Chart::AddAxisLabel(#Chart,  "8:00", Date(2019, 1, 1,  8, 0, 0))
        Chart::AddAxisLabel(#Chart,  "9:00", Date(2019, 1, 1,  9, 0, 0))
        Chart::AddAxisLabel(#Chart, "10:00", Date(2019, 1, 1, 10, 0, 0))
        Chart::AddAxisLabel(#Chart, "11:00", Date(2019, 1, 1, 11, 0, 0))
        Chart::AddAxisLabel(#Chart, "12:00", Date(2019, 1, 1, 12, 0, 0))
        Chart::AddAxisLabel(#Chart, "13:00", Date(2019, 1, 1, 13, 0, 0))
        Chart::SetFlags(#Chart, Chart::#AxisX, Chart::#Time|Chart::#Labels)

        Chart::SetAttribute(#Chart, Chart::#Decimals, 2)
        Chart::ToolTipText(#Chart, Chart::#Scatter$ + ": " + Chart::#Value$)
        
        
        If Chart::AddScatterPlot(#Chart, "Scatter 1", $FF901E)
          Chart::AddScatterItem(#Chart, "Scatter 1", "08:30",  Date(2019, 1, 1,  8, 30, 0), 45.33)
          Chart::AddScatterItem(#Chart, "Scatter 1", "10:30",  Date(2019, 1, 1,  10, 30, 0), 46.55)
          Chart::AddScatterItem(#Chart, "Scatter 1", "11::30", Date(2019, 1, 1,  11, 30, 0), 46.27)
          Chart::AddScatterItem(#Chart, "Scatter 1", "12::30", Date(2019, 1, 1,  12, 30, 0), 46.77)
        EndIf
        Chart::DisplayScatterPlot(#Chart, "Scatter 1", #True)
        
        Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Last edited by cyril on Sat Mar 07, 2020 4:08 pm, edited 1 time in total.
cyril
User
User
Posts: 15
Joined: Sun Feb 23, 2020 4:28 pm

Re: [Module] Chart - Gadget

Post by cyril »

Here is an image showing the rounding of value.
Image
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: Floats for item data
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
cyril
User
User
Posts: 15
Joined: Sun Feb 23, 2020 4:28 pm

Re: [Module] Chart - Gadget

Post by cyril »

Thanks for the update Thorsten1867.

I finally got it working :)
cyril
User
User
Posts: 15
Joined: Sun Feb 23, 2020 4:28 pm

Re: [Module] Chart - Gadget

Post by cyril »

Hello Thorsten

I'm having a problem with tooltips using a scatterplot graph.

I'm using:

Code: Select all

Chart::ToolTipText(#Gadget_Chart, Chart::#Scatter$ + ": " + Chart::#Time$ + " - " + Chart::#DataY$ + " pounds")
But the tooltip is still something like: "128.888888888" instead of "Weight: 01/03/2020 - 128.89 pounds".

I also tried with

Code: Select all

Chart::ToolTipText(#Gadget_Chart, Chart::#Scatter$ + ": " + Chart::#Time$ + " - " + Chart::#Value$ + " pounds")
The complete initialization code i'm using is:

Code: Select all

Chart::Gadget(#Gadget_Chart, x, y, width, height, Chart::#ScatterPlot|Chart::#Border|Chart::#ShowLines|Chart::#ToolTips|Chart::#AutoResize, #Window_Main)
Chart::SetFlags(#Gadget_Chart, Chart::#AxisX, Chart::#Time|Chart::#Labels)
Chart::SetAttribute(#Gadget_Chart, Chart::#Decimals, 2)
Chart::SetMask(#Gadget_Chart, Chart::#AxisX, "%dd/%mm/%yyyy")
Chart::ToolTipText(#Gadget_Chart, Chart::#Scatter$ + ": " + Chart::#Time$ + " - " + Chart::#DataY$ + " pounds")
What am I doing wrong ?
cyril
User
User
Posts: 15
Joined: Sun Feb 23, 2020 4:28 pm

Re: [Module] Chart - Gadget

Post by cyril »

Here is a sample code that shows the problem:

Code: Select all

XIncludeFile "ChartModule.pbi"

Enumeration
  #Window
  #Chart
EndEnumeration

If OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 400, 200, "Chart decimal test", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
        Chart::Gadget(#Chart, 10, 10, 380, 180, Chart::#ScatterPlot|Chart::#Border|Chart::#ToolTips|Chart::#AutoResize|Chart::#ShowLines, #Window)
        Chart::SetAttribute(#Chart, Chart::#MaximumY, 47)
        Chart::SetAttribute(#Chart, Chart::#MinimumY, 45)
        Chart::SetAttribute(#Chart, Chart::#MinimumX, Date(2019, 1, 1, 8, 0, 0))
        Chart::SetAttribute(#Chart, Chart::#MaximumX, Date(2019, 1, 1, 13, 0, 0))
       
        Chart::AddAxisLabel(#Chart,  "8:00", Date(2019, 1, 1,  8, 0, 0))
        Chart::AddAxisLabel(#Chart,  "9:00", Date(2019, 1, 1,  9, 0, 0))
        Chart::AddAxisLabel(#Chart, "10:00", Date(2019, 1, 1, 10, 0, 0))
        Chart::AddAxisLabel(#Chart, "11:00", Date(2019, 1, 1, 11, 0, 0))
        Chart::AddAxisLabel(#Chart, "12:00", Date(2019, 1, 1, 12, 0, 0))
        Chart::AddAxisLabel(#Chart, "13:00", Date(2019, 1, 1, 13, 0, 0))
        Chart::SetFlags(#Chart, Chart::#AxisX, Chart::#Time|Chart::#Labels)

        Chart::SetAttribute(#Chart, Chart::#Decimals, 2)
        Chart::ToolTipText(#Chart, Chart::#Scatter$ + ": " + Chart::#Time$ + " - " + Chart::#Value$ + " pounds")
       
       
        If Chart::AddScatterPlot(#Chart, "Scatter 1", $FF901E)
          Chart::AddScatterItem(#Chart, "Scatter 1", "08:30",  Date(2019, 1, 1,  8, 30, 0), 45.33)
          Chart::AddScatterItem(#Chart, "Scatter 1", "10:30",  Date(2019, 1, 1,  10, 30, 0), 46.55)
          Chart::AddScatterItem(#Chart, "Scatter 1", "11::30", Date(2019, 1, 1,  11, 30, 0), 46.27)
          Chart::AddScatterItem(#Chart, "Scatter 1", "12::30", Date(2019, 1, 1,  12, 30, 0), 46.77)
        EndIf
        Chart::DisplayScatterPlot(#Chart, "Scatter 1", #True)
       
        Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
When hovering over a point, only the value is displayed (with no rounding) instead of what was specified using Chart::ToolTipText.
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Chart - Gadget

Post by Thorsten1867 »

Bugfixes
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
cyril
User
User
Posts: 15
Joined: Sun Feb 23, 2020 4:28 pm

Re: [Module] Chart - Gadget

Post by cyril »

Thank you Thorsten :)

It's working great !
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: [Module] Chart - Gadget

Post by Lord »

Hi!

Sometimes it would be desirable if the x-axis labels were arranged vertically,
especially for longer texts.
Is this possible with the chart gadget?

Example:
Image
Image
Post Reply