From 14c7cbb2aed54781c93a964a71de756f24f702e8 Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Tue, 21 Sep 2021 08:27:24 -0700 Subject: [PATCH 01/11] Add test for Format and update readme (#3) --- QuickChartTest/QuickChartTest.cs | 57 +++++++++++++++++++++++--------- README.md | 3 ++ 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/QuickChartTest/QuickChartTest.cs b/QuickChartTest/QuickChartTest.cs index 9ed2b1b..4141d40 100644 --- a/QuickChartTest/QuickChartTest.cs +++ b/QuickChartTest/QuickChartTest.cs @@ -10,20 +10,20 @@ namespace QuickChartTest [Fact] public void TestBasic() { - Chart qc = new Chart - { - Width = 500, - Height = 300, + Chart qc = new Chart + { + Width = 500, + Height = 300, Config = @"{ type: 'bar', data: { labels: ['Q1', 'Q2', 'Q3', 'Q4'], datasets: [{ - label: 'Users', - data: [50, 60, 70, 180] + label: 'Users', + data: [50, 60, 70, 180] }] } - }" + }" }; string url = qc.GetUrl(); @@ -36,21 +36,21 @@ namespace QuickChartTest [Fact] public void TestWithKey() { - Chart qc = new Chart - { - Key = "abc123", - Width = 500, - Height = 300, + Chart qc = new Chart + { + Key = "abc123", + Width = 500, + Height = 300, Config = @"{ type: 'bar', data: { labels: ['Q1', 'Q2', 'Q3', 'Q4'], datasets: [{ - label: 'Users', - data: [50, 60, 70, 180] + label: 'Users', + data: [50, 60, 70, 180] }] } - }" + }" }; string url = qc.GetUrl(); @@ -59,5 +59,32 @@ namespace QuickChartTest Assert.Contains("h=300", url); Assert.Contains("key=abc123", url); } + + [Fact] + public void TestWithFormat() + { + Chart qc = new Chart + { + Width = 500, + Height = 300, + Format = "svg", + 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("f=svg", url); + } } } diff --git a/README.md b/README.md index 7524eec..a54f56b 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,9 @@ The background color of the chart. Any valid HTML color works. Defaults to #ffff #### DevicePixelRatio: double The device pixel ratio of the chart. This will multiply the number of pixels by the value. This is usually used for retina displays. Defaults to 1.0. +#### Format: string +The output format of the chart. Defaults to "png" + #### Key: string API key (not required) From f96e2a3adf307e9208a8dfef213df2fad3fb85c4 Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Tue, 21 Sep 2021 08:37:01 -0700 Subject: [PATCH 02/11] formatting --- QuickChart/QuickChart.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QuickChart/QuickChart.cs b/QuickChart/QuickChart.cs index eb03464..007ac19 100644 --- a/QuickChart/QuickChart.cs +++ b/QuickChart/QuickChart.cs @@ -19,7 +19,7 @@ namespace QuickChart public int Width { get; set; } public int Height { get; set; } public double DevicePixelRatio { get; set; } - public string Format {get;set;} + public string Format { get; set; } public string BackgroundColor { get; set; } public string Key { get; set; } public string Config { get; set; } From fbb6deee1a4db3b76bfae57ffa068bfe4c545ec4 Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Tue, 21 Sep 2021 08:37:04 -0700 Subject: [PATCH 03/11] bump version --- QuickChart.sln | 10 +++++----- QuickChart/QuickChart.csproj | 3 +-- README.md | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/QuickChart.sln b/QuickChart.sln index 70c2fcc..8558119 100644 --- a/QuickChart.sln +++ b/QuickChart.sln @@ -9,7 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickChartExamples", "QuickChartExamples\QuickChartExamples.csproj", "{52AC08E4-5A20-4A46-A117-BFAC03BB7940}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickChartTest", "QuickChartTest\QuickChartTest.csproj", "{0CEF2268-6F2B-4DEB-B152-DDA0B09ABEDA}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickChartTest", "QuickChartTest\QuickChartTest.csproj", "{21C67AF9-6B21-4FA3-A203-294C36DC7F2A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -25,10 +25,10 @@ Global {52AC08E4-5A20-4A46-A117-BFAC03BB7940}.Debug|Any CPU.Build.0 = Debug|Any CPU {52AC08E4-5A20-4A46-A117-BFAC03BB7940}.Release|Any CPU.ActiveCfg = Release|Any CPU {52AC08E4-5A20-4A46-A117-BFAC03BB7940}.Release|Any CPU.Build.0 = Release|Any CPU - {0CEF2268-6F2B-4DEB-B152-DDA0B09ABEDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0CEF2268-6F2B-4DEB-B152-DDA0B09ABEDA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0CEF2268-6F2B-4DEB-B152-DDA0B09ABEDA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0CEF2268-6F2B-4DEB-B152-DDA0B09ABEDA}.Release|Any CPU.Build.0 = Release|Any CPU + {21C67AF9-6B21-4FA3-A203-294C36DC7F2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {21C67AF9-6B21-4FA3-A203-294C36DC7F2A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {21C67AF9-6B21-4FA3-A203-294C36DC7F2A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {21C67AF9-6B21-4FA3-A203-294C36DC7F2A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/QuickChart/QuickChart.csproj b/QuickChart/QuickChart.csproj index 40d4769..55c4136 100644 --- a/QuickChart/QuickChart.csproj +++ b/QuickChart/QuickChart.csproj @@ -6,7 +6,6 @@ true Ian Webster Ian Webster 2020 - https://github.com/typpo/quickchart-csharp/blob/main/LICENSE MIT QuickChart https://github.com/typpo/quickchart-csharp @@ -14,7 +13,7 @@ chart image, chart api, chart, charts, image charts QuickChart Client library for the QuickChart Chart API, used to generate chart images. - 2.0.0 + 2.1.0 QuickChart diff --git a/README.md b/README.md index a54f56b..367158a 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ A C# client for the [quickchart.io](https://quickchart.io/) chart API. Use `QuickChart/QuickChart.cs` in this project, or install the `QuickChart` package from [NuGet](https://www.nuget.org/packages/QuickChart): ``` -PM> Install-Package QuickChart -Version 2.0.0 +PM> Install-Package QuickChart -Version 2.1.0 ``` or ``` -dotnet add package QuickChart --version 2.0.0 +dotnet add package QuickChart --version 2.1.0 ``` --- ## Usage From 3735d4d1818547b9230fc9be3d79524efc3725a6 Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Sun, 7 Nov 2021 15:18:15 -0800 Subject: [PATCH 04/11] Add support for chart.js version parameter (#4) --- QuickChart/QuickChart.cs | 7 +++++++ QuickChartTest/QuickChartTest.cs | 27 +++++++++++++++++++++++++++ README.md | 8 ++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/QuickChart/QuickChart.cs b/QuickChart/QuickChart.cs index 007ac19..b485bd1 100644 --- a/QuickChart/QuickChart.cs +++ b/QuickChart/QuickChart.cs @@ -22,6 +22,7 @@ namespace QuickChart public string Format { get; set; } public string BackgroundColor { get; set; } public string Key { get; set; } + public string Version { get; set; } public string Config { get; set; } public string Scheme { get; set; } @@ -62,6 +63,10 @@ namespace QuickChart { builder.Append("&key=").Append(Uri.EscapeDataString(Key)); } + if (!string.IsNullOrEmpty(Version)) + { + builder.Append("&v=").Append(Uri.EscapeDataString(Version)); + } return $"{Scheme}://{Host}:{Port}/chart?{builder}"; } @@ -85,6 +90,7 @@ namespace QuickChart format = Format, chart = Config, key = Key, + version = Version, }, options); string url = $"{Scheme}://{Host}:{Port}/chart/create"; @@ -123,6 +129,7 @@ namespace QuickChart format = Format, chart = Config, key = Key, + version = Version, }, options); string url = $"{Scheme}://{Host}:{Port}/chart"; diff --git a/QuickChartTest/QuickChartTest.cs b/QuickChartTest/QuickChartTest.cs index 4141d40..fca83bb 100644 --- a/QuickChartTest/QuickChartTest.cs +++ b/QuickChartTest/QuickChartTest.cs @@ -86,5 +86,32 @@ namespace QuickChartTest Assert.Contains("h=300", 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); + } } } diff --git a/README.md b/README.md index 367158a..b1ac086 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,14 @@ Chart qc = new Chart(); qc.Width = 500; qc.Height = 300; +qc.Version = "2.9.4"; qc.Config = @"{ type: 'bar', data: { labels: ['Q1', 'Q2', 'Q3', 'Q4'], datasets: [{ - label: 'Users', - data: [50, 60, 70, 180] + label: 'Users', + data: [50, 60, 70, 180] }] } }"; @@ -80,6 +81,9 @@ The device pixel ratio of the chart. This will multiply the number of pixels by #### Format: string The output format of the chart. Defaults to "png" +#### Version: string +Chart.js version (not required) + #### Key: string API key (not required) From 6bf090b391f55b1e88d94710e681a01a3811b2b8 Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Sun, 7 Nov 2021 15:20:21 -0800 Subject: [PATCH 05/11] Fix test --- QuickChartTest/QuickChartTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QuickChartTest/QuickChartTest.cs b/QuickChartTest/QuickChartTest.cs index fca83bb..72e67ab 100644 --- a/QuickChartTest/QuickChartTest.cs +++ b/QuickChartTest/QuickChartTest.cs @@ -94,7 +94,7 @@ namespace QuickChartTest { Width = 500, Height = 300, - Format = "2.9.4", + Version = "2.9.4", Config = @"{ type: 'bar', data: { From 32d5ada399339c188a16a55a93294c2e422129df Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Sun, 7 Nov 2021 15:20:30 -0800 Subject: [PATCH 06/11] Bump to version 2.2.0 --- QuickChart/QuickChart.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QuickChart/QuickChart.csproj b/QuickChart/QuickChart.csproj index 55c4136..3e5416c 100644 --- a/QuickChart/QuickChart.csproj +++ b/QuickChart/QuickChart.csproj @@ -5,7 +5,7 @@ netcoreapp3.1;netstandard2.0;net472 true Ian Webster - Ian Webster 2020 + Ian Webster MIT QuickChart https://github.com/typpo/quickchart-csharp @@ -13,7 +13,7 @@ chart image, chart api, chart, charts, image charts QuickChart Client library for the QuickChart Chart API, used to generate chart images. - 2.1.0 + 2.2.0 QuickChart From 03ac2f63d673a218cebe40a0db04aa126e3dd137 Mon Sep 17 00:00:00 2001 From: dianaduca <94049431+dianaduca@users.noreply.github.com> Date: Sat, 12 Mar 2022 02:11:32 +0000 Subject: [PATCH 07/11] Add ability to specify chart generation url for self hosted QuickChart (#5) * Add ability to specify chart generation url for self hosted QuickChart * Add more configuration setting: if user specify: a host only, default to https:443, a host and http, set port to 80 a host and https, set port to 443 Co-authored-by: Duca Diana --- QuickChart/QuickChart.cs | 39 ++++++++++++++++++++++++++++---- QuickChartTest/QuickChartTest.cs | 27 ++++++++++++++++++++++ 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/QuickChart/QuickChart.cs b/QuickChart/QuickChart.cs index b485bd1..93ba667 100644 --- a/QuickChart/QuickChart.cs +++ b/QuickChart/QuickChart.cs @@ -31,7 +31,7 @@ namespace QuickChart private static readonly HttpClient Client = new HttpClient(); - public Chart() + public Chart(string scheme = null, string host = null, int? port = null) { Width = 500; Height = 300; @@ -39,9 +39,40 @@ namespace QuickChart Format = "png"; BackgroundColor = "transparent"; - Scheme = "https"; - Host = "quickchart.io"; - Port = 443; + if (host != null) + { + Host = host; + if (scheme != null) + { + Scheme = scheme; + if (port.HasValue) + { + Port = port.Value; + } + else + { + if(scheme == "http") + { + Port = 80; + } + else + { + Port = 443; + } + } + } + else + { + Scheme = "https"; + Port = 443; + } + } + else + { + Scheme = "https"; + Host = "quickchart.io"; + Port = 443; + } } public string GetUrl() diff --git a/QuickChartTest/QuickChartTest.cs b/QuickChartTest/QuickChartTest.cs index 72e67ab..810a598 100644 --- a/QuickChartTest/QuickChartTest.cs +++ b/QuickChartTest/QuickChartTest.cs @@ -113,5 +113,32 @@ namespace QuickChartTest Assert.Contains("h=300", url); Assert.Contains("v=2.9.4", url); } + + [Fact] + public void TestWithSelfHostingQuickChart() + { + var scheme = "http"; + var host = "localhost"; + var port = 47000; + Chart qc = new Chart(scheme, host, port); + qc.Width = 500; + qc.Height = 300; + qc.Config = @"{ + type: 'bar', + data: { + labels: ['Q1', 'Q2', 'Q3', 'Q4'], + datasets: [{ + label: 'Users', + data: [50, 60, 70, 180] + }] + }[] + }"; + + string url = qc.GetUrl(); + Assert.Contains($"{scheme}://{host}:{port}/chart", url); + Assert.Contains("w=500", url); + Assert.Contains("h=300", url); + Assert.DoesNotContain("key=", url); + } } } From 306a40d4d595c6ac460b21b7532633c8c597f97f Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Mon, 14 Mar 2022 23:12:40 -0700 Subject: [PATCH 08/11] bump version to 2.3.0 --- QuickChart/QuickChart.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QuickChart/QuickChart.csproj b/QuickChart/QuickChart.csproj index 3e5416c..6d88026 100644 --- a/QuickChart/QuickChart.csproj +++ b/QuickChart/QuickChart.csproj @@ -13,7 +13,7 @@ chart image, chart api, chart, charts, image charts QuickChart Client library for the QuickChart Chart API, used to generate chart images. - 2.2.0 + 2.3.0 QuickChart From 491ab2d0ee5cd9b99569cb4d9ec0372c016212fe Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Sat, 24 Sep 2022 08:59:24 -0700 Subject: [PATCH 09/11] Add link to reference --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1ac086..ca49b73 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ The device pixel ratio of the chart. This will multiply the number of pixels by The output format of the chart. Defaults to "png" #### Version: string -Chart.js version (not required) +Chart.js version. See [documentation](https://quickchart.io/documentation/#parameters) for supported versions. #### Key: string API key (not required) From de08e5e4ee8becb1508a4e8b08a894c776a53f2d Mon Sep 17 00:00:00 2001 From: Mira <56395159+TheXorog@users.noreply.github.com> Date: Thu, 21 Sep 2023 16:52:24 +0200 Subject: [PATCH 10/11] feat: Expose API Response on Api Error --- QuickChart/QuickChart.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/QuickChart/QuickChart.cs b/QuickChart/QuickChart.cs index 93ba667..01d16e6 100644 --- a/QuickChart/QuickChart.cs +++ b/QuickChart/QuickChart.cs @@ -133,7 +133,7 @@ namespace QuickChart if (!response.IsSuccessStatusCode) { - throw new Exception("Unsuccessful response from API"); + throw new ApiException("Unsuccessful response from API", response); } string responseText = response.Content.ReadAsStringAsync().Result; @@ -172,7 +172,7 @@ namespace QuickChart if (!response.IsSuccessStatusCode) { - throw new Exception("Unsuccessful response from API"); + throw new ApiException("Unsuccessful response from API", response); } return response.Content.ReadAsByteArrayAsync().Result; @@ -183,4 +183,12 @@ namespace QuickChart File.WriteAllBytes(filePath, this.ToByteArray()); } } + + public class ApiException : Exception + { + public ApiException(string message, HttpResponseMessage response) : base(message) + => this.Response = response; + + public HttpResponseMessage Response { get; private set; } + } } From 0b60f2e32db9d79dcc45311ee77b38b7a32ef776 Mon Sep 17 00:00:00 2001 From: Mira <56395159+TheXorog@users.noreply.github.com> Date: Mon, 27 Jan 2025 00:02:49 +0100 Subject: [PATCH 11/11] chore: Update to net9 --- QuickChart/QuickChart.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QuickChart/QuickChart.csproj b/QuickChart/QuickChart.csproj index 6d88026..2e5933a 100644 --- a/QuickChart/QuickChart.csproj +++ b/QuickChart/QuickChart.csproj @@ -2,7 +2,7 @@ Library - netcoreapp3.1;netstandard2.0;net472 + net9.0 true Ian Webster Ian Webster