Skip to content

Commit 007d4e9

Browse files
committed
Finished implementation of the data module
1 parent 6b9bf4b commit 007d4e9

File tree

5 files changed

+194
-21
lines changed

5 files changed

+194
-21
lines changed

DotNet.Highcharts/DotNet.Highcharts.Samples/Controllers/DemoController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using DotNet.Highcharts.Helpers;
77
using DotNet.Highcharts.Options;
88
using DotNet.Highcharts.Options.Accessibility;
9+
using DotNet.Highcharts.Options.DataOptions;
910
using DotNet.Highcharts.Options.Exporting;
1011
using DotNet.Highcharts.Options.Legend;
1112
using DotNet.Highcharts.Options.PlotOptions;
@@ -93,7 +94,7 @@ public ActionResult ColumnData()
9394
{
9495
Type = ChartTypes.Column
9596
})
96-
.SetData(new HighchartsData
97+
.SetDataOptions(new DataOptions
9798
{
9899
Rows = new object[,] {
99100
{null, "Ola", "Kari"}, // series names

DotNet.Highcharts/DotNet.Highcharts/DotNet.Highcharts.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
<Compile Include="Options\Colors.cs" />
126126
<Compile Include="Options\ContainerOptions.cs" />
127127
<Compile Include="Options\Credits.cs" />
128-
<Compile Include="Options\HigchartsData.cs" />
128+
<Compile Include="Options\DataOptions\DataOptions.cs" />
129129
<Compile Include="Options\DataGrouping.cs" />
130130
<Compile Include="Options\Exporting\Exporting.cs" />
131131
<Compile Include="Options\Exporting\ExportingButtons.cs" />

DotNet.Highcharts/DotNet.Highcharts/Highcharts.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Web;
1414
using DotNet.Highcharts.Options.Boost;
1515
using DotNet.Highcharts.Options.ColorAxis;
16+
using DotNet.Highcharts.Options.DataOptions;
1617

1718
namespace DotNet.Highcharts
1819
{
@@ -36,7 +37,7 @@ public class Highcharts : IHtmlString
3637
private Boost _boost;
3738
private Chart _chart;
3839
private ColorAxis _colorAxis;
39-
private HighchartsData _data;
40+
private DataOptions _dataOptions;
4041
private Credits _credits;
4142
private Labels _labels;
4243
private Legend _legend;
@@ -144,9 +145,9 @@ public Highcharts ColorAxis(ColorAxis colorAxis)
144145
/// </summary>
145146
/// <param name="data"></param>
146147
/// <returns></returns>
147-
public Highcharts SetData(HighchartsData data)
148+
public Highcharts SetDataOptions(DataOptions data)
148149
{
149-
_data = data;
150+
_dataOptions = data;
150151
return this;
151152
}
152153

@@ -433,10 +434,10 @@ public virtual string GetOptions()
433434
options.Append("colorAxis: {0}".FormatWith(JsonSerializer.Serialize(_colorAxis)), 2);
434435
}
435436

436-
if (_data != null)
437+
if (_dataOptions != null)
437438
{
438439
options.AppendLine(", ");
439-
options.AppendLine("data: {0}".FormatWith(JsonSerializer.Serialize(_data)), 2);
440+
options.AppendLine("data: {0}".FormatWith(JsonSerializer.Serialize(_dataOptions)), 2);
440441
}
441442

442443
if (_labels != null)
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
using DotNet.Highcharts.Attributes;
2+
using DotNet.Highcharts.Helpers;
3+
4+
namespace DotNet.Highcharts.Options.DataOptions
5+
{
6+
/// <summary>
7+
/// The Data module provides a simplified interface for adding data to a chart from sources like CVS, HTML tables or grid views. See also the tutorial article on the Data module.
8+
/// It requires the modules/data.js file to be loaded.
9+
/// Please note that the default way of adding data in Highcharts, without the need of a module, is through the series.data option.
10+
/// </summary>
11+
public class DataOptions
12+
{
13+
/// <summary>
14+
/// A callback function to modify the CSV before parsing it. Return the modified string.
15+
/// Default: undefined
16+
/// </summary>
17+
[JsonFormatter("{0}")]
18+
public string BeforeParse { get; set; }
19+
20+
/// <summary>
21+
/// A two-dimensional array representing the input data on tabular form. This input can be used when the data is already parsed, for example from a grid view component. Each cell can be a string or number. If not switchRowsAndColumns is set, the columns are interpreted as series.
22+
/// Default: undefined
23+
/// </summary>
24+
public object[,] Columns { get; set; }
25+
26+
/// <summary>
27+
/// A URL to a remote JSON dataset, structured as a column array. Will be fetched when the chart is created using Ajax.
28+
/// Default: undefined
29+
/// </summary>
30+
public string ColumnsURL { get; set; }
31+
32+
/// <summary>
33+
/// The callback that is evaluated when the data is finished loading, optionally from an external source, and parsed. The first argument passed is a finished chart options object, containing the series. These options can be extended with additional options and passed directly to the chart constructor.
34+
/// Default: undefined
35+
/// </summary>
36+
[JsonFormatter("{0)")]
37+
public string Complete { get; set; }
38+
39+
/// <summary>
40+
/// A comma delimited string to be parsed. Related options are startRow, endRow, startColumn and endColumn to delimit what part of the table is used. The lineDelimiter and itemDelimiter options define the CSV delimiter formats.
41+
/// The built-in CSV parser doesn't support all flavours of CSV, so in some cases it may be necessary to use an external CSV parser. See this example of parsing CSV through the MIT licensed Papa Parse library.
42+
/// Default: undefined
43+
/// </summary>
44+
public string Csv { get; set; }
45+
46+
/// <summary>
47+
/// A URL to a remote CSV dataset. Will be fetched when the chart is created using Ajax.
48+
/// Default: undefined
49+
/// </summary>
50+
public string CsvURL { get; set; }
51+
52+
/// <summary>
53+
/// Sets the refresh rate for data polling when importing remote dataset by setting data.csvURL, data.rowsURL, data.columnsURL, or data.googleSpreadsheetKey.
54+
/// Note that polling must be enabled by setting data.enablePolling to true.
55+
/// The value is the number of seconds between pollings. It cannot be set to less than 1 second.
56+
/// Default: 1
57+
/// </summary>
58+
public Number? DataRefreshRate { get; set; }
59+
60+
/// <summary>
61+
/// Which of the predefined date formats in Date.prototype.dateFormats to use to parse date values. Defaults to a best guess based on what format gives valid and ordered dates.
62+
/// Valid options include:
63+
/// YYYY/mm/dd
64+
/// dd/mm/YYYY
65+
/// mm/dd/YYYY
66+
/// dd/mm/YY
67+
/// mm/dd/YY
68+
/// Default: undefined
69+
/// </summary>
70+
public string DateFormat { get; set; }
71+
72+
/// <summary>
73+
/// The decimal point used for parsing numbers in the CSV
74+
/// If both this and data.delimiter is set to false, the parser will attempt to deduce the decimal point automatically.
75+
/// Default: . .
76+
/// </summary>
77+
public string DecimalPoint { get; set; }
78+
79+
/// <summary>
80+
/// Enables automatic refetching of remote datasets every n seconds (defined by setting data.dataRefreshRate).
81+
/// Only works when either data.csvURL, data.rowsURL, data.columnsURL, or data.googleSpreadsheetKey.
82+
/// Default: false
83+
/// </summary>
84+
public bool? EnablePolling { get; set; }
85+
86+
/// <summary>
87+
/// In tabular input data, the last column (indexed by 0) to use. Defaults to the last column containing data.
88+
/// Default: undefined
89+
/// </summary>
90+
public Number? EndColumn { get; set; }
91+
92+
/// <summary>
93+
/// In tabular input data, the last row (indexed by 0) to use. Defaults to the last row containing data.
94+
/// Default: undefined
95+
/// </summary>
96+
public Number? EndRow { get; set; }
97+
98+
/// <summary>
99+
/// Whether to use the first row in the data set as series names.
100+
/// Default: true
101+
/// </summary>
102+
public bool? FirstRowAsNames { get; set; }
103+
104+
/// <summary>
105+
/// The key for a Google Spreadsheet to load. See general information on GS.
106+
/// Default: undefined
107+
/// </summary>
108+
public string GoogleSpreadsheetKey { get; set; }
109+
110+
/// <summary>
111+
/// The Google Spreadsheet worksheet to use in combination with googleSpreadsheetKey. The available id's from your sheet can be read from https://spreadsheets.google.com/feeds/worksheets/{key}/public/basic.
112+
/// Default: undefined
113+
/// </summary>
114+
public string GoogleSpreadsheetWorksheet { get; set; }
115+
116+
/// <summary>
117+
/// Item or cell delimiter for parsing CSV. Defaults to the tab character \t if a tab character is found in the CSV string, if not it defaults to ,.
118+
/// If this is set to false or undefined, the parser will attempt to deduce the delimiter automatically.
119+
/// Default: undefined
120+
/// </summary>
121+
public string ItemDelimiter { get; set; }
122+
123+
/// <summary>
124+
/// Line delimiter for parsing CSV.
125+
/// Default: \n
126+
/// </summary>
127+
public string LineDelimiter { get; set; }
128+
129+
/// <summary>
130+
/// A callback function to access the parsed columns, the two-dimentional input data array directly, before they are interpreted into series data and categories. Return false to stop completion, or call this.complete() to continue async.
131+
/// Default: undefined
132+
/// </summary>
133+
[JsonFormatter("{0)")]
134+
public string Parsed { get; set; }
135+
136+
/// <summary>
137+
/// A callback function to parse string representations of dates into JavaScript timestamps. Should return an integer timestamp on success.
138+
/// Default: undefined
139+
/// </summary>
140+
[JsonFormatter("{0)")]
141+
public string ParseDate { get; set; }
142+
143+
/// <summary>
144+
/// The same as the columns input option, but defining rows intead of columns.
145+
/// Default: undefined
146+
/// </summary>
147+
public object[,] Rows { get; set; }
148+
149+
/// <summary>
150+
/// A URL to a remote JSON dataset, structured as a row array. Will be fetched when the chart is created using Ajax.
151+
/// Default: undefined
152+
/// </summary>
153+
public string RowsURL { get; set; }
154+
155+
/// <summary>
156+
/// An array containing object with Point property names along with what column id the property should be taken from.
157+
/// Default: undefined
158+
/// </summary>
159+
public object[] SeriesMapping { get; set; }
160+
161+
/// <summary>
162+
/// In tabular input data, the first column (indexed by 0) to use.
163+
/// Default: 0
164+
/// </summary>
165+
public Number? StartColumn { get; set; }
166+
167+
/// <summary>
168+
/// In tabular input data, the first row (indexed by 0) to use.
169+
/// Default: 0
170+
/// </summary>
171+
public Number? StartRow { get; set; }
172+
173+
/// <summary>
174+
/// Switch rows and columns of the input data, so that this.columns effectively becomes the rows of the data set, and the rows are interpreted as series.
175+
/// Default: false
176+
/// </summary>
177+
public bool? SwitchRowsAndColumns { get; set; }
178+
179+
/// <summary>
180+
/// An HTML table or the id of such to be parsed as input data. Related options are startRow, endRow, startColumn and endColumn to delimit what part of the table is used.
181+
/// Default: undefined
182+
/// </summary>
183+
public string Table { get; set; }
184+
}
185+
}

DotNet.Highcharts/DotNet.Highcharts/Options/HigchartsData.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)