Skip to content

Commit e036d56

Browse files
author
Mischa Spelt
committed
Add LineChartDataset Fill options
1 parent 248b81e commit e036d56

File tree

1 file changed

+79
-2
lines changed

1 file changed

+79
-2
lines changed

blazorbootstrap/Models/Charts/ChartDataset/LineChart/LineChartDataset.cs

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
namespace BlazorBootstrap;
1+
using System;
2+
using System.ComponentModel.Design;
3+
using System.Data;
4+
5+
namespace BlazorBootstrap;
26

37
/// <summary>
48
/// The line chart allows a number of properties to be specified for each dataset.
@@ -95,7 +99,80 @@ public class LineChartDataset : ChartDataset<double?>
9599
/// <remarks>
96100
/// Default value is <see langword="false"/>.
97101
/// </remarks>
98-
public bool Fill { get; set; }
102+
public object Fill { get; set; } = false;
103+
104+
public LineChartDataset FillToDataset( int index, bool relativeIndex = false )
105+
{
106+
if( relativeIndex && ( index == 0 ) )
107+
{
108+
throw new ArgumentException( "The relative index must be non-zero." );
109+
}
110+
111+
Fill = relativeIndex ? index.ToString( "+0;-0" ) : index + 1;
112+
return this;
113+
}
114+
115+
public LineChartDataset FillToDataset( ChartData chartData, IChartDataset dataset, bool relativeIndex = false )
116+
{
117+
int index = chartData?.Datasets?.IndexOf( dataset ) ?? -1;
118+
if( index < 0 )
119+
{
120+
throw new ArgumentException( "The dataset is not in the chart data." );
121+
}
122+
123+
if( relativeIndex )
124+
{
125+
126+
int myIndex = relativeIndex ? chartData.Datasets.IndexOf( this ) : 0;
127+
if( myIndex < 0 )
128+
{
129+
throw new ArgumentException( "The dataset is not in the chart data." );
130+
}
131+
132+
if( myIndex == index )
133+
{
134+
throw new ArgumentException( "The dataset is the same as this dataset." );
135+
}
136+
137+
Fill = ( index - myIndex ).ToString( "+0;-0" );
138+
}
139+
else
140+
{
141+
Fill = index + 1;
142+
}
143+
144+
return this;
145+
}
146+
147+
public LineChartDataset FillToStart()
148+
{
149+
Fill = "start";
150+
return this;
151+
}
152+
153+
public LineChartDataset FillToEnd()
154+
{
155+
Fill = "end";
156+
return this;
157+
}
158+
159+
public LineChartDataset FillToOrigin()
160+
{
161+
Fill = "origin";
162+
return this;
163+
}
164+
165+
public LineChartDataset FillToStackedValueBelow()
166+
{
167+
Fill = "stack";
168+
return this;
169+
}
170+
171+
public LineChartDataset FillToValue( double value )
172+
{
173+
Fill = new { value };
174+
return this;
175+
}
99176

100177
/// <summary>
101178
/// The line fill color when hovered.

0 commit comments

Comments
 (0)