Giter Site home page Giter Site logo

thisal-d / ctkchart Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 0.0 589 KB

ctkchart is a Python library for creating live updating line charts in customtkinter.

Home Page: https://pypi.org/project/ctkchart/

License: MIT License

Python 100.00%
ctk ctk-components ctkchart customtkinter customtkinter-widgets customtkinterassets line-chart-for-python-customtkinter line-chart-for-python-tkinter linechart python-chart tkchart tkinter tkinter-graphic-interface tkinter-widgets tkinter-widget

ctkchart's Introduction

๐ŸŒŸIf you find this project helpful, your support by starring it would mean a lot! Your feedback motivates me to keep refining and enhancing it further. ๐Ÿš€

Your support means a lot and inspires me to do better with each update. Thank you for taking the time to check out this project!๐Ÿฅฐ

ctkchart

Downloads Downloads Downloads

  • ctkchart is a Python library for creating live updating line charts in customtkinter.

  • Features

    • Live Update: Display live data with line charts.
    • Multiple Lines: Support for plotting multiple lines on the same chart for easy comparison.
    • Color Customization: Customize colors to match your application's design or data representation.
    • Dynamic Color Change: Dynamic Color Change for Dark & Light.
    • Font Customization: Adjust fonts for text elements to enhance readability.
    • Dimension Customization: Customize chart dimensions to fit various display sizes and layouts.

    Importing & Installation

    • Installation

      pip install ctkchart
      
    • Importing

      import ctkchart

    Simple Guide

    • import package

      import tkchart
    • Create Line Chart and place the chart

      chart = ctkchart.CTkLineChart(
          master=root,
          x_axis_values=("a", "b", "c", "d", "e", "f"),
          y_axis_values=(100, 900)
      )
      chart.place(x=10, y=10)
    • Create Line

      line = ctkchart.CTkLine(master=chart)
    • Display Data display data using a loop

      def loop():
          while True:
              random_data = random.choice(range(100, 900))
              chart.show_data(line=line, data=[random_data])
              time.sleep(1)
      
      #call the loop as thead
      theading.Thread(target=loop).start()

    Links


    What You Can Accomplish

    • Simple

      1.mp4
      import customtkinter as ctk  # Importing the customtkinter library as ctk
      import ctkchart  # Importing the ctkchart module for chart creation
      import random  # Importing the random module for generating random data
      import threading  # Importing the threading module for running tasks concurrently
      import time  # Importing the time module for adding delays
      
      # Create the root window and configure
      root = ctk.CTk()
      root.configure(fg_color="#0d1117")
      root.geometry("720x430+200+200")  
      
      # Create a line chart widget
      line_chart = ctkchart.CTkLineChart(
          master=root,  # Set the master as the root window
          x_axis_values=("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07", "01-08", "01-09", "01-10"),  # X-axis values
          y_axis_values=(0, 1000)  # Y-axis values (range)
      )
      
      line_chart.pack(pady=15)  # Pack the line chart widget into the root
      
      # Create a line for the line chart
      line = ctkchart.CTkLine(master=line_chart)  # Set the master as the line chart
      
      def display_data():
          """Function to continuously display random data on the line chart."""
          while True:
              random_data = [random.choice(range(0, 1000))]  # Generate random data between 0 and 1000
              line_chart.show_data(line=line, data=random_data)  # Display the random data on the line chart
              time.sleep(0.5)  # Pause for 0.5 seconds before the next iteration
      
      # Call the display_data function as a separate thread
      threading.Thread(target=display_data).start()
      
      # Start the main event loop
      root.mainloop()

    • Simple style

      2.mp4
      import customtkinter as ctk  # Importing the customtkinter library as ctk
      import ctkchart  # Importing the ctkchart module for chart creation
      import random  # Importing the random module for generating random data
      import threading  # Importing the threading module for running tasks concurrently
      import time  # Importing the time module for adding delays
      
      # Create the root window and configure
      root = ctk.CTk()
      root.configure(fg_color="#0d1117")
      root.geometry("720x430+200+200")  
      
      # Create a line chart widget
      line_chart = ctkchart.CTkLineChart(
          master=root,  # Set the master as the root window
          x_axis_values=("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07", "01-08", "01-09", "01-10"),  # X-axis values
          y_axis_values=(0, 1000),  # Y-axis values (range)
          y_axis_label_count=10, # set y axis labels count to 10
      )
      
      line_chart.pack(pady=15)  # Pack the line chart widget into the root
      
      # Create a line for the line chart
      line = ctkchart.CTkLine(
          master=line_chart,  # Set the master as the line chart
          size=2,  # Set the line size to 2
          fill="enabled" # enable line fill
      )  
      
      def display_data():
          """Function to continuously display random data on the line chart."""
          while True:
              random_data = [random.choice(range(0, 1000))]  # Generate random data between 0 and 1000
              line_chart.show_data(line=line, data=random_data)  # Display the random data on the line chart
              time.sleep(0.5)  # Pause for 0.5 seconds before the next iteration
      
      # Call the display_data function as a separate thread
      threading.Thread(target=display_data).start()
      
      # Start the main event loop
      root.mainloop()

    • 2 lines with different line styles

      3.mp4
      import customtkinter as ctk  # Importing the customtkinter library as ctk
      import ctkchart  # Importing the ctkchart module for chart creation
      import random  # Importing the random module for generating random data
      import threading  # Importing the threading module for running tasks concurrently
      import time  # Importing the time module for adding delays
      
      # Create the root window and configure
      root = ctk.CTk()
      root.configure(fg_color=("#ffffff", "#0d1117"))
      root.geometry("720x430+200+200")  
      
      # Create a line chart widget
      line_chart = ctkchart.CTkLineChart(
          master=root,  # Set the master as the root window
          x_axis_values=("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07", "01-08", "01-09", "01-10"),  # X-axis values
          y_axis_values=(0, 1000),  # Y-axis values (range)
          y_axis_label_count=10, # set y axis labels count to 10
      )
      
      line_chart.pack(pady=15)  # Pack the line chart widget into the root
      
      line1 = ctkchart.CTkLine(
          master=line_chart,  # Set the master as the line chart
          color=("#5dffb6","#5dffb6"), # index 0 for light and 1 for dark theme
          size=2,  # Set the line size to 2
          style="dashed", # style change to dashed
          style_type=(10, 5), #index 0 for dash width and 1 for space between dashes
      ) 
      
      line2 = ctkchart.CTkLine(
          master=line_chart,  # Set the master as the line chart
          color=("#FFBAD2", "#FFBAD2"), # index 0 for light and 1 for dark theme
          size=2,  # Set the line size to 2
          point_highlight="enabled", # enable point highlight
          point_highlight_color=("#FFBAD2", "#FFBAD2"), # enable point highlight
      )  
      
      def display_data():
          """Function to continuously display random data on the line chart."""
          while True:
              random_data = [random.choice(range(0, 1000))]  # Generate random data between 0 and 1000
              line_chart.show_data(line=line1, data=random_data)  # Display the random data on the line 1 on chart
              random_data = [random.choice(range(0, 1000))]  # Generate random data between 0 and 1000
              line_chart.show_data(line=line2, data=random_data)  # Display the random data on the line 2 on chart    
              time.sleep(0.5)  # Pause for 0.5 seconds before the next iteration
      
      # Call the display_data function as a separate thread
      threading.Thread(target=display_data).start()
      
      # Start the main event loop
      root.mainloop()

    • 3 lines with different line styles

      4.mp4
      import customtkinter as ctk  # Importing the customtkinter library as ctk
      import ctkchart  # Importing the ctkchart module for chart creation
      import random  # Importing the random module for generating random data
      import threading  # Importing the threading module for running tasks concurrently
      import time  # Importing the time module for adding delays
      
      # Create the root window and configure
      root = ctk.CTk()
      root.configure(fg_color=("#ffffff", "#0d1117"))
      root.geometry("720x430+200+200")  
      
      # Create a line chart widget
      line_chart = ctkchart.CTkLineChart(
          master=root,  # Set the master as the root window
          x_axis_values=("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07", "01-08", "01-09", "01-10"),  # X-axis values
          y_axis_values=(0, 1000),  # Y-axis values (range)
          y_axis_label_count=10, # set y axis labels count to 10
      )
      
      line_chart.pack(pady=15)  # Pack the line chart widget into the root
      
      # Create a line 1 for the line chart
      line1 = ctkchart.CTkLine(
          master=line_chart,  # Set the master as the line chart
          size=2,  # Set the line size to 2
          fill="enabled" # enable line fill
      )  
      
      line2 = ctkchart.CTkLine(
          master=line_chart,  # Set the master as the line chart
          color=("#5dffb6","#5dffb6"), # index 0 for light and 1 for dark theme
          size=2,  # Set the line size to 2
          style="dashed", # style change to dashed
          style_type=(10, 5), #index 0 for dash width and 1 for space between dashes
      ) 
      
      line3 = ctkchart.CTkLine(
          master=line_chart,  # Set the master as the line chart
          color=("#FFBAD2", "#FFBAD2"), # index 0 for light and 1 for dark theme
          size=2,  # Set the line size to 2
          point_highlight="enabled", # enable point highlight
          point_highlight_color=("#FFBAD2", "#FFBAD2"), # enable point highlight
      )  
      
      def display_data():
          """Function to continuously display random data on the line chart."""
          while True:
              random_data = [random.choice(range(0, 1000))]  # Generate random data between 0 and 1000
              line_chart.show_data(line=line1, data=random_data)  # Display the random data on the line 1 on chart
              random_data = [random.choice(range(0, 1000))]  # Generate random data between 0 and 1000
              line_chart.show_data(line=line2, data=random_data)  # Display the random data on the line 2 on chart
              random_data = [random.choice(range(0, 1000))]  # Generate random data between 0 and 1000
              line_chart.show_data(line=line3, data=random_data)  # Display the random data on the line 3 on chart
              time.sleep(0.5)  # Pause for 0.5 seconds before the next iteration
      
      # Call the display_data function as a separate thread
      threading.Thread(target=display_data).start()
      
      # Start the main event loop
      root.mainloop()

    • Advance (Actually not, Just Two More Attributes Added)

      5.mp4
      import customtkinter as ctk  # Importing the customtkinter library as ctk
      import ctkchart  # Importing the ctkchart module for chart creation
      import random  # Importing the random module for generating random data
      import threading  # Importing the threading module for running tasks concurrently
      import time  # Importing the time module for adding delays
      
      # Create the root window and configure
      root = ctk.CTk()
      root.configure(fg_color=("#ffffff", "#0d1117"))
      root.geometry("720x430+200+200")  
      
      # Create a line chart widget
      line_chart = ctkchart.CTkLineChart(
          master=root,  # Set the master as the root window
          x_axis_values=("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07", "01-08", "01-09", "01-10"),  # X-axis values
          y_axis_values=(0, 1000),  # Y-axis values (range)
          y_axis_label_count=10, # set y axis labels count to 1
          y_axis_section_count=10,
          x_axis_section_count=10,
      )
      
      line_chart.pack(pady=15)  # Pack the line chart widget into the root
      
      line1 = ctkchart.CTkLine(
          master=line_chart,  # Set the master as the line chart
          color=("#5dffb6","#5dffb6"), # index 0 for light and 1 for dark theme
          size=2,  # Set the line size to 2
          style="dashed", # style change to dashed
          style_type=(10, 5), #index 0 for dash width and 1 for space between dashes
      ) 
      
      line2 = ctkchart.CTkLine(
          master=line_chart,  # Set the master as the line chart
          color=("#FFBAD2", "#FFBAD2"), # index 0 for light and 1 for dark theme
          size=2,  # Set the line size to 2
          point_highlight="enabled", # enable point highlight
          point_highlight_color=("#FFBAD2", "#FFBAD2"), # enable point highlight
      )  
      
      def display_data():
          """Function to continuously display random data on the line chart."""
          while True:
              random_data = [random.choice(range(0, 1000))]  # Generate random data between 0 and 1000
              line_chart.show_data(line=line1, data=random_data)  # Display the random data on the line 1 on chart
              random_data = [random.choice(range(0, 1000))]  # Generate random data between 0 and 1000
              line_chart.show_data(line=line2, data=random_data)  # Display the random data on the line 2 on chart    
              time.sleep(0.5)  # Pause for 0.5 seconds before the next iteration
      
      # Call the display_data function as a separate thread
      threading.Thread(target=display_data).start()
      
      # Start the main event loop
      root.mainloop()

    • Light and Dark theme

      For every parameter that involves color in ctkchart, you can provide either:

      • A single string representing the color.
      • A tuple of two strings where the first string represents the color for the light theme and the second string represents the color for the dark theme.
      6.mp4

    Explore customizable features such as colors, fonts, and more in the documentation.

    Please refer to the full documentation


    Contributors

    ctkchart's People

    Contributors

    thisal-d avatar

    Stargazers

     avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

    Watchers

     avatar  avatar

    ctkchart's Issues

    Easing

    can you add easing to the animated graphs?
    like when the graph is being drawn instead of one line at a time, it can draw slow then fast then slow for each line or the whole thing
    just something that would be cool

    Support for customtkinter appearance mode

    Is your feature request related to a problem? Please describe.
    Customtkinter has the option to change between light and dark appearance mode, but this tkchart widget does not support this out of the box.
    https://customtkinter.tomschimansky.com/documentation/appearancemode
    Adding customtkinter.set_appearance_mode("light") to the 1. Simple.py example results in this:
    Screenshot 2024-03-07 151646

    Describe the solution you'd like
    customtkinter widgets accept a tuple with two colors, one for light and one for dark mode.
    https://customtkinter.tomschimansky.com/documentation/color
    If the mode gets changed while the program is running, the colors should change to match the mode.
    This would be nice to have for this widget, too. Then it can be integrated in customtkinter apps with the option to change between dark and light mode.

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google โค๏ธ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.