GoogleSheetsChartDataSource
public sealed class GoogleSheetsChartDataSource : ChartFileDataSourceBaseConvenience wrapper around 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:
- In Google Sheets: File → Share → Publish to web.
- Paste the shared sheet URL into
GoogleSheetsChartDataSource.ShareUrl(or paste the spreadsheet ID intoGoogleSheetsChartDataSource.SpreadsheetIdand setGoogleSheetsChartDataSource.SheetGid). - Optionally set
GoogleSheetsChartDataSource.PollIntervalSeconds> 0 to refresh periodically.
Methods
Section titled “Methods”
Load(string)
Section titled “Load(string)”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 |
LoadText()
Section titled “LoadText()”protected override string LoadText()Subclasses override to obtain the raw text payload synchronously. Return an empty string to signal "no data".
Returns
System.String
LoadTextAsync(CancellationToken)
Section titled “LoadTextAsync(CancellationToken)”protected override Task<string> LoadTextAsync(CancellationToken ct)Async variant. The default implementation snapshots the source text on
the Unity thread because a source may read a TextAsset.
Subclasses with a true async pipeline should override.
Parameters
| Name | Type |
|---|---|
ct |
System.Threading.CancellationToken |
Returns
System.Threading.Tasks.Task{System.String}
ParseToTabular(string)
Section titled “ParseToTabular(string)”protected override ChartTabularData ParseToTabular(string rawText)Convert raw text to a ChartTabularData. Implemented per source (CSV vs JSON).
Parameters
| Name | Type |
|---|---|
rawText |
System.String |
Returns
ChartGuru.ChartTabularData
Refresh()
Section titled “Refresh()”public override void Refresh()Queues an asynchronous fetch; the sheet is published when it arrives.
ExtractSpreadsheetId(string)
Section titled “ExtractSpreadsheetId(string)”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
ExtractGid(string)
Section titled “ExtractGid(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
Constructors
Section titled “Constructors”
GoogleSheetsChartDataSource()
Section titled “GoogleSheetsChartDataSource()”public GoogleSheetsChartDataSource()Properties
Section titled “Properties”
ShareUrl
Section titled “ShareUrl”public string ShareUrl { get; set; }Returns
System.String
SpreadsheetId
Section titled “SpreadsheetId”public string SpreadsheetId { get; set; }Returns
System.String
SheetGid
Section titled “SheetGid”public string SheetGid { get; set; }Returns
System.String
PollIntervalSeconds
Section titled “PollIntervalSeconds”public float PollIntervalSeconds { get; set; }Returns
System.Single
AutoApplyInEditMode
Section titled “AutoApplyInEditMode”protected override bool AutoApplyInEditMode { get; }Whether this source should populate an edit-mode preview when enabled.
Returns
System.Boolean
ResolvedExportUrl
Section titled “ResolvedExportUrl”public string ResolvedExportUrl { get; }Returns
System.String