Embedding Charts with a Custom Data Source

Description

Charts can be based on a custom data source defined using an Xbasic function.

Discussion

Xbasic can be used to generate the data to populate a chart control. To configure the chart control to use an Xbasic function, choose the "Custom" option when defining the data source to use.

You need to enter an expression that returns a ChartDataDefinition object. Typically, you will define an Xbasic function that returns a ChartDataDefinition object and you will enter an expression at the prompt that calls your function.

For example, you might enter this expression (where 'plotArrayData' is a function you defined that returns a ChartDataDefinition object):

plotArrayData(linkField)

Here is an example of how the 'plotArrayData' function could be defined. Notice that the function returns a ChartDataDefinition object.

function plotArrayData as Charting::ChartDataDefinition(linkingFieldValue as n)
    ' In this example, 'linkingFieldValue' is a field in the report with a type of 'n'. You can obviously
    ' pass in as many fields from the report data to you custom function as you want.

    'Create an array with some data to plot
    dim a[5] as p
    a[1].name = "alpha"
    a[1].value = 5

    a[2].name = "beta"
    a[2].value = 2

    a[3].name = "gamma"
    a[3].value = 7

    a[4].name = "delta"
    a[4].value = 3

    a[5].name = "epsilon"
    a[5].value = 9

    dim count as n
    count = a.size()
    dim i as n

    ' Dim the chart & series
    dim cd as Charting::ChartDataDefinition
    dim cs as Charting::ChartSeriesDefinition
    cd.series.add(cs)

    for i = 1 to count
        dim cdd as Charting::ChartValueDefinition = new Charting::ChartValueDefinition()
        cdd.value = a[i].value
        cdd.label = a[i].name + " ("+cdd.value+")"
        cs.data.add(cdd)
    next
    plotArrayData = cd
end function

For more examples and information, visit the links below:

Name
Description
Chart Example: Populating a Bar Chart with a Custom Data Series

This example demonstrates how to define an Xbasic function that is used as a Custom data source for a chart control to display multiple data series. The data series is used to populate a Bar Grouped Chart in a Report.

Chart API

Alpha Anywhere includes a powerful built-in charting engine that uses the charting capabilities of Microsoft .NET Framework 4. You can program the charting engine directly using the API described on this page, or create charts in a builder, described at Chart Control. Using the API gives you the maximum amount of flexibility, but using the builder you can produce most commonly-used charts quickly and easily.