Regina
Regina

Reputation: 143

Is it possible to create charts with .NET Core

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

Answers (4)

Anonymous
Anonymous

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

ELHILI Abdelmounaim
ELHILI Abdelmounaim

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

Alexandr Sahatir
Alexandr Sahatir

Reputation: 19

Yes, you can do it as I did this.

  1. Install into your WinForms core project Microsoft charts nuget
  2. Install into your WinForms core project other nuget
  3. Remark: Forms designer for charts in Winforms core projects will not work. But you can create a temporary Winforms .Net Framework project. Then create a chart by project form designer.
  4. Then copy chart code into your first WinForms core project.

That's all you need.

Upvotes: 2

ILally
ILally

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

Related Questions