Bunifu LineChart is a chart component that renders a dataset as a single line path on the canvas. It can also be set to render area charts suitable for displaying quantitative data, often for comparing two sets of data.
Here is an example of a sales dashboard using Bunifu Line Chart.
Getting started
Getting started with Design View
This section explains to you the steps required to start creating a simple line chart in the design view.
Step 1: Drag the canvas control to the form from the toolbox
Step 2: In the property window of the canvas on the labels property, add the following values in the string collection editor window as shown below:
Step 3: From the toolbox drag and drop BunifuLineChart to the form.
Step 4: Click the ellipsis button on the Data property of BunifuLine, and add the following values to the collection window editor displayed as shown below:
Step 5: Go to the property named TargetCanvas select bunifuChartCanvas1 as the target component.
Step 6: Advance to BunifuLineChart properties and set a name on the Label property. An example would be No. of Solid State Drives repaired.
Step 7: Run the application.
Advance to BunifuLineChart properties and set a name on the Label property. An example would be No. of Solid State Drives repaired.
Alternatively, we can code and render a line chart without using the design view. Here's how to do it:
Code View
voidrenderLineChart() { Bunifu.Charts.WinForms.ChartTypes.BunifuLineChart bunifuLineChart = new Bunifu.Charts.WinForms.ChartTypes.BunifuLineChart();
/* * For this example we will use random numbers */var r =newRandom();/* * Add your data from your source - accepts double list * Below is an example from a random number */List<double> data =newList<double>();data.Add(-30);for (int i =0; i <5; i++) {data.Add(r.NextDouble()); }/* * Set your data */bunifuLineChart.Data= data;/* * Specify the target canvas */bunifuLineChart.TargetCanvas= bunifuChartCanvas1;/* * Add labels to your canvas * Label count should correspond to data count for charts like Bar charts */bunifuChartCanvas1.Labels=newstring[] { "Label1","Label2","Label3","Label4","Label5" };/* * Beautify the chart by sepcifying the colors */bunifuLineChart.BackgroundColor=Color.Purple; }
Private SubrenderLineChart() Dim bunifuLineChart As Bunifu.Charts.WinForms.ChartTypes.BunifuLineChart = New Bunifu.Charts.WinForms.ChartTypes.BunifuLineChart()
' ' For this example we will use random numbers ' Dim r = New Random() ' ' Add your data from your source - accepts double list ' Below is an example from a random number ' Dim data As List(Of Double) = New List(Of Double)() data.Add(-30) For i As Integer = 0 To 5 - 1 data.Add(r.NextDouble()) Next ' ' Set your data ' bunifuLineChart.Data = data ' ' Specify the target canvas ' bunifuLineChart.TargetCanvas = bunifuChartCanvas1 ' ' Add labels to your canvas ' Label count should correspond to data count for charts like Bar charts ' bunifuChartCanvas1.Labels = New String() {"Label1", "Label2", "Label3", "Label4", "Label5"}' ' Beautify the chart by sepcifying the colors' bunifuLineChart.BackgroundColor=Color.PurpleEnd Sub
Let us examine Bunifu Line charting properties.
Line properties
1. CubicInterpolationMode
This property gets and sets the algorithm that draws the curves of a spline line chart. The default algorithm uses a custom weighted cubic interpolation, which renders smooth curves, and the monotone algorithm preserves monotonicity (i.e. it reserves a strict order of the dataset being interpolated/plotted) suitable for presenting y=f(x) datasets.
the code below illustrates how to set the cubic interpolation at run-time.
Private Sub bunifuRadioButton1_CheckedChanged2(ByVal sender As Object, ByVal e As Bunifu.UI.WinForms.BunifuRadioButton.CheckedChangedEventArgs)
Ife.Checked Then'sets the default cubic interploation mode bunifuLineChart1.CubicInterpolationMode = BunifuLineChart.CubicInterpolationModes.Default Else 'sets a monotone cubic interpolation modebunifuLineChart1.CubicInterpolationMode=BunifuLineChart.CubicInterpolationModes.MonotoneEnd IfEnd Sub
2. LineTension
Gets and sets a double numeric value that changes a curve tension of a spline line chart. A zero value renders straight line charts.
Note that the property doesn’t work when
a monotone algorithm is used in the cubic interpolation mode property.
rendering a stepped line chart.
3. Order
This property gets and sets the z-order index of a dataset in the case of multiple datasets. A dataset having a less order number will be displayed in front of other line datasets.
For example, let's have a pair of charts targeted to the same canvas. The line chart to have an order value of 0 and another chart set to an order value 1. The chart which has an order value of 0 will be displayed on top of the other chart components that have a value of 1 and above.
An additional point to note is that a higher negative ordered line plot will render the line chart above other chart components( such as lines, area, scatter plot, bar, etc.), that have a lower negative order value.
As can see, the code below assigns different higher negative order values to render the line plots above the other line plots.
Private Sub setBorderWidth(ByVal bunifuLineChart As BunifuLineChart, ByVal width As Integer) bunifuLineChart.BorderWidth = widthEnd Sub Private Sub bunifuRadioButton1_CheckedChanged2(ByVal sender As Object, ByVal e As Bunifu.UI.WinForms.BunifuRadioButton.CheckedChangedEventArgs)
If e.Checked Then bunifuLineChart1.Order =0 bunifuLineChart2.Order =1 bunifuLineChart3.Order =2 setBorderWidth(bunifuLineChart1,6) setBorderWidth(bunifuLineChart2,3) setBorderWidth(bunifuLineChart3,3) End If End Sub Private Sub bunifuRadioButton2_CheckedChanged2(ByVal sender As Object, ByVal e As Bunifu.UI.WinForms.BunifuRadioButton.CheckedChangedEventArgs)
If e.Checked Then bunifuLineChart2.Order =-1 bunifuLineChart1.Order =0 bunifuLineChart3.Order =2 setBorderWidth(bunifuLineChart2,6) setBorderWidth(bunifuLineChart1,3) setBorderWidth(bunifuLineChart3,3) End If End Sub Private Sub bunifuRadioButton3_CheckedChanged2(ByVal sender As Object, ByVal e As Bunifu.UI.WinForms.BunifuRadioButton.CheckedChangedEventArgs)
If e.Checked Then bunifuLineChart3.Order =-2 bunifuLineChart1.Order =0 bunifuLineChart2.Order =2 setBorderWidth(bunifuLineChart3,6) setBorderWidth(bunifuLineChart2,3) setBorderWidth(bunifuLineChart1,3) End If End Sub
4.ShowLine
This property gets and sets a boolean value (true or false) to hide or show the line on the canvas. A false value will hide the line plot but display the data points.
5. SteppedLine
This property gets and sets the type of line to render on the canvas. Values of a stepped line include;
False: does not render a step plot. It is the common default value, for rendering a spline chart
Before: renders a plot value before the next step of a data category. The same graphical plot is also applied with the true value. Below is its illustration
Middle: renders a plot value in the middle step of a data category
After: which renders a plot value after the next step of data category.
Border (Line plot) properties
1. BorderCapStyle
This property gets or sets the end cap style of a line plot. The property can be set to one of the following the values can be configured as follows:
Butt - renders a squared border style for the line plot's beginning and end. This is the line plot's default value.
Square - functions similarly as a Butt prop value where it renders a squared border cap at the end and at the start of the line plot.
Round - renders a rounded cap at the start and at the end of the line plot.
The following code demonstrates how to change the border cap at run-time.
Imports Bunifu.Charts.WinForms.ChartTypes Private Sub bunifuRadioButton1_CheckedChanged(ByVal sender As Object, ByVal e As Bunifu.UI.WinForms.BunifuRadioButton.CheckedChangedEventArgs)
If e.Checked Then bunifuLineChart1.BorderCapStyle = BunifuLineChart.LineCaps.Butt bunifuChartCanvas1.Update() End If End Sub Private Sub bunifuRadioButton2_CheckedChanged(ByVal sender As Object, ByVal e As Bunifu.UI.WinForms.BunifuRadioButton.CheckedChangedEventArgs)
If e.Checked Then bunifuLineChart1.BorderCapStyle = BunifuLineChart.LineCaps.Round bunifuChartCanvas1.Update() End If End Sub
2. BorderWidth
This property gets and sets an integer value that changes the line plot's width. The greater the value, the denser the line plot.
Data Point properties
1. PointBackgroundColor
This property sets or gets a data point background color on the line plot.
2. PointBorderColor
This property gets and sets a color value to the point border on a line plot.
3. PointBorderWidth
This property gets and sets an integer number that changes the border width of the line's data points.
4. PointRadius
This property gets or sets the integer value that decreases or increases the radius of a point (i.e. distance from the point’s center to its border). It can as well be used to enlarge the points on a line plot.
5. PointStyle
This property gets or sets a shape (circle, star, line, etc...) to render as a data point on the line plot.
6. PointRotation
This property gets or sets the integer value that changes the angle of points on a line plot.
The code below shows how to set the PointStyle and PointRotation properties at run-time.
usingBunifu.Charts.WinForms.ChartTypes;usingSystem;//using a dropdown SelectedIndex property to change the style of a pointprivatevoidbunifuDropdown1_SelectedIndexChanged(object sender,EventArgs e) {if (bunifuDropdown1.SelectedIndex==0) {bunifuLineChart1.PointStyle=BunifuLineChart.PointStyles.Circle; }elseif (bunifuDropdown1.SelectedIndex==1) {bunifuLineChart1.PointStyle=BunifuLineChart.PointStyles.CrossRot; }elseif (bunifuDropdown1.SelectedIndex==2) {bunifuLineChart1.PointStyle=BunifuLineChart.PointStyles.RectRounded; }else {bunifuLineChart1.PointStyle=BunifuLineChart.PointStyles.Triangle; } }/*On an slider scroll event the PointRotation property of the line chart shall be set with the slider's value;*/privatevoidbunifuHSlider1_Scroll(object sender,Utilities.BunifuSlider.BunifuHScrollBar.ScrollEventArgs e) {bunifuLineChart1.PointRotation=bunifuHSlider2.Value;bunifuChartCanvas1.Update(); }
ImportsBunifu.Charts.WinForms.ChartTypesImportsSystem'using a dropdown SelectedIndex property to change the style of a point Private Sub bunifuDropdown1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) If bunifuDropdown1.SelectedIndex = 0 Then bunifuLineChart1.PointStyle = BunifuLineChart.PointStyles.Circle ElseIf bunifuDropdown1.SelectedIndex = 1 Then bunifuLineChart1.PointStyle = BunifuLineChart.PointStyles.CrossRot ElseIf bunifuDropdown1.SelectedIndex = 2 Then bunifuLineChart1.PointStyle = BunifuLineChart.PointStyles.RectRounded Else bunifuLineChart1.PointStyle = BunifuLineChart.PointStyles.Triangle End If End Sub'On an slider scroll event the PointRotation property of the' line chart shall be set with the slider's value; Private Sub bunifuHSlider1_Scroll(ByVal sender As Object, ByVal e As Utilities.BunifuSlider.BunifuHScrollBar.ScrollEventArgs)
bunifuLineChart1.PointRotation=bunifuHSlider2.ValuebunifuChartCanvas1.Update()EndSub
7. PointHoverBackgroundColor
This property sets a color value property to the point's background when a mouse pointer hovers over a data point from the line plot.
8. PointHoverBorderWidth
This property sets an integer value property to the point's border width on a mouse hover. When a mouse pointer hovers over a data point in a line plot, this property sets an integer value property to the point's border width.
9. PointHoverRadius
This property sets the integer value that decreases or increases the radius of a point (i.e. distance from the point’s center to its border), when a mouse pointer hovers over a data point from the line plot. It can as well be used to enlarge the hovered point on a line plot.
Creating Area Charts
Bunifu line can also be used to create spline-area charts or stepped-line area charts by utilizing the following properties:
1.BackgroundColor property
This property gets and sets the color value for the background fill. It can accept an RGB color specification or an ARGB color specification. In addition, the property is also used to set the colors of the line data points.
2. Fill property
This property gets and sets the type of fill mode for its background color. A false value will disable the fill mode. The following are the possible values to use in the property:
Start: Fills the background color on the bounded line plot area.
Origin: Fills the background color on the space within the bounding line. It has the same effect as setting the Fill property to the start value.
End: Fills the background color on the outer area of the bounding line plot.
Blank: This is the default value of rendering a line chart. It renders a line plot without a background color around the boundary line.
Here's a sample application using the FillType prop values at run-time as explained from above
Setting the FillType property at runtime is demonstrated in the following code:
usingBunifu.Charts.WinForms.ChartTypes;usingSystem; //the radio buttons are used to change the different values used in the FillType property. private void bunifuRadioButton1_CheckedChanged2(object sender, Bunifu.UI.WinForms.BunifuRadioButton.CheckedChangedEventArgs e)
{if (e.Checked) {bunifuLineChart1.Fill=BunifuLineChart.FillOptions.Blank; } } private void bunifuRadioButton2_CheckedChanged2(object sender, Bunifu.UI.WinForms.BunifuRadioButton.CheckedChangedEventArgs e)
{if (e.Checked) {bunifuLineChart1.Fill=BunifuLineChart.FillOptions.Start; } } private void bunifuRadioButton3_CheckedChanged2(object sender, Bunifu.UI.WinForms.BunifuRadioButton.CheckedChangedEventArgs e)
{if (e.Checked) {bunifuLineChart1.Fill=BunifuLineChart.FillOptions.End; } }
Imports Bunifu.Charts.WinForms.ChartTypes Imports System'the radio buttons are used to change the different values used in the FillType property. Private Sub bunifuRadioButton1_CheckedChanged2(ByVal sender As Object, ByVal e As Bunifu.UI.WinForms.BunifuRadioButton.CheckedChangedEventArgs)
If e.Checked Then bunifuLineChart1.Fill = BunifuLineChart.FillOptions.Blank End If End Sub Private Sub bunifuRadioButton2_CheckedChanged2(ByVal sender As Object, ByVal e As Bunifu.UI.WinForms.BunifuRadioButton.CheckedChangedEventArgs)
If e.Checked Then bunifuLineChart1.Fill = BunifuLineChart.FillOptions.Start End If End Sub Private Sub bunifuRadioButton3_CheckedChanged2(ByVal sender As Object, ByVal e As Bunifu.UI.WinForms.BunifuRadioButton.CheckedChangedEventArgs)
If e.Checked Then bunifuLineChart1.Fill = BunifuLineChart.FillOptions.End End If End Sub
There are 3 types of area charts that Bunifu Line can render: single area charts (as shown in the above picture) , overlapping area charts, and stacked area charts.
A single area chart contains one dataset category whereas overlapping and stacked area charts have at most 2 dataset categories.
Avoid using area charts when there are more than 3-4 categories. In that case use line charts.
To create an overlapping chart have a pair of bunifu lines each having different datasets. Each to have a FillType value of start and set its background colors.
Make the colors transparent to avoid obscuring information in the background. To set a transparent color use the Alpha, Red, Green and Blue (ARGB) color format.
In the example below, the background colors for the first line chart is 190,186,85,211; and for the second line chart, is 100,249,233, 0.
To render a stacked area chart, set the canvas's XAxesStacked property to true. The outcome is depicted below.
Take Away
Bunifu Line Chart is an excellent charting tool in condensing both small and large datasets into manageable visualizations - and it's more enjoyable than poring over tables. If you've ever designed a dashboard or worked on another project that requires data visualization, you understand how difficult it can be to design such dashboards. Bunifu Line chart is able to assist you in creating visually appealing dashboards.