Onvo Documentation
APIs
Dashboards
Get:Get Dashboard by Id

Get dashboard by id

GET
/
api
/
dashboards
/
{id}

Authorizations

x-api-key
string
headerrequired

Response

200 - application/json

The response is of type object.

{
    "id": "47b6e961-a51c-4bf3-a9d4-01f30215cc42",
    "created_at": "2023-09-01T11:14:50.430891+00:00",
    "last_updated_at": "2023-09-07T14:51:42.626+00:00",
    "title": "Sample Dashboard",
    "description": "Some description about the dashboard",
    "thumbnail": "http://localhost:54321/storage/v1/object/public/data-sources/31a05cfd-1275-4c76-8390-20b328a3c4bf/dashboard:47b6e961-a51c-4bf3-a9d4-01f30215cc42/thumbnail.png",
    "organisation": "31a05cfd-1275-4c76-8390-20b328a3c4bf",
    "parent_dashboard": null,
    "widgets": [
        {
            "id": "7bfddd8e-cb99-4a9d-b540-2a07f31c7aee",
            "title": "Total sales",
            "query": "Show me a metric showing the total amount of sales in US dollars. Round the final value to 2 decimal points",
            "x": 4,
            "y": 0,
            "w": 4,
            "h": 1,
            "assumptions": [
                "1. The total sales will be calculated from the array with key 74813926-d1ec-4b38-82e1-08d1820cb029 as it contains the 'Sales' field.",
                "2. The 'Sales' field is assumed to be in US dollars.",
                "3. The 'Sales' field is assumed to be a numerical value, but it will be passed through the validateNumber function to ensure it is a usable number.",
                "4. The 'Sales' field values will be summed up to get the total sales.",
                "5. The total sales value will be rounded to 2 decimal points using the toFixed(2) method.",
                "6. The total sales value will be returned as a single data point in the datasets.data array.",
                "7. The datasets.label will be set to 'Total Sales (USD)' to indicate the unit of the metric.",
                "8. The type of chart in config will be set to 'metric' as per the user's request."
            ],
            "code": "function main(data) {\n    let totalSales = 0;\n    data['74813926-d1ec-4b38-82e1-08d1820cb029'].forEach(item => {\n        totalSales += validateNumber(item['Sales']);\n    });\n    totalSales = totalSales.toFixed(2);\n    return {\n        type: 'metric',\n        data: {\n            datasets: [{\n                data: [totalSales],\n                label: 'Total Sales (USD)'\n            }]\n        },\n        options: {\n            responsive: true,\n            maintainAspectRatio: false\n        }\n    };\n}",
            "organisation": "31a05cfd-1275-4c76-8390-20b328a3c4bf",
            "dashboard": "47b6e961-a51c-4bf3-a9d4-01f30215cc42"
        },
        {
            "id": "d38b4048-9a60-40e7-aead-62ba8227b7da",
            "title": "Total customers",
            "query": "Create a metric showing the total customer to date",
            "x": 0,
            "y": 0,
            "w": 4,
            "h": 1,
            "assumptions": [
                "1. The total customer to date is calculated by counting the unique Customer IDs in the data.",
                "2. The data for Customer IDs is assumed to be in the array for key 44a3aa21-0181-46d9-a54b-af915aaec92e.",
                "3. The function uses a Set to store unique Customer IDs and then counts the size of the Set.",
                "4. The chart type is set to 'metric' and the total customer count is returned as a single data point.",
                "5. The label for the data point is set to 'Total Customers'."
            ],
            "code": "function main(data) {\n    const customerData = data['44a3aa21-0181-46d9-a54b-af915aaec92e'];\n    const uniqueCustomers = new Set(customerData.map(customer => customer['Customer ID']));\n    const totalCustomers = uniqueCustomers.size;\n    return {\n        type: 'metric',\n        data: {\n            datasets: [{\n                data: [totalCustomers],\n                label: 'Total Customers'\n            }]\n        },\n        options: {\n            responsive: true,\n            maintainAspectRatio: false\n        }\n    };\n}",
            "organisation": "31a05cfd-1275-4c76-8390-20b328a3c4bf",
            "dashboard": "47b6e961-a51c-4bf3-a9d4-01f30215cc42"
        },
        {
            "id": "05f28a95-7cf5-488f-ac52-736536b3594e",
            "title": "Sales per month as a line chart",
            "query": "Show me the sales per month as a line chart. Each line should show the sales for a year.",
            "x": 6,
            "y": 1,
            "w": 6,
            "h": 3,
            "assumptions": [],
            "code": "function main(data) {\n    let salesData = data['74813926-d1ec-4b38-82e1-08d1820cb029'];\n    let salesPerMonth = {};\n    salesData.forEach(sale => {\n        let date = new Date(sale['Order Date']);\n        let year = date.getFullYear();\n        let month = date.getMonth();\n        if (!salesPerMonth[year]) {\n            salesPerMonth[year] = Array(12).fill(0);\n        }\n        salesPerMonth[year][month] += validateNumber(sale['Sales']);\n    });\n    let datasets = [];\n    for (let year in salesPerMonth) {\n        datasets.push({\n            label: year,\n            data: salesPerMonth[year],\n            fill: false,\n            borderColor: '#' + Math.floor(Math.random()*16777215).toString(16)\n        });\n    }\n    return {\n        type: 'line',\n        data: {\n            labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],\n            datasets: datasets\n        },\n        options: {\n            responsive: true,\n            maintainAspectRatio: false,\n            scales: {\n                xAxes: [{\n                    display: true,\n                    scaleLabel: {\n                        display: true,\n                        labelString: 'Month'\n                    }\n                }],\n                yAxes: [{\n                    display: true,\n                    scaleLabel: {\n                        display: true,\n                        labelString: 'Sales'\n                    }\n                }]\n            }\n        }\n    };\n}",
            "organisation": "31a05cfd-1275-4c76-8390-20b328a3c4bf",
            "dashboard": "47b6e961-a51c-4bf3-a9d4-01f30215cc42"
        },
        {
            "id": "85ebae13-f31f-418d-9a46-b0ee9ac8fa09",
            "title": "Total orders",
            "query": "Show me a metric for how many orders I have to date",
            "x": 8,
            "y": 0,
            "w": 4,
            "h": 1,
            "assumptions": [
                "1. The user wants to know the total number of orders to date.",
                "2. The 'Order ID' field from the array with key '74813926-d1ec-4b38-82e1-08d1820cb029' will be used to count the number of orders.",
                "3. The 'Order Date' field will be used to filter the orders up to the current date.",
                "4. The 'Customer ID' field will be used to match the data from both arrays.",
                "5. The validateNumber function will be used to ensure the 'Order ID' is a valid number before counting.",
                "6. The chart type will be set to 'metric' as per the user's request.",
                "7. The chart will display a single data point representing the total number of orders to date.",
                "8. The label for the data point will be 'Total Orders'."
            ],
            "code": "function main(data) {\n    let orders = data['74813926-d1ec-4b38-82e1-08d1820cb029'];\n    let currentDate = new Date();\n    let totalOrders = 0;\n    for (let i = 0; i < orders.length; i++) {\n        let orderDate = new Date(orders[i]['Order Date']);\n        if (orderDate <= currentDate && validateNumber(orders[i]['Order ID'])) {\n            totalOrders++;\n        }\n    }\n    return {\n        type: 'metric',\n        data: {\n            datasets: [{\n                data: [totalOrders],\n                label: 'Total Orders'\n            }]\n        },\n        options: {\n            responsive: true,\n            maintainAspectRatio: false,\n            scales: {\n                xAxes: [{\n                    display: true,\n                    scaleLabel: {\n                        display: true,\n                        labelString: 'Orders'\n                    }\n                }],\n                yAxes: [{\n                    display: true,\n                    scaleLabel: {\n                        display: true,\n                        labelString: 'Count'\n                    }\n                }]\n            }\n        }\n    };\n}",
            "organisation": "31a05cfd-1275-4c76-8390-20b328a3c4bf",
            "dashboard": "47b6e961-a51c-4bf3-a9d4-01f30215cc42"
        },
        {
            "id": "5734dba1-4392-4128-8deb-058b7f6517fe",
            "title": "Top 5 states by sales volume",
            "query": "Create a chart showing the top 5 states by sales volume",
            "x": 0,
            "y": 1,
            "w": 6,
            "h": 3,
            "assumptions": [],
            "code": "function main(data) {\n    // Extract the arrays from the data object\n    const customerData = data['44a3aa21-0181-46d9-a54b-af915aaec92e'];\n    const salesData = data['74813926-d1ec-4b38-82e1-08d1820cb029'];\n    // Create a map to store the total sales volume for each state\n    const stateSales = new Map();\n    // Iterate over the sales data\n    for (let i = 0; i < salesData.length; i++) {\n        // Find the corresponding customer data\n        const customer = customerData.find(c => c['Customer ID'] === salesData[i]['Customer ID']);\n        // If the customer data is found and the state is not yet in the map, add it\n        if (customer && !stateSales.has(customer.State)) {\n            stateSales.set(customer.State, validateNumber(salesData[i].Sales));\n        }\n        // If the state is already in the map, add the sales volume to the existing value\n        else if (customer) {\n            stateSales.set(customer.State, stateSales.get(customer.State) + validateNumber(salesData[i].Sales));\n        }\n    }\n    // Convert the map to an array and sort it in descending order by sales volume\n    const sortedStates = Array.from(stateSales).sort((a, b) => b[1] - a[1]);\n    // Limit the data to the top 5 states\n    const topStates = sortedStates.slice(0, 5);\n    // Create the data for the chart\n    const chartData = {\n        labels: topStates.map(s => s[0]),\n        datasets: [{\n            label: 'Sales Volume',\n            data: topStates.map(s => s[1]),\n            backgroundColor: 'rgba(75, 192, 192, 0.2)',\n            borderColor: 'rgba(75, 192, 192, 1)',\n            borderWidth: 1\n        }]\n    };\n    // Create the options for the chart\n    const chartOptions = {\n        responsive: true,\n        maintainAspectRatio: false,\n        scales: {\n            yAxes: [{\n                ticks: {\n                    beginAtZero: true\n                },\n                scaleLabel: {\n                    display: true,\n                    labelString: 'Sales Volume'\n                }\n            }],\n            xAxes: [{\n                scaleLabel: {\n                    display: true,\n                    labelString: 'State'\n                }\n            }]\n        }\n    };\n    // Return the chart configuration\n    return {\n        type: 'bar',\n        data: chartData,\n        options: chartOptions\n    };\n}",
            "organisation": "31a05cfd-1275-4c76-8390-20b328a3c4bf",
            "dashboard": "47b6e961-a51c-4bf3-a9d4-01f30215cc42"
        }
    ],
    "datasources": [
        {
            "id": "44a3aa21-0181-46d9-a54b-af915aaec92e",
            "created_at": "2023-09-01T11:39:30.716235+00:00",
            "last_updated_at": "2023-09-01T11:40:13.644+00:00",
            "title": "Customer data",
            "source": "file",
            "config": {
                "url": "http://localhost:54321/storage/v1/object/public/data-sources/31a05cfd-1275-4c76-8390-20b328a3c4bf/datasource:44a3aa21-0181-46d9-a54b-af915aaec92e/Sample%20Customers.csv",
                "type": "csv"
            },
            "columns": [
                {
                    "title": "Customer ID",
                    "description": "Customer ID is a unique key across tables"
                },
                {
                    "title": "City",
                    "description": "City"
                },
                {
                    "title": "Country",
                    "description": "Country"
                },
                {
                    "title": "Segment",
                    "description": "The segment of the customer"
                },
                {
                    "title": "State",
                    "description": "State"
                },
                {
                    "title": "Postal Code",
                    "description": "Postal Code"
                },
                {
                    "title": "Region",
                    "description": "Region"
                }
            ],
            "organisation": "31a05cfd-1275-4c76-8390-20b328a3c4bf",
            "parameters": []
        },
        {
            "id": "74813926-d1ec-4b38-82e1-08d1820cb029",
            "created_at": "2023-09-01T10:26:18.017866+00:00",
            "last_updated_at": "2023-09-06T15:17:27.333+00:00",
            "title": "Order data",
            "source": "file",
            "config": {
                "url": "http://localhost:54321/storage/v1/object/public/data-sources/31a05cfd-1275-4c76-8390-20b328a3c4bf/datasource:3f6aa55e-ba95-42e3-8a07-b4baceb0812d/Sample%20demo%20dataset%20-%20Sample%20Orders.csv",
                "type": "csv"
            },
            "columns": [
                {
                    "title": "Row ID",
                    "description": "Row ID"
                },
                {
                    "title": "Order ID",
                    "description": "Order ID"
                },
                {
                    "title": "Order Date",
                    "description": "Order Date"
                },
                {
                    "title": "Ship Date",
                    "description": "Ship Date"
                },
                {
                    "title": "Ship Mode",
                    "description": "Ship Mode"
                },
                {
                    "title": "Customer ID",
                    "description": "Customer ID"
                },
                {
                    "title": "Product ID",
                    "description": "Product ID"
                },
                {
                    "title": "Category",
                    "description": "Category"
                },
                {
                    "title": "Sub-Category",
                    "description": "Sub-Category"
                },
                {
                    "title": "Product Name",
                    "description": "Product Name"
                },
                {
                    "title": "Sales",
                    "description": "Sales"
                },
                {
                    "title": "Quantity",
                    "description": "Quantity"
                },
                {
                    "title": "Discount",
                    "description": "Discount"
                },
                {
                    "title": "Profit",
                    "description": "Profit"
                }
            ],
            "organisation": "31a05cfd-1275-4c76-8390-20b328a3c4bf",
            "parameters": []
        }
    ]
}