pie_multiple.py 2.7 KB

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