ChartSQL
AboutProductDownloadCommunity
  • Basics
    • Intro
    • Quick Start
  • CHARTS
    • Overview
    • Auto Charts
    • Area
    • Bar
    • Bubble
    • Column
    • Combo
    • Gauge
    • Heatmap
    • Line
    • Pie
    • Radar
    • Scatter
    • Formatting & Rendering
      • Baselines
      • Formats
      • Series Titles
      • Series Labels
      • Stacked Charts
      • Grouped Category
  • ChartSQL Studio
    • Overview
    • ChartSQL Studio Cloud
    • Installing Studio Desktop
    • Basic Concepts
      • Interface Overview
      • Workspace
      • SQL Scripts & Charts
      • Folders
      • Datasources
      • Thinking in ChartSQL
    • Creating Charts
      • Editor Panels
      • Column Data Types
      • Chart Types
      • Directives
      • Stacking
      • Baselines
      • Series Titles
      • Dynamic SQL Charts
      • Dynamic Data Functions
    • Presenting
    • Settings & Customization
    • Troubleshooting & Support
    • Datasources
      • Overview
      • CSV File
      • HyperSQL
      • MongoDB
      • MySQL
      • PostgreSQL
      • SQLite
      • Custom Datasources
    • Extensions
      • Overview
      • Extension Points
      • Core Extensions
      • Extensions API Reference
  • Dashboards
    • Coming Soon
  • ChartSQL JS
    • Coming Soon
  • Reference
    • Auto Charts
    • Directives
      • @baselines
      • @baseline-types
      • @chart
      • @category
      • @formats
      • @series
      • @title
      • @subtitle
      • @groups
      • @series-types
      • @series-labels
      • @stacking-mode
      • //@directive: comments
      • @dash-id
      • @overlay-series
      • @tags
      • @select-list
    • Glossary
    • Shortcuts
    • Publishing API
  • Product & Community
    • About
    • Features
    • Use Cases
      • General Uses
      • For SQL Developers
      • For Application Developers
      • For Agencies
      • For Data Science Teams
    • Community & Support
    • Roadmap
    • Release Notes
    • In Development
      • Workspaces
      • Dashboards
        • Intro
        • Dashboards
        • Packages
        • Pages
        • Charts
        • Access Control
      • Sharing & Publishing
      • ChartSQL.js
        • Overview
      • @threshold
      • Thresholds
      • Sheets
Powered by GitBook

Support

  • Discord
  • X

ChartSQL

On this page
  • Basic Bar Chart
  • Bar chart with Parent and Sub Category Groups
  • Bar Chart with Formats
  • Bar with Stacking
  • Heading

Was this helpful?

  1. CHARTS

Bar

Example Bar Charts

PreviousAreaNextBubble

Last updated 1 year ago

Was this helpful?

Basic Bar Chart

-- @chart: bar
-- @title: Bar Chart
-- @subtitle: An basic example of a bar chart
SELECT 
Channel,
count(*) as Won_Sales
FROM Sales
WHERE Status = 'Won'
GROUP BY Channel
ORDER BY Won_Sales DESC;
CHANNEL
WON_SALES

pr_ad

21.0

coldcall

37.0

search

66.0

event

112.0

referral

243.0

Bar chart with Parent and Sub Category Groups

-- @chart: bar
-- @title: Groups - Multiple category groups
-- @subtitle: An example of multiple category groups
-- @groups: Channel, Owner
-- @series: TotalSales
-- @formats: currency
SELECT 
	Final.*
FROM (  
  SELECT 
  	Channel,    
  	Owner,
    (
      SELECT sum(Sub.Amount)
      FROM Sales Sub
      WHERE Sub.Channel = Sales.Channel
    ) as TotalChannelSales,
    sum(Amount) as TotalSales
  FROM Sales
  WHERE Owner IN (
    SELECT Owner
    FROM Sales
    GROUP BY Owner
    ORDER BY sum(Amount)
    LIMIT 10
  )
  GROUP BY Channel, Owner
) as Final
ORDER BY TotalChannelSales DESC, TotalSales DESC
CHANNEL
OWNER
TOTALCHANNELSALES
TOTALSALES

pr_ad

Kim

9181300.0

84603.0

pr_ad

Roger

9181300.0

118985.0

pr_ad

Lucy

9181300.0

138374.0

pr_ad

Norbit

9181300.0

141711.0

pr_ad

Justice

9181300.0

160517.0

pr_ad

Heather

9181300.0

239870.0

pr_ad

Peter

9181300.0

266655.0

pr_ad

Tammy

9181300.0

501805.0

coldcall

Justice

1.7372264E7

87207.0

coldcall

Heather

1.7372264E7

162974.0

coldcall

Norbit

1.7372264E7

333648.0

Bar Chart with Formats

-- @chart: bar
-- @title: Bar Chart With Formats
-- @subtitle: An example bar chart with formats
-- @formats: currency
SELECT 
Channel,
sum(Amount) as Total_Sales
FROM Sales
WHERE Status = 'Won'
GROUP BY Channel
ORDER BY Total_Sales DESC;
CHANNEL
TOTAL_SALES

pr_ad

1716590.0

coldcall

3267837.0

search

6320993.0

event

1.1198055E7

referral

2.6029056E7

Bar with Stacking

-- @chart: bar
-- @title: Bar Stacking - Example bar chart with stacking
-- @groups: Owner, Channel
-- @subtitle: An example bar chart that has a single stack
-- @formats: currency
-- @series: Sales
-- @stacks: Channel
SELECT *
FROM (  
  SELECT 
      Owner,
      Channel,
      (
        SELECT sum(Amount)
        FROM Sales Sub
        WHERE Sub.Owner = Sales.Owner
      ) as OwnerTotal,
      sum(amount) as Sales
  FROM sales
  GROUP BY Owner, Channel
) as Final
ORDER BY Final.OwnerTotal ASC, Sales DESC;
OWNER
CHANNEL
OWNERTOTAL
SALES

Roger

referral

1459150.0

607758.0

Roger

coldcall

1459150.0

365129.0

Roger

search

1459150.0

223080.0

Roger

event

1459150.0

144198.0

Roger

pr_ad

1459150.0

118985.0

Lucy

referral

1460022.0

914463.0

Lucy

event

1460022.0

267908.0

Lucy

search

1460022.0

139277.0

Lucy

pr_ad

1460022.0

138374.0

Kim

referral

1768826.0

1338296.0

Kim

search

1768826.0

177605.0

Kim

event

1768826.0

168322.0

Kim

pr_ad

1768826.0

84603.0

Grenda

referral

2411989.0

1567753.0

Grenda

event

2411989.0

511020.0

Grenda

search

2411989.0

333216.0

Irene

referral

2798575.0

1698665.0

Irene

search

2798575.0

706034.0

Irene

event

2798575.0

393876.0

Norbit

referral

2921665.0

1282432.0

Norbit

event

2921665.0

722410.0

Norbit

search

2921665.0

441464.0

Norbit

coldcall

2921665.0

333648.0

Norbit

pr_ad

2921665.0

141711.0

Justice

referral

3292632.0

1971882.0

Justice

search

3292632.0

638796.0

Justice

event

3292632.0

434230.0

Justice

pr_ad

3292632.0

160517.0

Heading

An example of a bar chart
An example bar chart with group parent and sub category
An example bar chart with specified currency format
An example bar chart with stacking
Cover
Cover
Cover
Cover
Basic Bar Chart
Bar chart with Parent and Sub Category Groups
Bar Chart with Formats
Bar with Stacking