Advertisement

02.28.2008 at 06:47AM PST, ID: 23200380
[x]
Attachment Details

How do I set an Excel Chart Series up using VB.Net

Asked by kuelbsd in .NET, Microsoft Excel Spreadsheet Software, Visual Studio .NET 2005

Tags: Microsoft, vb.net & Excel, vb.net 2005 Excell 2000

I am reading a database and creating several excel spreadsheets containing different view of the data.  I would also like to chart the data.  I have everything formatted out correctly but the series name.  The legend always reads, "series 1, series 2, etc"  I need to be able to assign the names to the series.

The code used to generate the chart is attached and a view of the chart.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
Dim objChart As Excel.Chart
        Dim ChrtsYearToDate As Excel.ChartObjects
        Dim ChrtYearToDate As Excel.ChartObject
        Dim chrtSheet As Excel.Worksheet = wb.Worksheets.Add
        Dim dataSheet As Excel.Worksheet = wb.Worksheets.Item("Year To Date NPS")
        'Dim objSeries As Excel.SeriesCollection
 
        chrtSheet.Name = "Year To Date Chart"
        'dataSheet.Name = "Year To Date NPS"
        ChrtsYearToDate = chrtSheet.ChartObjects
        'set chart location
 
        ChrtYearToDate = ChrtsYearToDate.Add(0, 0, 800, 400)
        objChart = ChrtYearToDate.Chart
        'use the follwoing line if u want 
        'to draw chart on the default location
        objChart.Location(Excel.XlChartLocation.xlLocationAsObject, chrtSheet.Name)
 
        With objChart
 
            'set data range for chart
            Dim chartRange As Excel.Range
            chartRange = dataSheet.Range("A1", "D3")
            .SetSourceData(chartRange)
 
            'set how you want to draw chart i.e column wise or row wise
            .PlotBy = Excel.XlRowCol.xlRows
 
            'set data lables for bars
            .ApplyDataLabels(Excel.XlDataLabelsType.xlDataLabelsShowNone)
 
            'set legend to be displayed or not and location
            .HasLegend = True
            .Legend.Position = Excel.XlLegendPosition.xlLegendPositionRight
 
            'select chart type
            .ChartType = Excel.XlChartType.xlColumnClustered
 
            'chart title
            .HasTitle = True
            .ChartTitle.Text = "Year To Date NPS"
 
            'set titles for Axis values and categories
            Dim xlAxisCategory As Excel.Axes
            Dim xlAxisValue As Excel.Axes
            xlAxisCategory = CType(objChart.Axes(, Excel.XlAxisGroup.xlPrimary), Excel.Axes)
            xlAxisCategory.Item(Excel.XlAxisType.xlCategory).HasTitle = True
            xlAxisCategory.Item(Excel.XlAxisType.xlCategory).AxisTitle.Characters.Text = "Week Number"
            xlAxisValue = CType(objChart.Axes(, Excel.XlAxisGroup.xlPrimary), Excel.Axes)
            xlAxisValue.Item(Excel.XlAxisType.xlValue).HasTitle = True
            xlAxisValue.Item(Excel.XlAxisType.xlValue).AxisTitle.Characters.Text = "Percent"
            xlAxisValue.Item(Excel.XlAxisType.xlValue).MaximumScale = 100
        End With
Attachments:
 
View of the chart being created with sample data.
View of the chart being created with sample data.
 
 
Loading Advertisement...
 
[+][-]02.28.2008 at 07:20AM PST, ID: 21004521

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 07:25AM PST, ID: 21004585

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 07:34AM PST, ID: 21004689

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET, Microsoft Excel Spreadsheet Software, Visual Studio .NET 2005
Tags: Microsoft, vb.net & Excel, vb.net 2005 Excell 2000
Sign Up Now!
Solution Provided By: rorya
Participating Experts: 1
Solution Grade: B
 
 
[+][-]02.28.2008 at 07:52AM PST, ID: 21004906

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628