Skip to main content

Posts

Showing posts with the label Dynamic Chart

Generate a Pie Chart at runtime, C#, .NET

We can quickly write a function which returns a Pie Chart at runtime. Assuming that we are making a pie chart for the number of visitors/users from different countries, we will pass System.Data.DataTable as parameter to the function and it shall return a Chart object. Please add following namespaces to the page/class. using System.Windows.Forms.DataVisualization.Charting; using System.Drawing; using System.Data; Write the following function to get a Chart as return Parameter. You can pass a Datatable to the funtion with following schema, Datatable dt (Country Text, Users Int) Following is the function : protected internal Chart GetPieChart(DataTable dtChartData)         {             Chart pieChart = new Chart()             {                 Width = 800,                 Height = 800        ...