Chart Series Datasource

Posted by: svaz on 8 September 2017, 2:02 pm EST

  • Posted 8 September 2017, 2:02 pm EST

    Hi


    If I add a series to a XYPointSeries or XYBubbleSeries charts using the Change Datasource menu, it allows me to supply an address of the spreadsheet for name,x and y values, however if I create the series using code I cannot see the option to supply the values as addresses in the spreadsheet and I have to supply the values directly. Is there a reason for not exposing the same interface to programmers or is there a way that I am not aware of?


     


    Many thanks


    Svaz

  • Replied 8 September 2017, 2:02 pm EST

    Svaz,


    When working with the series classes, the data can be bound or unbound.


    For unbound data, you can use the Add or AddRange methods to store the data directly in the series.


        BarSeries series = new BarSeries();
        series.Values.AddRange(new double[] { 1.0, 3.0, 1.0, 9.0 });


    For bound data, you can use the DataSource and DataField properties.


    If the data is a list of numbers then you just need to set the DataSource property.


        double[] list = new double[] { 1.0, 2.0, 3.0, 4.0 };


        BarSeries series = new BarSeries();
        series.Values.DataSource = list;


    If the data is a list of objects that contain a number then you need to set both the DataSoure and DataField proeprties.


        DataTable table = new DataTable();
        table.Columns.Add("x", typeof(double));
        table.Columns.Add("y", typeof(double));
        table.Rows.Add(new object[] { 1.0, 2.0 });
        table.Rows.Add(new object[] { 2.0, 4.0 });
        table.Rows.Add(new object[] { 4.0, 3.0 });
        table.Rows.Add(new object[] { 8.0, 5.0 });


        BarSeries series = new BarSeries();
        series.Values.DataSource = table;
        series.Values.DataField = "x";


    When binding to cell values in the spreadsheet, you can use the SeriesDataField class for the series DataSource.  This class can be used to expose the cell values as a list of numbers.


        BarSeries series = new BarSeries();
        series.Values.DataSource = new FarPoint.Win.Spread.Chart.SeriesDataField(fpSpread1, "Values", "Sheet1!$C$1:$C$4");


    Bobby

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels