Reputation: 143
I need create line chart in visual studio in C#. I have a question, that is it possible to create charts with .NET Core in Windows Forms?
Upvotes: 9
Views: 20947
Reputation: 1978
A possible solution might be using the CEFSharp control displaying web page and this page displays chart generated with
https://github.com/Indemos/Canvas
<CanvasView @ref="View"></CanvasView>
@code
{
public CanvasView View { get; set; }
protected override async Task OnAfterRenderAsync(bool setup)
{
if (setup)
{
var generator = new Random();
var points = Enumerable.Range(1, 1000).Select(i => new BarShape
{
X = i,
Y = generator.Next(-5000, 5000)
} as IItemModel).ToList();
var composer = new Composer
{
Name = "Demo",
Items = points
};
await View.Create<CanvasEngine>(engine => composer);
composer.Update();
}
await base.OnAfterRenderAsync(setup);
}
}
Disclaimer: I am the author.
Upvotes: 0
Reputation: 59
I do it by installing System.Windows.Forms.DataVisualization + System.Data.SqlClient
Don't use Forms designer for charts in Winforms core projects. Just create a new Winforms solution with .Net Framework (not core). Then create a chart in a new form by using designer you can adjust it as you want (colors, series...). Copy related chart code (from code behind cs) into your WinForms core project that's it.
Upvotes: 1
Reputation: 19
Yes, you can do it as I did this.
That's all you need.
Upvotes: 2
Reputation: 339
Yes it's possible. You can get sample code here https://github.com/dotnet/winforms-datavisualization.
The line chart examples can be found in the folder sample/ChartSamples/ChartTypes/LineCharts.
Note: DataVisualization is deprecated
Upvotes: 1