Skip to content

Conversation

@medsriha
Copy link
Member

@medsriha medsriha commented Dec 16, 2025

This component converts a Pandas DataFrame into a JSON object compatible with Chart.js.

Usage Examples

import json
import pandas as pd

pandas_df = pd.DataFrame(
    {
        "date": ["2023-01-01", "2023-01-02", "2023-01-03"],
        "sales": [100, 150, 200],
        "expenses": [80, 120, 160],
    }
)

converter = PandasChartJSConverter(
    version="4",
    dataset_colors=["#36A2EB", "#FF6384"],
    background_color="white",
)

result = converter.run(
    dataframe=pandas_df,
    chart_columns_config='{"label_column": "date", "data_columns": ["sales", "expenses"]}',
    get_long_url=True,
    get_short_url=True,
)

print(json.dumps(result["chart_config"], indent=2))

Output

{
  "type": "bar",
  "data": {
    "labels": [
      "2023-01-01",
      "2023-01-02",
      "2023-01-03"
    ],
    "datasets": [
      {
        "label": "Sales",
        "data": [100, 150, 200],
        "backgroundColor": "#36A2EB",
        "borderColor": "#36A2EB"
      },
      {
        "label": "Expenses",
        "data": [80, 120, 160],
        "backgroundColor": "#FF6384",
        "borderColor": "#FF6384"
      }
    ]
  },
  "options": {
    "responsive": true
  }
}

Generated URLs

If enabled, the component also returns two URLs:

Long URL

Full URL with the entire chart configuration encoded in query parameters.

  • Self-contained and works immediately
  • No expiration
  • Can be very long (thousands of characters)
  • May break in some contexts (e.g., email clients or chat applications)

Short URL

A shortened, fixed-length URL that aliases the chart.

  • Easy to share
  • Always short and readable
  • Requires an API call to the QuickChart service
  • May expire depending on service policy
  • Falls back to the long URL if generation fails

@medsriha medsriha requested a review from a team as a code owner December 16, 2025 19:12
@medsriha medsriha requested review from vblagoje and removed request for a team December 16, 2025 19:12
@medsriha medsriha changed the title feat: adding pandas to chart component feat: graph.js generator Dec 16, 2025
@medsriha medsriha requested a review from sjrl December 16, 2025 19:30
@coveralls
Copy link

Pull Request Test Coverage Report for Build 20280353896

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+2.4%) to 72.992%

Totals Coverage Status
Change from base Build 20251961654: 2.4%
Covered Lines: 1227
Relevant Lines: 1681

💛 - Coveralls

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.

2 participants