Skip to main content

StockChartView Class

Contains settings that apply to stock series in a chart view.

Declaration

public class StockChartView extends ChartViewWithDataLabels

Remarks

When you add a StockSeries object to a chart, the chart creates a StockChartView object for the series. Call the Chart.getViews() method to access chart views.

Call setShowHighLowLines(boolean value) and setShowUpDownBars(boolean value) methods to display high-low lines and up-down bars. Call the setShowDropLines(boolean value) method to display drop lines.

Note

Add Open, High, Low, and Close series to a stock chart in this order. Up-down bars connect values of the first and last series in each category.

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

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

See Also

StockChartView()

Initializes a new instance of the StockChartView class.

Declaration

public StockChartView()

Methods

getChartType() Method

Returns the chart type of the view.

Declaration

public ChartType getChartType()

Returns

Type Description
ChartType

ChartType.STOCK.

getDataLabels() Method

Returns data label settings for all series in the view.

Declaration

public IStockDataLabels getDataLabels()

Returns

Type Description
IStockDataLabels

Data label settings.

Remarks

Call the StockSeries.getDataLabels() method to access data label settings for an individual series.

Refer to the following help topic for additional information: Customize Chart Data Labels — Presentation API for Java.

getDownBarProperties() Method

Returns fill and outline settings for down bars.

Declaration

public ChartElement getDownBarProperties()

Returns

Type Description
ChartElement

Down bar settings, or null if the view has no down bar settings.

getDropLineProperties() Method

Returns settings for drop lines.

Declaration

public ChartElement getDropLineProperties()

Returns

Type Description
ChartElement

Drop line settings, or null if the view has no drop line settings.

getHighLowLineProperties() Method

Returns settings for high-low lines.

Declaration

public ChartElement getHighLowLineProperties()

Returns

Type Description
ChartElement

High-low line settings, or null if the view has no high-low line settings.

getShowDropLines() Method

Returns whether the view displays drop lines.

Declaration

public boolean getShowDropLines()

Returns

Type Description
boolean

true if the view displays drop lines; otherwise, false.

getShowHighLowLines() Method

Returns whether the view displays high-low lines.

Declaration

public boolean getShowHighLowLines()

Returns

Type Description
boolean

true if the view displays high-low lines; otherwise, false.

getShowUpDownBars() Method

Returns whether the view displays up-down bars.

Declaration

public boolean getShowUpDownBars()

Returns

Type Description
boolean

true if the view displays up-down bars; otherwise, false.

getUpBarProperties() Method

Returns fill and outline settings for up bars.

Declaration

public ChartElement getUpBarProperties()

Returns

Type Description
ChartElement

Up bar settings, or null if the view has no up bar settings.

getUpDownBarGapWidth() Method

Returns the distance between up-down bars.

Declaration

public int getUpDownBarGapWidth()

Returns

Type Description
int

The gap width as a percentage of the bar width (from 0 to 500).

setDownBarProperties(ChartElement value) Method

Sets fill and outline settings for down bars.

Declaration

public void setDownBarProperties(ChartElement value)

Parameters

Name Type Description
value ChartElement

Down bar settings.

Remarks

Note

Down bar settings take effect when you call the setShowUpDownBars(true) method.

setDropLineProperties(ChartElement value) Method

Sets settings for drop lines.

Declaration

public void setDropLineProperties(ChartElement value)

Parameters

Name Type Description
value ChartElement

Drop line settings.

Remarks

To specify the line color and width, pass a ChartElement object with outline settings to the setDropLineProperties(value) method.

Note

Drop line settings take effect when you call the setShowDropLines(true) method.

setHighLowLineProperties(ChartElement value) Method

Sets settings for high-low lines.

Declaration

public void setHighLowLineProperties(ChartElement value)

Parameters

Name Type Description
value ChartElement

High-low line settings.

Remarks

To specify the line color and width, pass a ChartElement object with outline settings to the setHighLowLineProperties(value) method.

Note

High-low line settings take effect when you call the setShowHighLowLines(true) method.

setShowDropLines(boolean value) Method

Sets whether the view displays drop lines.

Declaration

public void setShowDropLines(boolean value)

Parameters

Name Type Description
value boolean

true to display drop lines; otherwise, false.

Remarks

Drop lines extend from data points to the category axis.

If you do not call the setShowDropLines(value) method, the API uses false. Call the setDropLineProperties(ChartElement value) method to specify the line color and width.

setShowHighLowLines(boolean value) Method

Sets whether the view displays high-low lines.

Declaration

public void setShowHighLowLines(boolean value)

Parameters

Name Type Description
value boolean

true to display high-low lines; otherwise, false.

Remarks

High-low lines connect the highest and lowest values in each category across all series in the view.

If you do not call the setShowHighLowLines(value) method, the API uses false. Call the setHighLowLineProperties(ChartElement value) method to specify the line color and width.

setShowUpDownBars(boolean value) Method

Sets whether the view displays up-down bars.

Declaration

public void setShowUpDownBars(boolean value)

Parameters

Name Type Description
value boolean

true to display up-down bars; otherwise, false.

Remarks

Up-down bars connect values of the first and last series in each category. The view displays an up bar if the last series value is greater than the first series value, and a down bar otherwise.

If you do not call the setShowUpDownBars(value) method, the API uses false. Call setUpBarProperties(ChartElement value), setDownBarProperties(ChartElement value), and setUpDownBarGapWidth(int value) methods to customize up-down bars.

setUpBarProperties(ChartElement value) Method

Sets fill and outline settings for up bars.

Declaration

public void setUpBarProperties(ChartElement value)

Parameters

Name Type Description
value ChartElement

Up bar settings.

Remarks

Note

Up bar settings take effect when you call the setShowUpDownBars(true) method.

setUpDownBarGapWidth(int value) Method

Sets the distance between up-down bars.

Declaration

public void setUpDownBarGapWidth(int value)

Parameters

Name Type Description
value int

The gap width as a percentage of the bar width (from 0 to 500).

Exceptions

Type Description
ArgumentOutOfRangeException

Thrown if the value parameter is less than 0 or greater than 500.

Remarks

The value range is from 0 to 500. If you do not call the setUpDownBarGapWidth(value) method, the API uses 150.

Note

The gap width takes effect when you call the setShowUpDownBars(true) method.