In my article on "SharePoint Web Part Development Tutorial" I discussed how we can develop and deploy custom SharePoint web part with visual designing. Now let’s see how we can add a chart for that web part. Finally you will be getting a result like following picture.
To create the above chart I’m getting data from a SharePoint list as follow.
You can see I’m showing the chart inside my custom web part called "My first custom Web Part". There I used the code from "Free Google Chart SharePoint Web Part" and customized it as I want. These are the steps to add nice chart to your web part for free.
First Create your custom web part, don’t deploy at this stage.
Then add a Class called “Chart.cs” and replace the code using following code.
Now change the variable names according to your site, list and columns.
Then Add this line to your .ascx file.
Now replace your "Page_Load" method as follows.
Now you can built and deploy your web part to see the result. You can get VerticalBar,Pie,Pie3D and HorizontalBar charts by changing the "ChartType" in the above code.