gantt_simple.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright 2021-2024 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. # -----------------------------------------------------------------------------------------
  12. # To execute this script, make sure that the taipy-gui package is installed in your
  13. # Python environment and run:
  14. # python <script>
  15. # -----------------------------------------------------------------------------------------
  16. import datetime
  17. from taipy.gui import Gui
  18. # Tasks definitions
  19. tasks = ["Plan", "Research", "Design", "Implement", "Test", "Deliver"]
  20. # Task durations, in days
  21. durations = [50, 30, 30, 40, 15, 10]
  22. # Planned start dates of tasks
  23. start_dates = [
  24. datetime.date(2022, 10, 15), # Plan
  25. datetime.date(2022, 11, 7), # Research
  26. datetime.date(2022, 12, 1), # Design
  27. datetime.date(2022, 12, 20), # Implement
  28. datetime.date(2023, 1, 15), # Test
  29. datetime.date(2023, 2, 1), # Deliver
  30. ]
  31. epoch = datetime.date(1970, 1, 1)
  32. data = {
  33. "start": start_dates,
  34. "Task": tasks,
  35. # Compute the time span as adatetime (relative to January 1st, 1970)
  36. "Date": [epoch + datetime.timedelta(days=duration) for duration in durations],
  37. }
  38. layout = {
  39. "yaxis": {
  40. # Sort tasks from top to bottom
  41. "autorange": "reversed",
  42. # Remove title
  43. "title": {"text": ""},
  44. },
  45. }
  46. page = """
  47. <|{data}|chart|type=bar|orientation=h|y=Task|x=Date|base=start|layout={layout}|>
  48. """
  49. if __name__ == "__main__":
  50. Gui(page).run(title="Chart - Gantt - Simple")