Skip to content

Commit f6b97b7

Browse files
committed
docs updates
1 parent 30daea3 commit f6b97b7

1 file changed

Lines changed: 81 additions & 13 deletions

File tree

cmd/visualization/create.go

Lines changed: 81 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,88 @@ func newCreateCmd() *cobra.Command {
1414
cmd := &cobra.Command{
1515
Use: "create",
1616
Short: "Create a new visualization on an existing query",
17-
Long: "Create a visualization attached to an existing saved query.\n\n" +
18-
"The visualization type must be one of: chart, table, counter, pivot,\n" +
19-
"cohort, funnel, choropleth, sankey, sunburst_sequence, word_cloud.\n\n" +
20-
"The --options flag accepts a JSON string of visualization-specific\n" +
21-
"configuration (axes, series, formatting, etc.).\n\n" +
22-
"Examples:\n" +
23-
" dune viz create --query-id 12345 --name \"Token Volume\" --type chart\n" +
24-
" dune viz create --query-id 12345 --name \"Summary\" --type counter --options '{\"column\":\"total\",\"row_num\":1}'\n" +
25-
" dune viz create --query-id 12345 --name \"Results\" --type table -o json",
17+
Long: `Create a visualization attached to an existing saved query.
18+
19+
IMPORTANT: The --options flag is required for a working visualization. Without
20+
proper options, the visualization will fail to render. The options format depends
21+
on the visualization type.
22+
23+
Visualization types: chart, table, counter, pivot, cohort, funnel, choropleth,
24+
sankey, sunburst_sequence, word_cloud.
25+
26+
For chart type, set globalSeriesType to: column, line, area, scatter, or pie.
27+
28+
COUNTER (simplest — shows a single number):
29+
--type counter --options '{
30+
"counterColName": "<column>",
31+
"rowNumber": 1,
32+
"stringDecimal": 0,
33+
"stringPrefix": "",
34+
"stringSuffix": "",
35+
"counterLabel": "My Label",
36+
"coloredPositiveValues": false,
37+
"coloredNegativeValues": false
38+
}'
39+
40+
TABLE (displays query results as a table):
41+
--type table --options '{
42+
"itemsPerPage": 25,
43+
"columns": [
44+
{"name": "<column>", "title": "Display Name", "type": "normal",
45+
"alignContent": "left", "isHidden": false}
46+
]
47+
}'
48+
49+
COLUMN/LINE/AREA/SCATTER CHART:
50+
--type chart --options '{
51+
"globalSeriesType": "line",
52+
"sortX": true,
53+
"legend": {"enabled": true},
54+
"series": {"stacking": null},
55+
"xAxis": {"title": {"text": "Date"}},
56+
"yAxis": [{"title": {"text": "Value"}}],
57+
"columnMapping": {"<x_column>": "x", "<y_column>": "y"},
58+
"seriesOptions": {
59+
"<y_column>": {"type": "line", "yAxis": 0, "zIndex": 0}
60+
}
61+
}'
62+
63+
PIE CHART:
64+
--type chart --options '{
65+
"globalSeriesType": "pie",
66+
"sortX": true,
67+
"showDataLabels": true,
68+
"columnMapping": {"<category_column>": "x", "<value_column>": "y"},
69+
"seriesOptions": {
70+
"<value_column>": {"type": "pie", "yAxis": 0, "zIndex": 0}
71+
}
72+
}'
73+
74+
Column names in options must match actual query result columns exactly.
75+
76+
Examples:
77+
# Counter showing row count
78+
dune viz create --query-id 12345 --name "Total Count" --type counter \
79+
--options '{"counterColName":"count","rowNumber":1,"stringDecimal":0}'
80+
81+
# Line chart of daily volume
82+
dune viz create --query-id 12345 --name "Daily Volume" --type chart \
83+
--options '{"globalSeriesType":"line","sortX":true,"columnMapping":{"day":"x","volume":"y"},"seriesOptions":{"volume":{"type":"line","yAxis":0,"zIndex":0}},"xAxis":{"title":{"text":"Day"}},"yAxis":[{"title":{"text":"Volume"}}],"legend":{"enabled":true},"series":{"stacking":null}}'
84+
85+
# Simple table
86+
dune viz create --query-id 12345 --name "Results" --type table \
87+
--options '{"itemsPerPage":25,"columns":[{"name":"address","title":"Address","type":"normal","alignContent":"left","isHidden":false},{"name":"balance","title":"Balance","type":"normal","alignContent":"right","isHidden":false}]}'`,
2688
RunE: runCreate,
2789
}
2890

2991
cmd.Flags().Int("query-id", 0, "ID of the query to attach the visualization to (required)")
3092
cmd.Flags().String("name", "", "visualization name, max 300 characters (required)")
31-
cmd.Flags().String("type", "table", "visualization type: chart, table, counter, pivot, cohort, funnel, choropleth, sankey, sunburst_sequence, word_cloud")
93+
cmd.Flags().String("type", "table", "visualization type: chart, table, counter")
3294
cmd.Flags().String("description", "", "visualization description, max 1000 characters")
33-
cmd.Flags().String("options", "{}", "JSON string of visualization options")
95+
cmd.Flags().String("options", "", `visualization options JSON (required for working visualizations, see --help for format per type)`)
3496
_ = cmd.MarkFlagRequired("query-id")
3597
_ = cmd.MarkFlagRequired("name")
98+
_ = cmd.MarkFlagRequired("options")
3699
output.AddFormatFlag(cmd, "text")
37100

38101
return cmd
@@ -63,12 +126,17 @@ func runCreate(cmd *cobra.Command, _ []string) error {
63126
return err
64127
}
65128

129+
url := fmt.Sprintf("https://dune.com/embeds/%d/%d", queryID, resp.ID)
130+
66131
w := cmd.OutOrStdout()
67132
switch output.FormatFromCmd(cmd) {
68133
case output.FormatJSON:
69-
return output.PrintJSON(w, resp)
134+
return output.PrintJSON(w, map[string]any{
135+
"id": resp.ID,
136+
"url": url,
137+
})
70138
default:
71-
fmt.Fprintf(w, "Created visualization %d on query %d\n", resp.ID, queryID)
139+
fmt.Fprintf(w, "Created visualization %d on query %d\n%s\n", resp.ID, queryID, url)
72140
return nil
73141
}
74142
}

0 commit comments

Comments
 (0)