Skip to content
Web > Charts > Chart Type Walkthroughs > Cartesian

Calendar of Daily P&L

Known issues

Some chart features have known issues in the current release. See Known issues.

This walkthrough colors one cell per trading day by its profit or loss, answering "Which days lost money?"

Prerequisites

  • Editor mode: click once on the screen, then press Ctrl+d. The AMIDB Shell Tool and the gallery are used as in the quickstart.
  • Data: the example data that stage 1 creates. To use a table of your own instead, see With your own data.

1. Create the example data

The chart reads a table in the Center, so create the table first.

  1. Select Dashboard -> AMIDB Shell Tool....
  2. Run:

    CREATE PUBLIC TABLE ChartDemoDailyPnl (Day UTC, Pnl Double);
    INSERT INTO ChartDemoDailyPnl VALUES
     (parseDate("2026-09-28", "yyyy-MM-dd", "EST5EDT"), 12),
     (parseDate("2026-09-29", "yyyy-MM-dd", "EST5EDT"), -4),
     (parseDate("2026-09-30", "yyyy-MM-dd", "EST5EDT"), 7),
     (parseDate("2026-10-01", "yyyy-MM-dd", "EST5EDT"), 15),
     (parseDate("2026-10-02", "yyyy-MM-dd", "EST5EDT"), -9),
     (parseDate("2026-10-05", "yyyy-MM-dd", "EST5EDT"), 3),
     (parseDate("2026-10-06", "yyyy-MM-dd", "EST5EDT"), 21),
     (parseDate("2026-10-07", "yyyy-MM-dd", "EST5EDT"), -2),
     (parseDate("2026-10-08", "yyyy-MM-dd", "EST5EDT"), 8),
     (parseDate("2026-10-09", "yyyy-MM-dd", "EST5EDT"), -14),
     (parseDate("2026-10-12", "yyyy-MM-dd", "EST5EDT"), 5),
     (parseDate("2026-10-13", "yyyy-MM-dd", "EST5EDT"), 11);
    SELECT * FROM ChartDemoDailyPnl;
    
  3. Check that the lower pane shows the 12 rows.

The dates are stored at midnight New York time, the default user time zone, so each one falls on its own day. See Dates on an axis.

2. Create the chart

The gallery creates a datamodel that reads the table, then places the chart.

  1. Select Windows -> New Window, then the edit button on Blank1, then "Create Table / Visualization / Form".
  2. Select "AMI (__AMI)", then "Next >>".
  3. Select the "USER" tile ChartDemoDailyPnl, then "Next >>".
  4. Select "Test (alt+enter)", then "Next >>".
  5. Select the "Cartesian" tab, then the "Calendar" tile.
  6. Set the fields below the tiles:

    Field Value
    "Date:" Day
    "Value:" Pnl
  7. Select "Finish".

  8. Check that the window shows a column for 2026-09 and one for 2026-10, with a cell per day, the lowest value, -14 on Oct 9, brightest red, and the highest, 21 on Oct 6, brightest green.

The colors run from red at the lowest value to green at the highest, darkest midway between them, not at zero: here at about 3.5, so a small gain can look as dark as a small loss, and on data that is all gains the smallest gain is red.

Result

A column per month and a row per day of the month, with a cell for each of the 12 days. It is the only template that fills in hover text, such as "2026-10-06: 21.0".

To check without looking, read the render stats: session.getDevTools().getAllRenderStats() in the AMIDB Shell Tool, with "Run on this web session" selected (see Running a script), or web_debug op=panelRenderStats over MCP. The "Cells" layer reports Rows 12 and an empty Problem.

With your own data

If your table holds trades rather than one row per day, shape the rows in the datamodel's query. To try it on the example trades, create ChartDemoTrades as in Using your own data.

  1. Follow stage 2 with the "USER" tile ChartDemoTrades, or the one for your own table, in place of ChartDemoDailyPnl.
  2. When the gallery shows the datamodel's query, replace the query with:

    1
    2
    3
    {
      CREATE TABLE ChartDemoDailyPnl AS EXECUTE SELECT (UTC) parseDate(formatDate(Time, "yyyy-MM-dd", "EST5EDT"), "yyyy-MM-dd", "EST5EDT") AS Day, sum(Pnl) AS Pnl FROM ChartDemoTrades WHERE ${WHERE} GROUP BY formatDate(Time, "yyyy-MM-dd", "EST5EDT") ORDER BY Day;
    }
    
  3. Select "Test (alt+enter)".

  4. Check that the "Tables" tab shows ChartDemoDailyPnl alone, 3 rows: 115 on Oct 7, 50 on Oct 8, and 180 on Oct 9.

Then continue with stage 2: the fields are the same, and any later stages apply as written. To do this over MCP, put the same statements in the onProcess of the datamodel that step 1 of "Over MCP" imports, with USE ds="AMI" before each EXECUTE.

The query totals each New York day's Pnl. (UTC) keeps "Day" a date, which "Date:" needs. The chart then shows 3 cells.

Over MCP

An agent builds the same chart from the same table. Connecting an agent is covered in the AI section; the tools are on Building charts over MCP.

  1. Create the datamodel with web_execute op=importDatamodel and this dmJson, then run it once with op=initDatamodelSchema and dmName ChartDemoDailyPnl:

    {"id": "ChartDemoDailyPnl", "queryMode": "startup", "callbacks": [{"name": "onProcess", "amiscript": ["{ CREATE TABLE ChartDemoDailyPnl AS USE ds=\"AMI\" EXECUTE SELECT * FROM ChartDemoDailyPnl; }"]}]}
    
  2. Create the chart:

    {"windowName": "ChartDemoCalendar", "templateKey": "tplCalendar", "datamodelId": "ChartDemoDailyPnl", "dmTable": "ChartDemoDailyPnl", "title": "ChartDemoCalendar", "bindings": "{\"DT\": \"Day\", \"VAL\": \"Pnl\"}"}
    
  3. Run the datamodel again with web_execute op=executeDatamodel, dmName ChartDemoDailyPnl. A chart created over MCP can stay empty until its datamodel runs again, with its axes at 0-100.

  4. Confirm that every layer reports the rows above and an empty Problem: run web_debug op=panelRenderStats.

The call is web_create_chart_from_template.

Removing the example

Remove the chart, then its datamodel, then the table, so that the next walkthrough can reuse the names:

  1. Close the chart's window with its close button, and select "Delete" when asked whether to delete the panel.
  2. Select Dashboard -> Data Modeler..., expand "Datamodels", right-click the chart's datamodel, ChartDemoDailyPnl, and select "Delete Datamodel", then "Yes". If that name was taken when stage 2 ran, the gallery added a number to it, as in ChartDemoDailyPnl1.
  3. Run DROP TABLE ChartDemoDailyPnl; in the AMIDB Shell Tool.
  4. Check that SELECT * FROM ChartDemoDailyPnl; reports Unknown table: ChartDemoDailyPnl.

Over MCP, delete the chart with web_danger op=deletePanel, then the datamodel with op=deleteDatamodel, dmName ChartDemoDailyPnl, and drop the table as in step 3. deleteDatamodel refuses a datamodel that has been committed; delete that one in the Data Modeler as in step 2. See Removing an agent's chart.