Skip to content

Commit 701b2de

Browse files
authored
Merge pull request #99 from apexcharts/fix-axis-label-color
Fix axis label color
2 parents 02d1f58 + 23aa3d8 commit 701b2de

File tree

8 files changed

+138
-35
lines changed

8 files changed

+138
-35
lines changed

docs/BlazorApexCharts.Docs.Server/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"IIS Express": {
1212
"commandName": "IISExpress",
1313
"launchBrowser": true,
14-
"launchUrl": "line-charts",
14+
"launchUrl": "features/axis",
1515
"environmentVariables": {
1616
"ASPNETCORE_ENVIRONMENT": "Development"
1717
}

docs/BlazorApexCharts.Docs/Components/ChartTypes/LineCharts/DataLabels.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
},
6464

6565
Colors = new List<string> { "#77B6EA", "#545454" },
66-
Markers = new Markers { Shape = ShapeEnum.Circle, Size = 5 },
66+
Markers = new Markers { Shape = ShapeEnum.Circle, Size = 5, FillOpacity = new Opacity(0.8d) },
6767
Stroke = new Stroke { Curve = Curve.Smooth },
6868
Legend = new Legend
6969
{

docs/BlazorApexCharts.Docs/Components/Features/Axis/AxisSamples.razor

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22

33
<DocExamples Title="Axis">
44

5-
<CodeSnippet Title="Multiple Y Axis" ClassName=@typeof(MultipleYAxis).ToString()>
5+
6+
7+
8+
<CodeSnippet Title="Multiple Y Axis" ClassName=@typeof(MultipleYAxis).ToString()>
69
<Snippet>
710
<MultipleYAxis />
811
</Snippet>
912
</CodeSnippet>
1013

11-
<CodeSnippet Title="XAxis Groups" ClassName=@typeof(XAxisGroupsChart).ToString()>
14+
<CodeSnippet Title="XAxis Groups" ClassName=@typeof(XAxisGroupsChart).ToString()>
1215
<Snippet>
1316
<XAxisGroupsChart />
1417
</Snippet>
1518
</CodeSnippet>
1619

17-
20+
<CodeSnippet Title="Axis Style" ClassName=@typeof(AxisStyle).ToString()>
21+
<Snippet>
22+
<AxisStyle />
23+
</Snippet>
24+
</CodeSnippet>
1825

1926
</DocExamples>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<DemoContainer>
2+
<ApexChart TItem="Order"
3+
Title="Order Net Value"
4+
Options=options
5+
Debug>
6+
7+
<ApexPointSeries TItem="Order"
8+
Items="Orders"
9+
Name="Value"
10+
XValue="@(e => e.Country)"
11+
YAggregate="@(e => e.Sum(e => e.GrossValue))"
12+
SeriesType="SeriesType.Bar" />
13+
14+
</ApexChart>
15+
</DemoContainer>
16+
17+
@code {
18+
private List<Order> Orders { get; set; } = SampleData.GetOrders();
19+
private ApexChartOptions<Order> options { get; set; } = new();
20+
21+
protected override void OnInitialized()
22+
{
23+
options.Yaxis = new List<YAxis>();
24+
25+
options.Yaxis.Add(new YAxis
26+
{
27+
Title = new AxisTitle { Text = "Value" },
28+
DecimalsInFloat = 0,
29+
TickAmount=6,
30+
31+
Labels = new YAxisLabels
32+
{
33+
Style = new AxisLabelStyle { FontSize = "20px", Colors = new Color("red") }
34+
}
35+
});
36+
37+
38+
options.Xaxis = new XAxis
39+
{
40+
Labels = new XAxisLabels
41+
{
42+
Style = new AxisLabelStyle
43+
{
44+
FontSize = "18px",
45+
FontWeight = "bolder",
46+
Colors = new Color(new List<string> { "red", "blue", "Orange", "Green" })
47+
}
48+
}
49+
};
50+
51+
}
52+
53+
}

src/Blazor-ApexCharts/ChartSerializer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ private JsonSerializerOptions GenerateOptions<TItem>() where TItem : class
2020
serializerOptions.Converters.Add(new DataPointConverter<TItem>());
2121
serializerOptions.Converters.Add(new SeriesConverter<TItem>());
2222
serializerOptions.Converters.Add(new CustomJsonStringEnumConverter());
23+
serializerOptions.Converters.Add(new ValueOrListConverter<string>());
24+
serializerOptions.Converters.Add(new ValueOrListConverter<double>());
2325

2426
return serializerOptions;
2527
}

src/Blazor-ApexCharts/Models/ApexChartOptions.cs

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System;
33
using System.Runtime.Serialization;
4+
using System.Linq;
45

56
namespace ApexCharts
67
{
@@ -1439,7 +1440,7 @@ public class DatetimeFormatter
14391440

14401441
public class AxisLabelStyle
14411442
{
1442-
public Color? Colors { get; set; }
1443+
public Color Colors { get; set; }
14431444
public string CssClass { get; set; }
14441445
public string FontFamily { get; set; }
14451446
public string FontSize { get; set; }
@@ -1564,42 +1565,45 @@ public enum TickAmountEnum { DataPoints };
15641565

15651566
public enum XAxisType { Category, Datetime, Numeric };
15661567

1567-
1568-
public struct Download
1568+
public class ValueOrList<T>
15691569
{
1570-
public bool? Bool;
1571-
public string String;
1570+
private readonly T _str;
1571+
private readonly List<T> _list;
1572+
public bool IsList { get; private set; }
15721573

1573-
public static implicit operator Download(bool Bool) => new Download { Bool = Bool };
1574-
public static implicit operator Download(string String) => new Download { String = String };
1575-
}
1574+
public T GetValue => _str;
1575+
public IEnumerable<T> GetList => _list;
15761576

1577-
public struct Color
1578-
{
1579-
public string String;
1580-
public List<string> StringArray;
1577+
public ValueOrList(T value)
1578+
{
1579+
_str = value;
1580+
}
15811581

1582-
public static implicit operator Color(string String) => new Color { String = String };
1583-
public static implicit operator Color(List<string> StringArray) => new Color { StringArray = StringArray };
1582+
public ValueOrList(IEnumerable<T> list)
1583+
{
1584+
IsList = true;
1585+
_list = list.ToList();
1586+
}
15841587
}
15851588

1586-
public struct Opacity
1587-
{
1588-
public double? Double;
1589-
public List<double> DoubleArray;
15901589

1591-
public static implicit operator Opacity(double Double) => new Opacity { Double = Double };
1592-
public static implicit operator Opacity(List<double> DoubleArray) => new Opacity { DoubleArray = DoubleArray };
1590+
public class Color : ValueOrList<string>
1591+
{
1592+
public Color(string value) : base(value)
1593+
{
1594+
}
1595+
public Color(IEnumerable<string> list) : base(list)
1596+
{
1597+
}
15931598
}
15941599

1595-
public struct ShapeUnion
1600+
public class Opacity : ValueOrList<double>
15961601
{
1597-
public ShapeEnum? Enum;
1598-
public List<string> StringArray;
1599-
1600-
public static implicit operator ShapeUnion(ShapeEnum Enum) => new ShapeUnion { Enum = Enum };
1601-
public static implicit operator ShapeUnion(List<string> StringArray) => new ShapeUnion { StringArray = StringArray };
1602+
public Opacity(double value) : base(value)
1603+
{
1604+
}
1605+
public Opacity(IEnumerable<double> list) : base(list)
1606+
{
1607+
}
16021608
}
1603-
1604-
16051609
}

src/Blazor-ApexCharts/Models/Converters/SeriesConverter.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Text;
54
using System.Text.Json;
65
using System.Text.Json.Serialization;
7-
using System.Threading.Tasks;
86

97
namespace ApexCharts.Models
108
{
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text.Json;
4+
using System.Text.Json.Serialization;
5+
6+
namespace ApexCharts.Models
7+
{
8+
9+
public class ValueOrListConverter<T> : JsonConverter<ValueOrList<T>>
10+
{
11+
public override ValueOrList<T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
12+
{
13+
throw new NotImplementedException();
14+
}
15+
16+
public override bool CanConvert(Type typeToConvert) => typeof(ValueOrList<T>).IsAssignableFrom(typeToConvert);
17+
18+
public override void Write(Utf8JsonWriter writer, ValueOrList<T> value, JsonSerializerOptions options)
19+
{
20+
if (value == null)
21+
{
22+
JsonSerializer.Serialize(writer, null, options);
23+
}
24+
else
25+
{
26+
if (value.IsList)
27+
{
28+
JsonSerializer.Serialize(writer, value.GetList, typeof(IEnumerable<T>), options);
29+
}
30+
else
31+
{
32+
JsonSerializer.Serialize(writer, value.GetValue, typeof(T), options);
33+
}
34+
}
35+
}
36+
}
37+
38+
}
39+

0 commit comments

Comments
 (0)