Autor: Bodoconsult EDV-Dienstleistungen GmbH, Robert Leisner
https://www.nuget.org/packages/Bodoconsult.Core.Charting/
https://github.com/RobertLeisner/Bodoconsult.Core.Charting
Bodoconsult.Core.Charting is a library for creating charts from database data. The workflow for using the library is generally as follows:
To work properly the DataTable objects must have a certain logical structure depending on the type of chart you want to create.
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.
All chart types require a IList
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.
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;
}
}
ChartItemData class
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();
ChartItemData class
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();
ChartItemData class
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);
ChartItemData class
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();
ChartItemData class
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();
ChartItemData class
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();
PieChartItemData class
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();
PointChartItemData class
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();
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.
Copyright (c) Bodoconsult EDV-Dienstleistungen GmbH, Vaterstetten (Germany)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Url: https://www.nuget.org/packages/ScottPlot
Project: https://swharden.com/scottplot/
MIT License
Copyright (c) _____
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MIT License
Copyright (c) _____
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Url: https://www.nuget.org/packages/System.Drawing.Common
Licence: https://licenses.nuget.org/MIT
The MIT License (MIT) for Bodoconsult.Core.Typography Copyright (c) Bodoconsult EDV-Dienstleistungen GmbH, Vaterstetten (Germany)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Url: https://github.com/RobertLeisner/Bodoconsult.Core.Typography
Licence: https://github.com/RobertLeisner/Bodoconsult.Core.Typography/blob/master/LICENSE.md