Chart Example: Populating a Bar Chart with a Custom Data Series
Description
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.
Discussion
The Xbasic function below demonstrates how to create and return a charting::chartDataDefinition object that contains two data series. It also demonstrates how to set the title and X and Y axis labels for the chart.
function chartData as charting::chartDataDefinition() dim rdc as charting::chartDataDefinition rdc.title = "Expenditures by department" rdc.xAxisLabel = "Department" rdc.yAxisLabel = "Expenditure in $" dim s1 as charting::chartSeriesDefinition s1.label = "AMCE Corp" s1.data.add(charting::ChartValueDefinition::createX(200000)) s1.data.add(charting::ChartValueDefinition::createX(150000)) s1.data.add(charting::ChartValueDefinition::createX(160000)) s1.data.add(charting::ChartValueDefinition::createX(300000)) s1.data.add(charting::ChartValueDefinition::createX(100000)) rdc.series.add(s1) dim s2 as charting::chartSeriesDefinition s2.label = "International tool" s2.data.add(charting::ChartValueDefinition::createX(250000)) s2.data.add(charting::ChartValueDefinition::createX(180000)) s2.data.add(charting::ChartValueDefinition::createX(200000)) s2.data.add(charting::ChartValueDefinition::createX(400000)) s2.data.add(charting::ChartValueDefinition::createX(150000)) rdc.series.add(s2) rdc.dataAxisLabels.add("Research") rdc.dataAxisLabels.add("Shipping") rdc.dataAxisLabels.add("Sales") rdc.dataAxisLabels.add("Manufacturing") rdc.dataAxisLabels.add("IT") chartData = rdc end function
When used to populate a Bar Vertical Grouped chart, the following chart is created:
The chartData function is not limited for use with Bar charts. Other chart types, such as line charts, can also be used to display the data. You can use the Preview button in the dialog used to configure the Chart control to see how the data is rendered using other charting types.