diff --git a/QuickChart.sln b/QuickChart.sln
index cb42e78..70c2fcc 100644
--- a/QuickChart.sln
+++ b/QuickChart.sln
@@ -6,12 +6,11 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickChart", "QuickChart\QuickChart.csproj", "{60C2308A-500A-4DA1-AF8E-671C88696BFA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C076DB54-F991-4386-969E-110648801D22}"
- ProjectSection(SolutionItems) = preProject
- EmptyClass.cs = EmptyClass.cs
- EndProjectSection
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}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -26,6 +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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/QuickChart/QuickChart.cs b/QuickChart/QuickChart.cs
index c84f52d..4bf8a06 100644
--- a/QuickChart/QuickChart.cs
+++ b/QuickChart/QuickChart.cs
@@ -56,6 +56,10 @@ namespace QuickChart
queryString.Add("devicePixelRatio", DevicePixelRatio.ToString());
queryString.Add("bkg", BackgroundColor);
queryString.Add("c", Config);
+ if (!string.IsNullOrEmpty(Key))
+ {
+ queryString.Add("key", Key);
+ }
return $"{Protocol}://{Host}:{Port}/chart?{queryString}";
}
@@ -67,6 +71,9 @@ namespace QuickChart
throw new NullReferenceException("You must set Config on the QuickChart object before generating a URL");
}
+ JsonSerializerOptions options = new JsonSerializerOptions();
+ options.IgnoreNullValues = true;
+
String json = JsonSerializer.Serialize(new
{
width = Width,
@@ -74,9 +81,8 @@ namespace QuickChart
backgroundColor = BackgroundColor,
devicePixelRatio = DevicePixelRatio,
chart = Config,
- });
-
- // TODO(ian): key
+ key = Key,
+ }, options);
string url = $"{Protocol}://{Host}:{Port}/chart/create";
@@ -102,6 +108,9 @@ namespace QuickChart
throw new NullReferenceException("You must set Config on the QuickChart object before generating a URL");
}
+ JsonSerializerOptions options = new JsonSerializerOptions();
+ options.IgnoreNullValues = true;
+
String json = JsonSerializer.Serialize(new
{
width = Width,
@@ -109,9 +118,8 @@ namespace QuickChart
backgroundColor = BackgroundColor,
devicePixelRatio = DevicePixelRatio,
chart = Config,
- });
-
- // TODO(ian): key
+ key = Key,
+ }, options);
string url = $"{Protocol}://{Host}:{Port}/chart";
diff --git a/QuickChart/QuickChart.csproj b/QuickChart/QuickChart.csproj
index aeac817..1c6a739 100644
--- a/QuickChart/QuickChart.csproj
+++ b/QuickChart/QuickChart.csproj
@@ -3,6 +3,18 @@
Library
netcoreapp3.1
+ true
+ Ian Webster
+ Ian Webster 2020
+ https://github.com/typpo/quickchart-csharp/blob/main/LICENSE
+ QuickChart
+ https://github.com/typpo/quickchart-csharp
+ Client library for the QuickChart Chart API, used to generate chart images.
+ chart image, chart api, chart, charts
+ QuickChart
+ Client library for the QuickChart Chart API, used to generate chart images.
+ 1.0.0
+ QuickChart
diff --git a/QuickChartExamples/Simple.cs b/QuickChartExamples/Simple.cs
index c98f37b..5c218be 100644
--- a/QuickChartExamples/Simple.cs
+++ b/QuickChartExamples/Simple.cs
@@ -7,7 +7,7 @@ namespace QuickChartExamples
{
static void Main(string[] args) {
Console.WriteLine("Writing simple URL...");
- QuickChart qc = new QuickChart();
+ Chart qc = new Chart();
qc.Width = 500;
qc.Height = 300;
diff --git a/QuickChartTest/QuickChartTest.cs b/QuickChartTest/QuickChartTest.cs
new file mode 100644
index 0000000..9ed2b1b
--- /dev/null
+++ b/QuickChartTest/QuickChartTest.cs
@@ -0,0 +1,63 @@
+using System;
+using Xunit;
+
+using QuickChart;
+
+namespace QuickChartTest
+{
+ public class QuickChartTest
+ {
+ [Fact]
+ public void TestBasic()
+ {
+ 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]
+ }]
+ }
+ }"
+ };
+
+ string url = qc.GetUrl();
+ Assert.Contains("https://quickchart.io:443/chart", url);
+ Assert.Contains("w=500", url);
+ Assert.Contains("h=300", url);
+ Assert.DoesNotContain("key=", url);
+ }
+
+ [Fact]
+ public void TestWithKey()
+ {
+ 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]
+ }]
+ }
+ }"
+ };
+
+ string url = qc.GetUrl();
+ Assert.Contains("https://quickchart.io:443/chart", url);
+ Assert.Contains("w=500", url);
+ Assert.Contains("h=300", url);
+ Assert.Contains("key=abc123", url);
+ }
+ }
+}
diff --git a/QuickChartTest/QuickChartTest.csproj b/QuickChartTest/QuickChartTest.csproj
new file mode 100644
index 0000000..e356ae8
--- /dev/null
+++ b/QuickChartTest/QuickChartTest.csproj
@@ -0,0 +1,21 @@
+
+
+
+ netcoreapp3.1
+
+ false
+
+
+
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+all
+
+
+
+
+
+
+
+