Create widget
PUT
/
api
/
widgets
Authorizations
x-api-key
string
headerrequiredResponse
200 - application/json
The response is of type object
.
{
"id": "a47b0ece-ef1b-43c6-a267-9debe10f7d27",
"title": "Testing title change",
"query": "Create a pie chart showing the sales in 2018 vs the sales in 2019",
"x": 0,
"y": 0,
"w": 4,
"h": 2,
"assumptions": [
"",
"1. Load the 'Order Date' and 'Sales' columns from the 'Sample Orders' dataset using pandas, as these are the only columns needed to calculate the total sales for 2018 and 2019.",
"2. Convert the 'Order Date' column to datetime format to filter the orders by year.",
"3. Filter the orders for the years 2018 and 2019.",
"4. Convert the 'Sales' column to numerical values using the provided `convertNum` function.",
"5. Calculate the total sales for each year by summing up the 'Sales' column after filtering.",
"6. Create a pie chart using Chart.js format where the data section contains the total sales for 2018 and 2019, and the labels section contains the years as strings.",
"7. Set the responsive option to true and maintainAspectRatio to false.",
"8. Add a title to the chart indicating it shows the comparison of sales between 2018 and 2019.",
"9. Since the user did not specify a chart type and did not ask to show values in the chart, the default type will be 'pie' and datalabels will be set to false.",
"",
""
],
"code": "import pandas as pd\ndef main():\n # Load the necessary columns from the CSV\n orders_df = pd.read_csv('/tmp/9f5cd772-aaff-460e-8e7a-03d21070b12c.csv', usecols=['Order Date', 'Sales'])\n \n # Convert 'Order Date' to datetime and filter for 2018 and 2019\n orders_df['Order Date'] = pd.to_datetime(orders_df['Order Date'], format='%Y-%m-%d')\n sales_2018 = orders_df[(orders_df['Order Date'].dt.year == 2018)]\n sales_2019 = orders_df[(orders_df['Order Date'].dt.year == 2019)]\n \n # Convert 'Sales' to numerical values\n sales_2018['Sales'] = sales_2018['Sales'].map(convertNum)\n sales_2019['Sales'] = sales_2019['Sales'].map(convertNum)\n \n # Calculate total sales for each year\n total_sales_2018 = sales_2018['Sales'].sum()\n total_sales_2019 = sales_2019['Sales'].sum()\n \n # Create the chart object\n chart = {\n 'type': 'pie',\n 'data': {\n 'labels': ['2018', '2019'],\n 'datasets': [{\n 'data': [total_sales_2018, total_sales_2019],\n 'backgroundColor': ['#4e79a7', '#f28e2b']\n }]\n },\n 'options': {\n 'responsive': True,\n 'maintainAspectRatio': False,\n 'plugins': {\n 'title': {\n 'display': True,\n 'text': 'Sales Comparison: 2018 vs 2019'\n },\n 'datalabels': {\n 'display': False\n }\n }\n }\n }\n \n return chart",
"dashboard": "fd0b9d77-791d-4898-afa6-99800301d861",
"cache": "yPqidavioVx462/1AKT8Il/yL7WDhryqAitAlNt82VlA//laqF8cSLD2kfEQgsXo29QSKwRJVChw mSxBCuDe97eX2zvc1D6U20XdDHR+y/68Is8Pt42DL7PmDefOMGi8KhisesLqtoHzFq160RHAfLfQ c6J4rasOfBKntNuaXddqg5syk5/rgca+UnX81D1rcQc1lqdaIwKqXTDebOGZH6n/WnLF6xlGOwKB x9zEaQkAyFwGyGSJa7ZaYxEvGO1toor0phvDIz3RjVN363H/2hhKhFUW/ivI+N7tyE6n+7T7+4yj OCCkQRS/AsiBvPm1ZvIGs2b4cqFhkKfmlPohn/RYQkH4SOnwQAmkysDNGrdlrOFHqTSWwrHAg8M1 PGLk5RuVotj3+UogcNKLFEEL4cYN2Fzi9J51d29i34vAwo5cXyva",
"team": "ee5b08c6-5167-4425-bbc3-a746fe4a7ead"
}
You can find all properties for Widgets in the concepts at this link