bar-simple.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 pandas
  17. from taipy.gui import Gui
  18. if __name__ == "__main__":
  19. # Source https://en.wikipedia.org/wiki/List_of_United_States_presidential_elections_by_popular_vote_margin
  20. percentages = [
  21. (1852, 50.83),
  22. (1856, 45.29),
  23. (1860, 39.65),
  24. (1864, 55.03),
  25. (1868, 52.66),
  26. (1872, 55.58),
  27. (1876, 47.92),
  28. (1880, 48.31),
  29. (1884, 48.85),
  30. (1888, 47.80),
  31. (1892, 46.02),
  32. (1896.0, 51.02),
  33. (1900, 51.64),
  34. (1904, 56.42),
  35. (1908, 51.57),
  36. (1912, 41.84),
  37. (1916, 49.24),
  38. (1920, 60.32),
  39. (1924, 54.04),
  40. (1928, 58.21),
  41. (1932, 57.41),
  42. (1936, 60.80),
  43. (1940, 54.74),
  44. (1944, 53.39),
  45. (1948, 49.55),
  46. (1952, 55.18),
  47. (1956, 57.37),
  48. (1960, 49.72),
  49. (1964, 61.05),
  50. (1968, 43.42),
  51. (1972, 60.67),
  52. (1976, 50.08),
  53. (1980, 50.75),
  54. (1984, 58.77),
  55. (1988, 53.37),
  56. (1992, 43.01),
  57. (1996, 49.23),
  58. (2000, 47.87),
  59. (2004, 50.73),
  60. (2008, 52.93),
  61. (2012, 51.06),
  62. (2016, 46.09),
  63. (2020, 51.31),
  64. ]
  65. data = pandas.DataFrame(percentages, columns=["Year", "%"])
  66. page = """
  67. # Bar - Simple
  68. <|{data}|chart|type=bar|x=Year|y=%|>
  69. """
  70. Gui(page).run()