Creating graphs using vb.net

How can i create graphs using vb.net. any tips, links would be helpfull. 

thanx 


Answer this question

Creating graphs using vb.net

  • theblueeyz

    check out the controls in task vision - although there is just a pie chart and a bar chart, if your just starting out that's an excellent starter, but graphs are a little bit more complex to extremely more complex

    search google for "GDI+ tutorials graphs" you'll get liinks like <a href="http://csharpfriends.411asp.net/home/tutorial/howto/graphics/charts cob=csharpfriends">csharpfriends</a>

    anything that is asp.net you can use no problem in winforms, also if there are examples you find in C#, search for conversion programs online, there are a couple of good ones that perfectly convert code to vb

    HTH

  • David Noor (Microsoft)

    I've learned to use it mostly through trial and error.  I would however be happy to post the basics to get you started.

    First, add a reference to Excel to your project.  As long as Excel is installed on the development machine you will have "Microsoft Excel X.X Object Library" on the "COM" tab of the Add/Remove Reference dialog.  There will usually be 2 references, an Excel 5.0 and then what ever version you have installed (ie 9.0 for Office 2000, 10.0 for Office XP, 11.0 for Office 2003).  You can use either reference so long as you only need to implement functionality that is common from Office 97 forward.  I usually reference whatever version I have installed.

    Once that is done, you just need to create an instance of Excel, add a worksheet, and then start doing stuff with it!  =)

    This starts Excel or hooks a running instance:
    Dim MSExl As New Excel.Application

    This will give you access to a WorkSheet:
    Dim Sheet1 As New Excel.Worksheet
    MSExl.Workbooks.Add()
    Sheet1 = MSExl.Workbooks(1).Sheets(1)

    Then you can do things like this:

    'Sets the sheet name displayed on the WorkSheet tab of Excel
    Sheet1.Name = "Weekly Run " & dtEnd.Month.ToString & "-" & dtEnd.Day.ToString & "-" & dtEnd.Year.ToString

    'Sets up page
    Sheet1.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape
    Sheet1.PageSetup.LeftMargin = 25
    Sheet1.PageSetup.RightMargin = 25
    Sheet1.PageSetup.TopMargin = 25
    Sheet1.PageSetup.BottomMargin = 25
    Sheet1.PageSetup.HeaderMargin = 0
    Sheet1.PageSetup.FooterMargin = 0

    'Merges a group of cells
    Sheet1.Cells.Range(Sheet1.Cells.Item(1, 1), Sheet1.Cells.Item(1, 17)).Merge()
    'Sets the Alignment of merged cells to Center
    Sheet1.Cells.Range(Sheet1.Cells.Item(1, 1), Sheet1.Cells.Item(1, 17)).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter

    'Writes text into merged cells
    Sheet1.Cells.Item(1, 1) = "Cell Weekly Run Report  -  " & dtEnd.Add(New TimeSpan(1, 0, 0, 0, 0)).ToLongDateString & " thru " & Now.Subtract(New TimeSpan(1, 0, 0, 0, 0)).ToLongDateString

    'Sets fontsize and bold
    Sheet1.Cells.Item(1, 1).Font.Size = 14
    Sheet1.Cells.Item(1, 1).Font.Bold = True


    For the most part, anything you can make Excel do by clicking a button in the App, you can make it do from behind the scenes with code.  Just explore the Excel object a bit in the editor.  You can also go to the MSDN website and search the knowlegebase for automate excel in visual basic.

    Once you fill in some columns with your data, you should be able to create a chart view based on values in columns.

  • cais

    sorry <a href="http://www.windowsforms.com/Default.aspx tabindex=8&tabid=44">task vision</a> there is a link there to the custom GDI+ controls - I've used these fora  couple custom charts
  • Perlman

    Hi rkimble

    i want to create a line graph and pie graph. wud it me possible for you to post some kind of code or some link where i can find more details on how to automate excel for creating graphs.

    thanx

  • shaherome

    Have a look at the graph control created by www.carlosag.net built for web but could use for win too.

    Scott

  • Juan P. Arellano

    I don't know what your final product is to be, but I often automate an instance of Microsoft Excel when I want graphs or pretty data printouts.  Excel is on all our computers so its not a problem for me.  It is really pretty easy to hook into and it exposes all the nice features that Excel offers for manipulating and displaying data.

    Just another possible option!

  • TA123

    what do you mean by "check out the controls in task vision", which is task vision  i can't see any chart controls in my toolbox
  • Creating graphs using vb.net