Skip to content

Commit 916b125

Browse files
committed
Update basic C# examples on doc index page
1 parent da3ffc4 commit 916b125

File tree

2 files changed

+90
-40
lines changed

2 files changed

+90
-40
lines changed

docs/index.fsx

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,28 @@ One of the main design points of Plotly.NET it is to provide support for multipl
219219
### Fluent interface style in C#:
220220
221221
```
222-
static void Main(string[] args)
222+
using System;
223+
using Plotly.NET;
224+
using Microsoft.FSharp.Core; // use this for less verbose and more helpful intellisense
225+
226+
namespace Plotly.NET.Tests.CSharp
223227
{
224-
double[] x = new double[] { 1, 2 };
225-
double[] y = new double[] { 5, 10 };
226-
GenericChart.GenericChart chart = Chart.Point(x: x, y: y);
227-
chart
228-
.WithTraceName("Hello from C#", true)
229-
.withXAxisStyle(title: "xAxis", Showgrid: false, Showline: true)
230-
.withYAxisStyle(title: "yAxis", Showgrid: false, Showline: true)
231-
.Show();
228+
class Program
229+
{
230+
static void Main(string[] args)
231+
{
232+
double[] x = new double[] { 1, 2 };
233+
double[] y = new double[] { 5, 10 };
234+
GenericChart.GenericChart chart = Chart2D.Chart.Point<double, double, string>(x: x, y: y);
235+
chart
236+
.WithTraceName("Hello from C#", true)
237+
.WithXAxisStyle(title: Title.init("xAxis"), ShowGrid: false, ShowLine: true)
238+
.WithYAxisStyle(title: Title.init("yAxis"), ShowGrid: false, ShowLine: true)
239+
.Show();
240+
}
241+
}
232242
}
243+
233244
```
234245
235246
### Declarative style in F# using the underlying `DynamicObj`:
@@ -273,36 +284,47 @@ GenericChart.ofTraceObject(trace)
273284
### Declarative style in C# using the underlying `DynamicObj`:
274285
275286
```
276-
static void Main(string[] args)
287+
using System;
288+
using Plotly.NET;
289+
using Microsoft.FSharp.Core; // use this for less verbose and more helpful intellisense
290+
using Plotly.NET.LayoutObjects;
291+
292+
namespace Plotly.NET.Tests.CSharp
277293
{
278-
double[] x = new double[] { 1, 2 };
279-
double[] y = new double[] { 5, 10 };
280-
281-
Axis.LinearAxis xAxis = new Axis.LinearAxis();
282-
xAxis.SetValue("title", "xAxis");
283-
xAxis.SetValue("showgrid", false);
284-
xAxis.SetValue("showline", true);
285-
286-
Axis.LinearAxis yAxis = new Axis.LinearAxis();
287-
yAxis.SetValue("title", "yAxis");
288-
yAxis.SetValue("showgrid", false);
289-
yAxis.SetValue("showline", true);
290-
291-
Layout layout = new Layout();
292-
layout.SetValue("xaxis", xAxis);
293-
layout.SetValue("yaxis", yAxis);
294-
layout.SetValue("showlegend", true);
295-
296-
Trace trace = new Trace("scatter");
297-
trace.SetValue("x", x);
298-
trace.SetValue("y", y);
299-
trace.SetValue("mode", "markers");
300-
trace.SetValue("name", "Hello from C#");
301-
302-
GenericChart
303-
.ofTraceObject(trace)
304-
.WithLayout(layout)
305-
.Show();
294+
class Program
295+
{
296+
static void Main(string[] args)
297+
{
298+
double[] x = new double[] { 1, 2 };
299+
double[] y = new double[] { 5, 10 };
300+
301+
LinearAxis xAxis = new LinearAxis();
302+
xAxis.SetValue("title", "xAxis");
303+
xAxis.SetValue("showgrid", false);
304+
xAxis.SetValue("showline", true);
305+
306+
LinearAxis yAxis = new LinearAxis();
307+
yAxis.SetValue("title", "yAxis");
308+
yAxis.SetValue("showgrid", false);
309+
yAxis.SetValue("showline", true);
310+
311+
Layout layout = new Layout();
312+
layout.SetValue("xaxis", xAxis);
313+
layout.SetValue("yaxis", yAxis);
314+
layout.SetValue("showlegend", true);
315+
316+
Trace trace = new Trace("scatter");
317+
trace.SetValue("x", x);
318+
trace.SetValue("y", y);
319+
trace.SetValue("mode", "markers");
320+
trace.SetValue("name", "Hello from C#");
321+
322+
GenericChart
323+
.ofTraceObject(trace)
324+
.WithLayout(layout)
325+
.Show();
326+
}
327+
}
306328
}
307329
```
308330
Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,42 @@
11
using System;
22
using Plotly.NET;
3+
using Microsoft.FSharp.Core; // use this for less verbose and more helpful intellisense
4+
using Plotly.NET.LayoutObjects;
35

46
namespace Plotly.NET.Tests.CSharp
57
{
68
class Program
79
{
810
static void Main(string[] args)
911
{
10-
Console.WriteLine(StyleParam.TextPosition.MiddleRight.ToString());
11-
Console.WriteLine(StyleParam.TextPosition.MiddleRight.Convert());
12+
double[] x = new double[] { 1, 2 };
13+
double[] y = new double[] { 5, 10 };
14+
15+
LinearAxis xAxis = new LinearAxis();
16+
xAxis.SetValue("title", "xAxis");
17+
xAxis.SetValue("showgrid", false);
18+
xAxis.SetValue("showline", true);
19+
20+
LinearAxis yAxis = new LinearAxis();
21+
yAxis.SetValue("title", "yAxis");
22+
yAxis.SetValue("showgrid", false);
23+
yAxis.SetValue("showline", true);
24+
25+
Layout layout = new Layout();
26+
layout.SetValue("xaxis", xAxis);
27+
layout.SetValue("yaxis", yAxis);
28+
layout.SetValue("showlegend", true);
29+
30+
Trace trace = new Trace("scatter");
31+
trace.SetValue("x", x);
32+
trace.SetValue("y", y);
33+
trace.SetValue("mode", "markers");
34+
trace.SetValue("name", "Hello from C#");
35+
36+
GenericChart
37+
.ofTraceObject(trace)
38+
.WithLayout(layout)
39+
.Show();
1240
}
1341
}
1442
}

0 commit comments

Comments
 (0)