StockSeries Class
A stock series in a standard chart.
Declaration
public class StockSeries extends LineSeriesBase
Remarks
Add StockSeries objects to the Chart.getSeries() collection to create a stock chart. The chart creates a StockChartView object for the series. Call StockChartView.setShowHighLowLines(value) and StockChartView.setShowUpDownBars(value) methods to display high-low lines and up-down bars.
Note
Add Open, High, Low, and Close series to a stock chart in this order.
Refer to the following help topic for additional information: Create Standard Charts — Presentation API for Java.
Example
Create a Stock Chart with High-Low Lines and Up-Down Bars
The following code snippet creates a stock chart with Open, High, Low, and Close series, displays high-low lines and colored up-down bars, and displays closing prices in data labels:
import java.io.*;
import java.nio.file.*;
import java.util.List;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;
import com.devexpress.system.drawing.*;
public class Main {
public static void main(String[] args) throws Exception {
try (Presentation presentation = new Presentation()) {
// Add a blank slide.
presentation.getSlides().clear();
Slide slide = new Slide(SlideLayoutType.BLANK);
presentation.getSlides().add(slide);
// Insert a chart that fills the slide.
Chart chart = new Chart();
chart.setWidth(presentation.getSlideSize().getWidth());
chart.setHeight(presentation.getSlideSize().getHeight());
slide.getShapes().add(chart);
// Add Open, High, Low, and Close series in this order.
String[] names = { "Open", "High", "Low", "Close" };
double[][] prices = {
{ 96, 88, 77, 92, 83 },
{ 100, 110, 105, 115, 99 },
{ 80, 73, 72, 78, 71 },
{ 90, 100, 81, 86, 88 }
};
for (int i = 0; i < names.length; i++) {
StockSeries series = new StockSeries();
series.setText(names[i]);
series.setArguments(new ChartStringData(List.of("Mon", "Tue", "Wed", "Thu", "Fri")));
series.setValues(new ChartNumericData(List.of(prices[i][0], prices[i][1], prices[i][2], prices[i][3], prices[i][4])));
// Hide series lines and markers.
OutlineStyle outline = new OutlineStyle();
outline.setFill(new NoFill());
ChartElement properties = new ChartElement();
properties.setOutlineStyle(outline);
series.setProperties(properties);
Marker marker = new Marker();
marker.setSymbol(MarkerStyle.NONE);
series.setMarker(marker);
chart.getSeries().add(series);
}
// Display high-low lines and up-down bars.
StockChartView view = (StockChartView) chart.getViews().get(0);
view.setShowHighLowLines(true);
view.setShowUpDownBars(true);
ChartElement upBars = new ChartElement();
upBars.setFill(new SolidFill(Color.getSeaGreen()));
view.setUpBarProperties(upBars);
ChartElement downBars = new ChartElement();
downBars.setFill(new SolidFill(Color.getIndianRed()));
view.setDownBarProperties(downBars);
// Display closing prices to the right of data points.
StockSeries closeSeries = (StockSeries) chart.getSeries().get(3);
closeSeries.getDataLabels().setShowValue(true);
closeSeries.getDataLabels().setLabelPosition(StockDataLabelPosition.RIGHT);
// Save the presentation.
Files.createDirectories(Path.of("output"));
try (OutputStream output = Files.newOutputStream(Path.of("output", "Chart.pptx"))) {
presentation.save(output);
}
}
}
}
Inherited Members
Inheritance
StockSeries()
Initializes a new instance of the StockSeries class.
Declaration
public StockSeries()
Methods
getAxisGroup() Method
Returns the axis group that displays the series.
Declaration
public ChartAxisGroupType getAxisGroup()
Returns
| Type | Description |
|---|---|
| ChartAxisGroupType | The axis group. |
getDataLabels() Method
Returns data label settings for the series.
Declaration
public IStockDataLabels getDataLabels()
Returns
| Type | Description |
|---|---|
| IStockDataLabels | Data label settings. |
Remarks
Call the StockChartView.getDataLabels() method to access data label settings for all series in a stock chart view.
Refer to the following help topic for additional information: Customize Chart Data Labels — Presentation API for Java.
getDataLabelsRange() Method
Returns a reference to cells that contain text for series data labels.
Declaration
public IChartDataReference getDataLabelsRange()
Returns
| Type | Description |
|---|---|
| IChartDataReference | A reference to the cell range, or |
getErrorBars() Method
Returns the collection of error bars for the series.
Declaration
public IErrorBarCollection getErrorBars()
Returns
| Type | Description |
|---|---|
| IErrorBarCollection | The collection of error bars. |
Remarks
Add an ErrorBar object to the collection to display error bars for series values.
Refer to the following help topic for additional information: Add Error Bars and Trend Lines to Charts — Presentation API for Java.
getTrendLine() Method
Returns the trend line of the series.
Declaration
public TrendLine getTrendLine()
Returns
| Type | Description |
|---|---|
| TrendLine | The trend line, or |
setAxisGroup(ChartAxisGroupType value) Method
Sets the axis group that displays the series.
Declaration
public void setAxisGroup(ChartAxisGroupType value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | ChartAxisGroupType | The axis group. |
Remarks
The setAxisGroup(value) method accepts the following values:
| Value | Description |
|---|---|
| PRIMARY | Indicates primary axes. |
| SECONDARY | Indicates secondary axes. |
If you do not call the setAxisGroup(value) method, the series uses primary axes. If you call the setAxisGroup(ChartAxisGroupType.SECONDARY) method, the chart moves the series to a separate chart view and creates secondary axes for this view.
Refer to the following help topics for additional information:
setDataLabelsRange(IChartDataReference value) Method
Sets a reference to cells that contain text for series data labels.
Declaration
public void setDataLabelsRange(IChartDataReference value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | IChartDataReference | A reference to the cell range, or |
Remarks
When you assign a cell range to a series in a chart, the API calls the setShowDataLabelRange(true) method of the object that the series getDataLabels() method returns. Each data label displays the value of the cell with the same index in the range. Call the setDataLabelsRange(null) method to remove cell values from data labels.
setTrendLine(TrendLine value) Method
Sets the trend line of the series.
Declaration
public void setTrendLine(TrendLine value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | TrendLine | The trend line, or |
Remarks
Refer to the following help topic for additional information: Add Error Bars and Trend Lines to Charts — Presentation API for Java.