Add test for Format and update readme

This commit is contained in:
Ian Webster 2021-09-21 08:20:41 -07:00
parent 67bed9519e
commit c7d475576c
2 changed files with 45 additions and 15 deletions

View file

@ -10,20 +10,20 @@ namespace QuickChartTest
[Fact] [Fact]
public void TestBasic() public void TestBasic()
{ {
Chart qc = new Chart Chart qc = new Chart
{ {
Width = 500, Width = 500,
Height = 300, Height = 300,
Config = @"{ Config = @"{
type: 'bar', type: 'bar',
data: { data: {
labels: ['Q1', 'Q2', 'Q3', 'Q4'], labels: ['Q1', 'Q2', 'Q3', 'Q4'],
datasets: [{ datasets: [{
label: 'Users', label: 'Users',
data: [50, 60, 70, 180] data: [50, 60, 70, 180]
}] }]
} }
}" }"
}; };
string url = qc.GetUrl(); string url = qc.GetUrl();
@ -36,21 +36,21 @@ namespace QuickChartTest
[Fact] [Fact]
public void TestWithKey() public void TestWithKey()
{ {
Chart qc = new Chart Chart qc = new Chart
{ {
Key = "abc123", Key = "abc123",
Width = 500, Width = 500,
Height = 300, Height = 300,
Config = @"{ Config = @"{
type: 'bar', type: 'bar',
data: { data: {
labels: ['Q1', 'Q2', 'Q3', 'Q4'], labels: ['Q1', 'Q2', 'Q3', 'Q4'],
datasets: [{ datasets: [{
label: 'Users', label: 'Users',
data: [50, 60, 70, 180] data: [50, 60, 70, 180]
}] }]
} }
}" }"
}; };
string url = qc.GetUrl(); string url = qc.GetUrl();
@ -59,5 +59,32 @@ namespace QuickChartTest
Assert.Contains("h=300", url); Assert.Contains("h=300", url);
Assert.Contains("key=abc123", 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);
}
} }
} }

View file

@ -77,6 +77,9 @@ The background color of the chart. Any valid HTML color works. Defaults to #ffff
#### DevicePixelRatio: double #### 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. 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 #### Key: string
API key (not required) API key (not required)