Skip to content

GoogleSheetsChartDataSource

ClassChartGuruChartGuru
[AddComponentMenu("ChartGuru/Data Sources/Google Sheets Chart Data Source")]
[DisallowMultipleComponent]
public sealed class GoogleSheetsChartDataSource : ChartFileDataSourceBase, IChartGuruElementDataSource, IChartDataSource

Convenience wrapper around ChartGuru.WebChartDataSource that converts a Google Sheets share URL into the matching CSV-export URL, then pulls + parses it on a configurable interval. The recipe also handles the most common gotchas — choosing the right gid, requesting CSV export instead of HTML, and decoding UTF-8.

To use:

  1. In Google Sheets: File → Share → Publish to web.
  2. Paste the shared sheet URL into `ChartGuru.GoogleSheetsChartDataSource.ShareUrl` (or paste the spreadsheet ID into `ChartGuru.GoogleSheetsChartDataSource.SpreadsheetId` and set `ChartGuru.GoogleSheetsChartDataSource.SheetGid`).
  3. Optionally set `ChartGuru.GoogleSheetsChartDataSource.PollIntervalSeconds` > 0 to refresh periodically.

public void Load(string shareUrl)

Set a Google Sheets share URL and immediately refresh. Convenience shortcut for ShareUrl = …; Refresh();.

Parameters

Name Type
shareUrl System.String
protected override string LoadText()

Subclasses override to obtain the raw text payload synchronously. Return an empty string to signal “no data”.

Returns

System.String

protected override Task<string> LoadTextAsync(CancellationToken ct)

Async variant. The default implementation invokes ChartGuru.ChartFileDataSourceBase.LoadText on a thread-pool worker. Subclasses with a true async pipeline (UnityWebRequest, file-stream ReadAsync) should override.

Parameters

Name Type
ct System.Threading.CancellationToken

Returns

System.Threading.Tasks.Task{System.String}

protected override ChartTabularData ParseToTabular(string rawText)

Convert raw text to a ChartGuru.ChartTabularData. Implemented per source (CSV vs JSON).

Parameters

Name Type
rawText System.String

Returns

ChartGuru.ChartTabularData

public override void Refresh()

Drive a synchronous load → parse → push cycle. Equivalent to ChartGuru.ChartFileDataSourceBase.ApplyData; provided as a more discoverable alias.

public static string ExtractSpreadsheetId(string url)

Extracts the stable spreadsheet identifier from a supported Google Sheets URL.

Parameters

Name Type
url System.String

Returns

System.String

public static string ExtractGid(string url)

Extracts the optional sheet-tab identifier from a Google Sheets URL.

Parameters

Name Type
url System.String

Returns

System.String

public GoogleSheetsChartDataSource()

public string ShareUrl { get; set; }

Returns

System.String

public string SpreadsheetId { get; set; }

Returns

System.String

public string SheetGid { get; set; }

Returns

System.String

public float PollIntervalSeconds { get; set; }

Returns

System.Single

public string ResolvedExportUrl { get; }

Returns

System.String