Skip to content

Commit

Permalink
Merge pull request #107 from apexcharts/csv-dateformatter
Browse files Browse the repository at this point in the history
Fixed Export CSV  DateFromatter
  • Loading branch information
joadan authored Jun 7, 2022
2 parents 3377abf + 56f26ae commit 904e060
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<DemoContainer>
<ApexChart TItem="Order" Title="Orders Value"
XAxisType="XAxisType.Datetime"
Options="options">

<ApexPointSeries TItem="Order"
Items="SampleData.GetOrders()"
Name="Net Value"
SeriesType="SeriesType.Line"
XValue="@(e => e.OrderDate.FirstDayOfMonth())"
YAggregate="@(e => e.Sum(e => e.NetValue))"
OrderBy="e=>e.X" />

<ApexPointSeries TItem="Order"
Items="SampleData.GetOrders()"
Name="Gross Value"
SeriesType="SeriesType.Line"
XValue="@(e => e.OrderDate.FirstDayOfMonth())"
YAggregate="@(e => e.Sum(e => e.GrossValue))"
OrderBy="e=>e.X" />
</ApexChart>
</DemoContainer>

@code {
private ApexChartOptions<Order> options = new ApexCharts.ApexChartOptions<Order>();
protected override void OnInitialized()
{
options.Chart = new Chart
{
Toolbar = new Toolbar
{
Export = new ExportOptions
{
Csv = new ExportCSV
{
Filename = "Test Date formatter",
HeaderCategory = "sep=|" + Environment.NewLine + "Date",
ColumnDelimiter = "|",
DateFormatter = "function (value) { return new Date(value).toLocaleString(); }"

}
}
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@
</Snippet>
</CodeSnippet>

<CodeSnippet Title="CSV formatter" ClassName=@typeof(CsvFormatter).ToString()>
<Snippet>
<CsvFormatter />
</Snippet>
</CodeSnippet>



</DocExamples>
4 changes: 2 additions & 2 deletions src/Blazor-ApexCharts/wwwroot/js/blazor-apex-charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

updateOptions(id, options, redrawPaths, animate, updateSyncedCharts) {
var data = JSON.parse(options, (key, value) =>
(key === 'formatter' || key === 'custom') && value.length !== 0 ? eval("(" + value + ")") : value
(key === 'formatter' || key === 'dateFormatter' || key === 'custom') && value.length !== 0 ? eval("(" + value + ")") : value
);
var chart = this.findChart(id);
if (chart !== undefined) {
Expand Down Expand Up @@ -189,7 +189,7 @@
}

var options = JSON.parse(options, (key, value) =>
(key === 'formatter' || key === 'custom') && value.length !== 0 ? eval("(" + value + ")") : value
(key === 'formatter' || key === 'dateFormatter' || key === 'custom') && value.length !== 0 ? eval("(" + value + ")") : value
);

if (options.debug == true) {
Expand Down

0 comments on commit 904e060

Please sign in to comment.