Compare commits
1 commit
main
...
format-upd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7d475576c |
5 changed files with 20 additions and 123 deletions
|
|
@ -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", "{21C67AF9-6B21-4FA3-A203-294C36DC7F2A}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickChartTest", "QuickChartTest\QuickChartTest.csproj", "{0CEF2268-6F2B-4DEB-B152-DDA0B09ABEDA}"
|
||||
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
|
||||
{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
|
||||
{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
|
||||
|
|
|
|||
|
|
@ -19,10 +19,9 @@ 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 Version { get; set; }
|
||||
public string Config { get; set; }
|
||||
|
||||
public string Scheme { get; set; }
|
||||
|
|
@ -31,7 +30,7 @@ namespace QuickChart
|
|||
|
||||
private static readonly HttpClient Client = new HttpClient();
|
||||
|
||||
public Chart(string scheme = null, string host = null, int? port = null)
|
||||
public Chart()
|
||||
{
|
||||
Width = 500;
|
||||
Height = 300;
|
||||
|
|
@ -39,41 +38,10 @@ namespace QuickChart
|
|||
Format = "png";
|
||||
BackgroundColor = "transparent";
|
||||
|
||||
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()
|
||||
{
|
||||
|
|
@ -94,10 +62,6 @@ 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}";
|
||||
}
|
||||
|
|
@ -121,7 +85,6 @@ namespace QuickChart
|
|||
format = Format,
|
||||
chart = Config,
|
||||
key = Key,
|
||||
version = Version,
|
||||
}, options);
|
||||
|
||||
string url = $"{Scheme}://{Host}:{Port}/chart/create";
|
||||
|
|
@ -133,7 +96,7 @@ namespace QuickChart
|
|||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new ApiException("Unsuccessful response from API", response);
|
||||
throw new Exception("Unsuccessful response from API");
|
||||
}
|
||||
|
||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||
|
|
@ -160,7 +123,6 @@ namespace QuickChart
|
|||
format = Format,
|
||||
chart = Config,
|
||||
key = Key,
|
||||
version = Version,
|
||||
}, options);
|
||||
|
||||
string url = $"{Scheme}://{Host}:{Port}/chart";
|
||||
|
|
@ -172,7 +134,7 @@ namespace QuickChart
|
|||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new ApiException("Unsuccessful response from API", response);
|
||||
throw new Exception("Unsuccessful response from API");
|
||||
}
|
||||
|
||||
return response.Content.ReadAsByteArrayAsync().Result;
|
||||
|
|
@ -183,12 +145,4 @@ 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; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFrameworks>net9.0</TargetFrameworks>
|
||||
<TargetFrameworks>netcoreapp3.1;netstandard2.0;net472</TargetFrameworks>
|
||||
<PackOnBuild>true</PackOnBuild>
|
||||
<Authors>Ian Webster</Authors>
|
||||
<Copyright>Ian Webster</Copyright>
|
||||
<Copyright>Ian Webster 2020</Copyright>
|
||||
<PackageLicenseUrl>https://github.com/typpo/quickchart-csharp/blob/main/LICENSE</PackageLicenseUrl>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<Owners>QuickChart</Owners>
|
||||
<PackageProjectUrl>https://github.com/typpo/quickchart-csharp</PackageProjectUrl>
|
||||
|
|
@ -13,7 +14,7 @@
|
|||
<PackageTags>chart image, chart api, chart, charts, image charts</PackageTags>
|
||||
<Title>QuickChart</Title>
|
||||
<Description>Client library for the QuickChart Chart API, used to generate chart images.</Description>
|
||||
<PackageVersion>2.3.0</PackageVersion>
|
||||
<PackageVersion>2.0.0</PackageVersion>
|
||||
<PackageId>QuickChart</PackageId>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -86,59 +86,5 @@ namespace QuickChartTest
|
|||
Assert.Contains("h=300", url);
|
||||
Assert.Contains("f=svg", url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWithVersion()
|
||||
{
|
||||
Chart qc = new Chart
|
||||
{
|
||||
Width = 500,
|
||||
Height = 300,
|
||||
Version = "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);
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.1.0
|
||||
PM> Install-Package QuickChart -Version 2.0.0
|
||||
```
|
||||
or
|
||||
```
|
||||
dotnet add package QuickChart --version 2.1.0
|
||||
dotnet add package QuickChart --version 2.0.0
|
||||
```
|
||||
---
|
||||
## Usage
|
||||
|
|
@ -26,7 +26,6 @@ Chart qc = new Chart();
|
|||
|
||||
qc.Width = 500;
|
||||
qc.Height = 300;
|
||||
qc.Version = "2.9.4";
|
||||
qc.Config = @"{
|
||||
type: 'bar',
|
||||
data: {
|
||||
|
|
@ -81,9 +80,6 @@ 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. See [documentation](https://quickchart.io/documentation/#parameters) for supported versions.
|
||||
|
||||
#### Key: string
|
||||
API key (not required)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue