创建开 高 低 收(OHLC)股票图表

可能的使用场景

开-高-低-收(OHLC)图表使用五列数据,分别是类别、开盘、最高、最低和收盘。每个类别的价格范围再次通过垂直线表示,开盘价格和收盘价格之间的范围由一个更宽的浮动条表示;如果该类别的价格上升(收盘价高于开盘价),则该条将填充一种颜色,而如果价格下降,则用另一种颜色填充。这种图表通常被称为蜡烛图。

todo:image_alt_text

todo:image_alt_text

图表的可见性改进

我们经常使用颜色而不是黑白来表示价格的涨跌。在下面的第一组蜡烛图中,红色显示上涨,绿色表示下跌。

todo:image_alt_text

示例代码

以下示例代码加载了示例Excel文件,并生成了输出Excel文件

from aspose.cells import Workbook
from aspose.cells.charts import ChartType, LegendPositionType
from aspose.cells.drawing import FillType
from aspose.pydrawing import Color
# Create an instance of Workbook
workbook = Workbook("Open-High-Low-Close.xlsx")
# Access the first worksheet.
worksheet = workbook.worksheets[0]
# Create High-Low-Close-Stock Chart
pieIdx = worksheet.charts.add(ChartType.STOCK_OPEN_HIGH_LOW_CLOSE, 5, 6, 20, 12)
# Retrieve the Chart object
chart = worksheet.charts[pieIdx]
# Set the legend can be showed
chart.show_legend = True
# Set the chart title name
chart.title.text = "OPen-High-Low-Close Stock"
# Set the Legend at the bottom of the chart area
chart.legend.position = LegendPositionType.BOTTOM
# Set data range
chart.set_chart_data_range("A1:E9", True)
# Set category data
chart.n_series.category_data = "A2:A9"
# Set the DownBars and UpBars with different color
chart.n_series[0].down_bars.area.foreground_color = Color.green
chart.n_series[0].up_bars.area.foreground_color = Color.red
# Fill the PlotArea area with nothing
chart.plot_area.area.fill_format.fill_type = FillType.NONE
# Save the Excel file
workbook.save("out.xlsx")