Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7990137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:55:13+00:00 2026-06-04T12:55:13+00:00

Is it possible to create a plot from List(Of Decimal) values in Excel with

  • 0

Is it possible to create a plot from List(Of Decimal) values in Excel with VB? I would like to avoid dumping data directly into a table, then creating the chart from that. Here is what I have so far, but I am getting a data type mismatch when I try to assign .XValues and .Values to the list. Is there some sort of conversion that needs to happen to turn a list into a series?

    Dim Series As Excel.Series
    Dim xVals As New List(Of Decimal)(New Decimal() {1, 3, 4, 5})
    Dim yVals As New List(Of Decimal)(New Decimal() {2, 2, 2, 2})
    xlWorkSheet = CType(Globals.ThisAddIn.Application.Worksheets.Add(), Excel.Worksheet)

    xlWorkSheet.Activate()
    xlWorkSheet.Name = "My Sheet"
    xlCharts = xlWorkSheet.ChartObjects
    xlChartObj = xlCharts.Add(150, 30, 400, 250)
    xlChart = xlChartObj.Chart

    With xlChart
        .ChartType = Excel.XlChartType.xlXYScatterLines
        .HasLegend = True
        .Legend.Position = Excel.XlLegendPosition.xlLegendPositionRight
        .HasTitle = True
        .ChartTitle.Text = "Test Chart"
        For i = 0 To channels.Count - 1
            .SeriesCollection.NewSeries()
            Series = .SeriesCollection(i + 1)
            Series.XValues = xVals
            Series.Values = yvals
        Next
        .Location(Excel.XlChartLocation.xlLocationAsNewSheet)
    End With

UPDATE:

I seems like the following code will work, but it is not very ideal. Is there a better way to do this other than converting the array to a string representation of the array like I did?

    Dim Series As Excel.Series
    Dim xVals As New List(Of Decimal)(New Decimal() {1, 3, 4, 5})
    Dim yVals As New List(Of Decimal)(New Decimal() {2, 2, 2, 2})
    Dim xString As String
    Dim yString As String
    xlWorkSheet = CType(Globals.ThisAddIn.Application.Worksheets.Add(), Excel.Worksheet)

    xlWorkSheet.Activate()
    xlWorkSheet.Name = "My Sheet"
    xlCharts = xlWorkSheet.ChartObjects
    xlChartObj = xlCharts.Add(150, 30, 400, 250)
    xlChart = xlChartObj.Chart

    With xlChart
        .ChartType = Excel.XlChartType.xlXYScatterLines
        .HasLegend = True
        .Legend.Position = Excel.XlLegendPosition.xlLegendPositionRight
        .HasTitle = True
        .ChartTitle.Text = "Test Chart"
        For i = 0 To channels.Count - 1
            .SeriesCollection.NewSeries()
            Series = .SeriesCollection(i + 1)

            xString = "={"
            xString += xVals(0).ToString
            For k = 1 To xVals.Count - 1
                xString += ","
                xString += xVals(k).ToString
            Next
            xString = "}"

            yString = "={"
            yString += yVals(0).ToString
            For k = 1 To yVals.Count - 1
                yString += ","
                yString += yVals(k).ToString
            Next
            yString = "}"

            Series.XValues = xString
            Series.Values = yString
        Next
        .Location(Excel.XlChartLocation.xlLocationAsNewSheet)
    End With
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:55:15+00:00Added an answer on June 4, 2026 at 12:55 pm

    I was able to get what I wanted with the following code using Ranges stored as objects. The string method I mentioned in my second block of code had a limit of 8000+ characters (not sure of actual number, 8192?).

    Dim Series As Excel.Series
    Dim xVals As New List(Of Decimal)(New Decimal() {1, 3, 4, 5})
    Dim yVals As New List(Of Decimal)(New Decimal() {2, 2, 2, 2})
    Dim xRange As Object
    Dim yRange As Object
    Dim tempSheet as Excel.Worksheet
    
    xlWorkSheet = CType(Globals.ThisAddIn.Application.Worksheets.Add(), Excel.Worksheet)
    xlWorkSheet.Activate()
    xlWorkSheet.Name = "My Sheet"
    xlCharts = xlWorkSheet.ChartObjects
    xlChartObj = xlCharts.Add(150, 30, 400, 250)
    xlChart = xlChartObj.Chart
    
    With xlChart
        .ChartType = Excel.XlChartType.xlXYScatterLines
        .HasLegend = True
        .Legend.Position = Excel.XlLegendPosition.xlLegendPositionRight
        .HasTitle = True
        .ChartTitle.Text = "Test Chart"
        For i = 0 To channels.Count - 1
            tempSheet = CType(Globals.ThisAddIn.Application.Worksheets.Add(), Excel.Worksheet)
            tempSheet.Activate()
            With tempSheet
                .Visible = False
                For k = 0 To xVals.Count - 1
                    tempSheet.Cells(k + 1, 1).Value = xVals(k)
                    tempSheet.Cells(k + 1, 2).Value = yVals(k) 'Assumes yVals.Count = xVals.Count
                Next
                xRange = tempSheet.Range("A1:A" + xVals.Count.ToString).Value
                yRange = tempSheet.Range("B1:B" + xVals.Count.ToString).Value
                Globals.ThisAddIn.Application.DisplayAlerts = False
                .Delete()
                Globals.ThisAddIn.Application.DisplayAlerts = True
            End With
    
            Series = .SeriesCollection.NewSeries()
            With Series
                .XValues = xRange
                .Values = yRange
            End With            
        Next
        .Location(Excel.XlChartLocation.xlLocationAsNewSheet)
    End With
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Create an Iframe from a Drupal Website I'd like to use an
Hi it'd like to know if it's at all possible create a parametric equalizer
Possible Duplicate: Create Excel file in Java How to save output in excel format
Is it possible to create a custom route for GDirections to walk around? Like
If I create a multi-plot window with par(mfrow=...) , is it possible to send
I can create a faceted plot like so, with 3 plots stacked vertically :
is that possible create an abstract class from DbQuery and IDbSet? I'm trying to
Possible Duplicate: Create a date with T-SQL I've a data table that stores each
I have a data.frame with a column with values ranging from 0 to 50.000.
Is it possible to call the plot functions from the c++ ? Currently when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.