Bodoconsult.Core.Charting
1.0.2
dotnet add package Bodoconsult.Core.Charting --version 1.0.2
NuGet\Install-Package Bodoconsult.Core.Charting -Version 1.0.2
<PackageReference Include="Bodoconsult.Core.Charting" Version="1.0.2" />
paket add Bodoconsult.Core.Charting --version 1.0.2
#r "nuget: Bodoconsult.Core.Charting, 1.0.2"
// Install Bodoconsult.Core.Charting as a Cake Addin #addin nuget:?package=Bodoconsult.Core.Charting&version=1.0.2 // Install Bodoconsult.Core.Charting as a Cake Tool #tool nuget:?package=Bodoconsult.Core.Charting&version=1.0.2
What does the library
Bodoconsult.Core.Charting is a library for creating charts from database data. The workflow for using the library is generally as follows:
- Getting data as DataTable from a database
- Create a ChartData object to make general settings for the chart and load the data from the DataTable as List<IChartItemData>
- Create a ChartHandler and deliver the ChartData object to it
- Export the data to a file
To work properly the DataTable objects must have a certain logical structure depending on the type of chart you want to create.
How to use the library
The source code contains NUnit test classes the following source code is extracted from. The samples below show the most helpful use cases for the library.
Chart data input
All chart types require a IList<IChartItemData> as input.
There are three classes implementing IChartItemData: ChartItemData, PieChartItemData and PointChartItemData. See the description for each chart type below for the required type of data input.
Style the charts
Chart styling is based on the class ChartStyle from the library Bodoconsult.Core.Typography you can download via Nuget. See the following code fragments for how chart styling is done in the test project.
public static class TestHelper
{
...
/// <summary>
/// Load a default style for the charts
/// </summary>
/// <param name="chartData"></param>
/// <param name="highResolution"></param>
public static void LoadDefaultChartStyle(ChartData chartData, bool highResolution = false)
{
var chartStyle = GlobalValues.DefaultTypography().ChartStyle;
if (highResolution)
{
chartStyle.Width = 4500;
chartStyle.Height = 2781;
chartStyle.FontSize = 12;
}
chartStyle.CopyrightFontSizeDelta = 0.6F;
chartStyle.BackgroundColor = Color.Transparent;
//_chartStyle.AxisLineColor = Color.DarkBlue;
//
chartData.ChartStyle = chartStyle;
chartData.Copyright = "(c) Testfirma";
}
...
}
public static class GlobalValues
{
/// <summary>
/// Get a elegant default typography
/// </summary>
/// <returns></returns>
public static ITypography DefaultTypography()
{
var typography = new ElegantTypographyPageHeader("Calibri", "Calibri", "Calibri")
{
ChartStyle =
{
Width = 750,
Height = 464,
FontSize = 10,
BackGradientStyle = GradientStyle.TopBottom,
}
};
return typography;
}
}
Line chart
Sample image
Chart data
ChartItemData class
Code
const string fileName = @"d:\temp\ScottPlott_LineChart.png";
if (File.Exists(fileName)) File.Delete(fileName);
var data = new ChartData
{
Title = "Test portfolio",
Copyright = "Testfirma",
XLabelText = "Anlageklassen",
YLabelText = "Anteilwert",
FileName = fileName,
ChartType = ChartType.LineChart,
//PaperColor = Color.Red
};
TestHelper.LoadDefaultChartStyle(data, HighResolution);
TestDataHelper.ChartSample(UseDatabase, data);
data.ChartStyle.XAxisNumberformat = "dd.MM.yyyy";
data.PropertiesToUseForChart.Add("XValue");
data.PropertiesToUseForChart.Add("YValue1");
data.PropertiesToUseForChart.Add("YValue2");
data.PropertiesToUseForChart.Add("YValue3");
data.LabelsForSeries.Add("Aktien");
data.LabelsForSeries.Add("Renten");
data.LabelsForSeries.Add("Liquidität");
var x = new ChartHandler
{
ChartData = data
};
x.Export();
Bar chart
Sample image
Chart data
ChartItemData class
Code
const string fileName = @"d:\temp\ScottPlott_BarChart.png";
if (File.Exists(fileName)) File.Delete(fileName);
var data = new ChartData
{
Title = "Test portfolio",
Copyright = "Testfirma",
XLabelText = "Anlageklassen",
YLabelText = "Anteil in %",
FileName = fileName,
ChartType = ChartType.BarChart,
};
TestHelper.LoadDefaultChartStyle(data, HighResolution);
TestDataHelper.BarChartSample(UseDatabase, data);
data.ChartStyle.XAxisNumberformat = "0.00";
var x = new ChartHandler
{
ChartData = data
};
x.Export();
Column chart
Sample image
Chart data
ChartItemData class
Code
const string fileName = @"d:\temp\ScottPlott_ColumnChart.png";
if (File.Exists(fileName)) File.Delete(fileName);
var data = new ChartData
{
Title = "Test portfolio",
Copyright = "Testfirma",
XLabelText = "Anlageklassen",
YLabelText = "Anteil in %",
FileName = fileName,
ChartType = ChartType.ColumnChart,
};
TestHelper.LoadDefaultChartStyle(data, HighResolution);
TestDataHelper.BarChartSample(UseDatabase, data);
data.ChartStyle.YAxisNumberformat = "0.00";
var x = new ChartHandler
{
ChartData = data
};
x.Export();
TestHelper.StartFile(fileName);
Stacked bar chart
Sample image
Chart data
ChartItemData class
Code
const string fileName = @"d:\temp\ScottPlott_Db_StackedBarChart.png";
if (File.Exists(fileName)) File.Delete(fileName);
var data = new ChartData
{
Title = "Test portfolio",
Copyright = "Testfirma",
XLabelText = "Anlageklassen",
YLabelText = "Anteilswert",
FileName = fileName,
ChartType = ChartType.StackedBarChart,
};
TestHelper.LoadDefaultChartStyle(data);
var dt = TestHelper.GetDataTable("StackedBarChart.xml");
ChartUtility.DataTableToChartItemData(dt, "", data);
var x = new ChartHandler
{
ChartData = data
};
x.Export();
Stacked column chart
Sample image
Chart data
ChartItemData class
Code
const string fileName = @"d:\temp\ScottPlott_Db_StackedColumnChart.png";
if (File.Exists(fileName)) File.Delete(fileName);
var data = new ChartData
{
Title = "Test portfolio",
Copyright = "Testfirma",
XLabelText = "Anlageklassen",
YLabelText = "Anteilswert",
FileName = fileName,
ChartType = ChartType.StackedColumnChart,
};
TestHelper.LoadDefaultChartStyle(data);
var dt = TestHelper.GetDataTable("StackedColumnChart.xml");
ChartUtility.DataTableToChartItemData(dt, "", data);
var x = new ChartHandler
{
ChartData = data
};
x.Export();
Stacked column chart 100%
Sample image
Chart data
ChartItemData class
Code
const string fileName = @"d:\temp\ScottPlott_Db_StackedColumn100Chart.png";
if (File.Exists(fileName)) File.Delete(fileName);
var data = new ChartData
{
Title = "Test portfolio",
Copyright = "Testfirma",
XLabelText = "Anlageklassen",
YLabelText = "Anteilswert",
FileName = fileName,
ChartType = ChartType.StackedColumn100Chart,
};
TestHelper.LoadDefaultChartStyle(data);
var dt = TestHelper.GetDataTable("StackedColumnChart.xml");
ChartUtility.DataTableToChartItemData(dt, "", data);
var x = new ChartHandler
{
ChartData = data
};
x.Export();
Pie chart
Sample image
Chart data
PieChartItemData class
Code
const string fileName = @"d:\temp\ScottPlott_PieChart.png";
if (File.Exists(fileName)) File.Delete(fileName);
var data = new ChartData
{
Title = "Test portfolio",
Copyright = "Testfirma",
YLabelText = "Anteil in %",
FileName = fileName,
ChartType = ChartType.PieChart,
};
TestHelper.LoadDefaultChartStyle(data, HighResolution);
TestDataHelper.PieChartSample(UseDatabase, data);
var x = new ChartHandler
{
ChartData = data
};
x.Export();
Point chart (risk-return-chart in finance)
Sample image
Chart data
PointChartItemData class
Code
const string fileName = @"d:\temp\ScottPlott_Db_StackedColumn100Chart.png";
if (File.Exists(fileName)) File.Delete(fileName);
var data = new ChartData
{
Title = "Test portfolio",
Copyright = "Testfirma",
XLabelText = "Anlageklassen",
YLabelText = "Anteilswert",
FileName = fileName,
ChartType = ChartType.StackedColumn100Chart,
};
TestHelper.LoadDefaultChartStyle(data);
var dt = TestHelper.GetDataTable("StackedColumnChart.xml");
ChartUtility.DataTableToChartItemData(dt, "", data);
var x = new ChartHandler
{
ChartData = data
};
x.Export();
About us
Bodoconsult http://www.bodoconsult.de is a Munich based software company from Germany.
Robert Leisner is senior software developer at Bodoconsult. See his profile on http://www.bodoconsult.de/Curriculum_vitae_Robert_Leisner.pdf.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Bodoconsult.Core.Charting.Base (>= 1.0.2)
- Bodoconsult.Core.Typography (>= 1.0.1)
- ScottPlot (>= 4.1.59)
- System.Drawing.Common (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Migration to .NET 6 and updated dependencies