pie-multiple.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. from taipy.gui import Gui
  17. if __name__ == "__main__":
  18. # List of countries, used as labels in the pie charts
  19. countries = ["US", "China", "European Union", "Russian Federation", "Brazil", "India", "Rest of World"]
  20. data = [
  21. {
  22. # Values for GHG Emissions
  23. "values": [16, 15, 12, 6, 5, 4, 42],
  24. "labels": countries,
  25. },
  26. {
  27. # Values for CO2 Emissions
  28. "values": [27, 11, 25, 8, 1, 3, 25],
  29. "labels": countries,
  30. },
  31. ]
  32. options = [
  33. # First pie chart
  34. {
  35. # Show label value on hover
  36. "hoverinfo": "label",
  37. # Leave a hole in the middle of the chart
  38. "hole": 0.4,
  39. # Place the trace on the left side
  40. "domain": {"column": 0},
  41. },
  42. # Second pie chart
  43. {
  44. # Show label value on hover
  45. "hoverinfo": "label",
  46. # Leave a hole in the middle of the chart
  47. "hole": 0.4,
  48. # Place the trace on the right side
  49. "domain": {"column": 1},
  50. },
  51. ]
  52. layout = {
  53. # Chart title
  54. "title": "Global Emissions 1990-2011",
  55. # Show traces in a 1x2 grid
  56. "grid": {"rows": 1, "columns": 2},
  57. "annotations": [
  58. # Annotation for the first trace
  59. {
  60. "text": "GHG",
  61. "font": {"size": 20},
  62. # Hide annotation arrow
  63. "showarrow": False,
  64. # Move to the center of the trace
  65. "x": 0.18,
  66. "y": 0.5,
  67. },
  68. # Annotation for the second trace
  69. {
  70. "text": "CO2",
  71. "font": {"size": 20},
  72. "showarrow": False,
  73. # Move to the center of the trace
  74. "x": 0.81,
  75. "y": 0.5,
  76. },
  77. ],
  78. "showlegend": False,
  79. }
  80. page = """
  81. # Pie - Multiple
  82. <|{data}|chart|type=pie|x[1]=0/values|x[2]=1/values|options={options}|layout={layout}|>
  83. """
  84. Gui(page).run()