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

Scatter Plot of Risk Against Return

Known issues

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

This walkthrough places one marker per symbol at its volatility and return, answering "Which symbols paid for their risk?"

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:

    1
    2
    3
    4
    CREATE PUBLIC TABLE ChartDemoRisk (Symbol String, Volatility Double, Return Double);
    INSERT INTO ChartDemoRisk VALUES ("MSFT", 18.2, 6.1), ("IBM", 14.5, 2.3), ("AAPL", 22.7, 8.4), ("JPM", 16.9, 4.0),
     ("NVDA", 41.3, 15.2), ("XOM", 20.1, -1.8), ("KO", 11.4, 1.2), ("TSLA", 48.6, -6.5);
    SELECT * FROM ChartDemoRisk;
    
  3. Check that the lower pane shows the 8 rows.

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 ChartDemoRisk, then "Next >>".
  4. Select "Test (alt+enter)", then "Next >>".
  5. Select the "Cartesian" tab, then the "Scatter Plot" tile.
  6. Set the fields below the tiles:

    Field Value
    "X:" Volatility
    "Y:" `Return`, in backticks, as filled in: return is an AmiScript word, so Return alone gives "Syntax error for Axis --> Y: Expecting ; but found End-of-Line"
    "Color by:" Symbol, as filled in, for one color per symbol
  7. Select "Finish".

  8. Check that the window shows 8 markers, from KO near (11.4, 1.2) to TSLA near (48.6, -6.5).

3. Make the markers larger

The markers start at "Marker Size(px):" 3 and are hard to see.

  1. Open the layer editor, Plot -> Edit Layers.
  2. Set "Marker Size(px):" to 10, then select "OK".
  3. Check that the markers are larger.

Result

8 markers, one color per symbol. The horizontal axis runs from about 10 to 50 and the vertical axis from -8 to 16; the exact ends depend on the window's size. The vertical axis is titled "Return", with the backticks.

The finished "Scatter Plot" chart: 8 markers, one color per symbol. The horizontal axis runs from about 10 to 50 and the vertical axis from -8 to 16; the exact ends depend on the window's size. The vertical axis is titled "Return", with the backticks

The chart's own PNG export, from AmiScript toImagePng; see Chart type walkthroughs.

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 layer reports Rows 8 and an empty Problem.

With your own data

The chart needs one row per point: a number for "X:" and a number for "Y:". In stage 2, select the "USER" tile of your table in place of ChartDemoRisk, and map your columns to the fields in stage 2's field table. Stage 2's check quotes the example data; on yours, check the same features against your own values. To filter rows, or to total raw rows first, see Using your own data.

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 ChartDemoRisk:

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

    {"windowName": "ChartDemoScatter", "datamodelId": "ChartDemoRisk", "dmTable": "ChartDemoRisk", "chartType": "scatter", "xField": "Volatility", "yField": "Return", "title": "ChartDemoScatter", "logScale": ""}
    
  3. Run the datamodel again with web_execute op=executeDatamodel, dmName ChartDemoRisk. 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.

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, ChartDemoRisk, and select "Delete Datamodel", then "Yes". If that name was taken when stage 2 ran, the gallery added a number to it, as in ChartDemoRisk1.
  3. Run DROP TABLE ChartDemoRisk; in the AMIDB Shell Tool.
  4. Check that SELECT * FROM ChartDemoRisk; reports Unknown table: ChartDemoRisk.

Over MCP, delete the chart with web_danger op=deletePanel, then the datamodel with op=deleteDatamodel, dmName ChartDemoRisk, 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.