Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new api to_chart_html #471

Merged
merged 1 commit into from Mar 8, 2024

Conversation

longxiaofei
Copy link
Member

@longxiaofei longxiaofei commented Mar 8, 2024

new api to_chart_html

API Reference

def to_chart_html(
    dataset: Union[DataFrame, Connector, str],
    spec: Dict[str, Any],
    *,
    spec_type: Literal["graphic-walker", "vega"] = "graphic-walker",
    theme_key: Literal['vega', 'g2'] = 'g2',
    dark: Literal['media', 'light', 'dark'] = 'media',
) -> str:
    """
    Generate HTML code of a chart by graphic-walker or vega spec.

    Args:
        - dataset (pl.DataFrame | pd.DataFrame | Connector, optional): dataset.
        - spec (Dict[str, Any]): chart config data.

    Kargs:
        - spec_type (Literal["graphic-walker", "vega"]): type of spec.
        - theme_key ('vega' | 'g2'): theme type.
        - dark ('media' | 'light' | 'dark'): 'media': auto detect OS theme.
    """
    pass

Example

from pygwalker.api.html import to_chart_html
from IPython.display import display, HTML

html = to_chart_html(
    df,
    {
        "mark": "bar",
        "encoding": {
            "x": {"field": "season"},
            "y": {"field": "casual", "aggregate": "sum"},
            "color": {"field": "holiday"},
        }
    },
    spec_type="vega"
)

display(HTML(html))

image

@longxiaofei longxiaofei merged commit ab1e8f9 into Kanaries:main Mar 8, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant