Skip to content

explain how to build a graph from a remote database please #230

Description

@SyntaxEvg

explain how to build a graph from a remote database please
select [date], [value] From bd.charts
How can I build a graph using my example, please explain
I need a for loop ?
https://sql.ophir.dev/documentation.sql?component=chart#component Example 1

select 
    'chart'             as component,
    'Quarterly Revenue' as title,
    'area'              as type,
    'indigo'            as color,
    5                   as marker,
    TRUE                as time;
select 
    '2022-01-01T00:00:00Z' as x,
    15                     as y;
select 
    '2022-04-01T00:00:00Z' as x,
    46                     as y;

Activity

  1. lovasoa commented on Feb 16, 2024

    @lovasoa
    Collaborator

    Hello and welcome to SQLPage !

    Let's say you have a table named charts with the following contents :

    date value
    2022-01-01 15
    2022-04-01 46

    and you want to generate the same graph as in the documentation.

    You start by connecting SQLPage to your database by editing sqlpage/sqlpage.json. Given the sql syntax you used above, it looks like you are using Microsoft SQL Server, so the connection string will have the following form, if the database is running locally on your computer (on localhost) :

    {
        "database_url": "mssql://username:password@localhost/YourDatabaseName"
    }

    Then you create a file named my_chart.sql with the following contents :

    select 
        'chart'             as component,
        'Quarterly Revenue' as title,
        'area'              as type,
        'indigo'            as color,
        5                   as marker,
        TRUE                as time;
    
    select 
        date as x,
        value as y
    from
        charts;

    The second select will fetch the values from your table and return them in the format expected by the SQLPage chart component.

    You can then launch SQLPage and open http://localhost:8080/my_chart.sql and you will see your graph appear.

  2. locked and limited conversation to collaborators on Feb 16, 2024
  3. converted this issue into a discussion #232 on Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions