Skip to content

Commit c0aeddb

Browse files
authored
Merge pull request #80 from apexcharts/add-datapoint-custom
Make possible to pass some extra data to a datapoint
2 parents c656f16 + 2ae45c9 commit c0aeddb

File tree

10 files changed

+95
-11
lines changed

10 files changed

+95
-11
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": "candlestick-charts",
14+
"launchUrl": "features/formatters",
1515
"environmentVariables": {
1616
"ASPNETCORE_ENVIRONMENT": "Development"
1717
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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="Gross Value"
10+
SeriesType="SeriesType.Line"
11+
XValue="@(e => e.Country)"
12+
YAggregate="@(e => e.Sum(e => e.GrossValue))"
13+
OrderByDescending="e=>e.Y" ShowDataLabels
14+
DataPointMutator=SetCustomData/>
15+
16+
17+
</ApexChart>
18+
</DemoContainer>
19+
20+
@code {
21+
private List<Order> Orders { get; set; } = SampleData.GetOrders();
22+
private ApexChartOptions<Order> options;
23+
24+
protected override void OnInitialized()
25+
{
26+
options = new ApexChartOptions<Order>();
27+
28+
options.Yaxis = new List<YAxis>();
29+
options.Yaxis.Add(new YAxis
30+
{
31+
Labels = new YAxisLabels
32+
{
33+
Formatter = @"function (value) {
34+
return '$' + Number(value).toLocaleString();}"
35+
}
36+
}
37+
);
38+
39+
options.Xaxis = new XAxis
40+
{
41+
Labels = new XAxisLabels
42+
{
43+
Formatter = @"function (value) {
44+
if (value === undefined) {return '';}
45+
return value.toUpperCase();}"
46+
}
47+
};
48+
49+
options.DataLabels = new DataLabels
50+
{
51+
Formatter = @"function(value, opts) {
52+
return Number(value).toLocaleString();}"
53+
};
54+
55+
options.Tooltip = new ApexCharts.Tooltip
56+
{
57+
X = new TooltipX
58+
{
59+
Formatter = @"function(value, opts) {
60+
if (value === undefined) {return '';}
61+
let extra = opts.w.config.series[opts.seriesIndex].data[opts.dataPointIndex].extra;
62+
return opts.w.globals.categoryLabels[value-1] + ':' + value + ' [' + extra.label + ']'}"
63+
}
64+
};
65+
}
66+
67+
private void SetCustomData(DataPoint<Order> datapoint)
68+
{
69+
datapoint.Extra = new AdditionalData { Label = "Extra Data!" };
70+
}
71+
72+
public class AdditionalData
73+
{
74+
public string Label { get; set; }
75+
}
76+
}

docs/BlazorApexCharts.Docs/Components/Features/Formatters/FormatterSamples.razor

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
@page "/features/formatters"
22

33
<DocExamples Title="Formatters">
4+
45

56
<CodeSnippet Title="Use javascript" ClassName=@typeof(UseJavascript).ToString()>
67
<Snippet>
78
<UseJavascript />
89
</Snippet>
910
</CodeSnippet>
1011

11-
12+
<CodeSnippet Title="Pass Extra Data" ClassName=@typeof(ExtraData).ToString()>
13+
<Snippet>
14+
<ExtraData />
15+
</Snippet>
16+
</CodeSnippet>
17+
1218
<CodeSnippet Title="Use DotNet" ClassName=@typeof(UseDotnet).ToString()>
1319
<Description>
1420
<Alert BackgroundColor=TablerColor.Danger>

src/Blazor-ApexCharts/ApexChart.razor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.JSInterop;
55
using System;
66
using System.Collections.Generic;
7-
using System.Diagnostics;
87
using System.Linq;
98
using System.Text.Json;
109
using System.Threading.Tasks;

src/Blazor-ApexCharts/Models/DataPoints/BubblePoint.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public class BubblePoint<TItem> : IDataPoint<TItem>
1515

1616
public decimal Z { get; set; }
1717

18-
18+
public object Extra { get; set; }
19+
1920
[JsonIgnore]
2021
public IEnumerable<TItem> Items { get; set; }
2122

src/Blazor-ApexCharts/Models/DataPoints/DataPoint.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class DataPoint<TItem> : IDataPoint<TItem>
1717
[JsonIgnore]
1818
public IEnumerable<TItem> Items { get; set; }
1919

20+
public object Extra { get; set; }
2021
}
2122

2223
public class DataPointGoal

src/Blazor-ApexCharts/Models/DataPoints/IDataPoint.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public interface IDataPoint<TItem>
77
IEnumerable<TItem> Items { get; set; }
88
object X { get; set; }
99
string FillColor { get; set; }
10+
11+
object Extra { get; set; }
1012

1113
}
1214
}

src/Blazor-ApexCharts/Models/DataPoints/ListPoint.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ public class ListPoint<TItem> : IDataPoint<TItem>
1313
public object X { get; set; }
1414
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
1515
public IEnumerable<decimal?> Y { get; set; }
16-
17-
16+
17+
public object Extra { get; set; }
18+
1819
[JsonIgnore]
1920
public IEnumerable<TItem> Items { get; set; }
2021
}

src/Blazor-ApexCharts/Series/ApexBaseSeries.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
5-
using System.Linq.Expressions;
65
using System.Threading.Tasks;
76

87
namespace ApexCharts
@@ -17,7 +16,6 @@ public abstract class ApexBaseSeries<TItem> : ComponentBase where TItem : class
1716
[Parameter] public IEnumerable<TItem> Items { get; set; }
1817
[Parameter] public SeriesStroke Stroke { get; set; }
1918
[Parameter] public string Color { get; set; }
20-
2119
[Parameter] public Func<TItem, string> PointColor { get; set; }
2220
public async Task Toggle()
2321
{
@@ -46,11 +44,10 @@ public string GetPointColor(IEnumerable<TItem> items)
4644
return PointColor.Invoke(items.First());
4745
}
4846

49-
50-
public List<T> UpdateDataPoints<T>(IEnumerable<T> items, Action<T> updateMethod)
47+
public List<T> UpdateDataPoints<T>(IEnumerable<T> items, Action<T> updateMethod)
5148
{
5249
var data = items.ToList();
53-
if(updateMethod == null)
50+
if (updateMethod == null)
5451
{
5552
return data;
5653
}

src/Blazor-ApexCharts/Series/IApexSeries.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public interface IApexSeries<TItem> : IDisposable where TItem : class
1212
Func<TItem, object> XValue { get; set; }
1313
IEnumerable<TItem> Items { get; set; }
1414
string Color { get; set; }
15+
1516
bool ShowDataLabels { get; set; }
1617
SeriesStroke Stroke { get; set; }
1718
public IEnumerable<IDataPoint<TItem>> GenerateDataPoints(IEnumerable<TItem> items);

0 commit comments

Comments
 (0)