Add support for chart.js version parameter (#4)

This commit is contained in:
Ian Webster 2021-11-07 15:18:15 -08:00 committed by GitHub
parent fbb6deee1a
commit 3735d4d181
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 2 deletions

View file

@ -22,6 +22,7 @@ namespace QuickChart
public string Format { get; set; } public string Format { get; set; }
public string BackgroundColor { get; set; } public string BackgroundColor { get; set; }
public string Key { get; set; } public string Key { get; set; }
public string Version { get; set; }
public string Config { get; set; } public string Config { get; set; }
public string Scheme { get; set; } public string Scheme { get; set; }
@ -62,6 +63,10 @@ namespace QuickChart
{ {
builder.Append("&key=").Append(Uri.EscapeDataString(Key)); builder.Append("&key=").Append(Uri.EscapeDataString(Key));
} }
if (!string.IsNullOrEmpty(Version))
{
builder.Append("&v=").Append(Uri.EscapeDataString(Version));
}
return $"{Scheme}://{Host}:{Port}/chart?{builder}"; return $"{Scheme}://{Host}:{Port}/chart?{builder}";
} }
@ -85,6 +90,7 @@ namespace QuickChart
format = Format, format = Format,
chart = Config, chart = Config,
key = Key, key = Key,
version = Version,
}, options); }, options);
string url = $"{Scheme}://{Host}:{Port}/chart/create"; string url = $"{Scheme}://{Host}:{Port}/chart/create";
@ -123,6 +129,7 @@ namespace QuickChart
format = Format, format = Format,
chart = Config, chart = Config,
key = Key, key = Key,
version = Version,
}, options); }, options);
string url = $"{Scheme}://{Host}:{Port}/chart"; string url = $"{Scheme}://{Host}:{Port}/chart";

View file

@ -86,5 +86,32 @@ namespace QuickChartTest
Assert.Contains("h=300", url); Assert.Contains("h=300", url);
Assert.Contains("f=svg", url); Assert.Contains("f=svg", url);
} }
[Fact]
public void TestWithVersion()
{
Chart qc = new Chart
{
Width = 500,
Height = 300,
Format = "2.9.4",
Config = @"{
type: 'bar',
data: {
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
datasets: [{
label: 'Users',
data: [50, 60, 70, 180]
}]
}
}"
};
string url = qc.GetUrl();
Assert.Contains("https://quickchart.io:443/chart", url);
Assert.Contains("w=500", url);
Assert.Contains("h=300", url);
Assert.Contains("v=2.9.4", url);
}
} }
} }

View file

@ -26,6 +26,7 @@ Chart qc = new Chart();
qc.Width = 500; qc.Width = 500;
qc.Height = 300; qc.Height = 300;
qc.Version = "2.9.4";
qc.Config = @"{ qc.Config = @"{
type: 'bar', type: 'bar',
data: { data: {
@ -80,6 +81,9 @@ The device pixel ratio of the chart. This will multiply the number of pixels by
#### Format: string #### Format: string
The output format of the chart. Defaults to "png" The output format of the chart. Defaults to "png"
#### Version: string
Chart.js version (not required)
#### Key: string #### Key: string
API key (not required) API key (not required)