All Projects → wangyiqian → StockChart

wangyiqian / StockChart

Licence: Apache-2.0 License
StockChart是一款适用于Android的高扩展性、高性能股票图开发库,轻松完成各种子图的组合,还能灵活的定制自己的子图满足复杂的业务需求。

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to StockChart

Yykline
iOS YYKline:Kline、Chart、Volume、Scroll、Scale、MACD、KDJ、K线图、分时图...
Stars: ✭ 2,318 (+3638.71%)
Mutual labels:  stock, kline, macd, kdj, boll
MyTT
MyTT将通达信,同花顺,文华麦语言等指标公式,最简移植到Python中,核心库单个文件,仅百行代码,十几个核心函数,神奇的实现所有常见技术指标算法(不依赖talib库)的纯python实现和转换通达信MACD,RSI,BOLL,ATR,KDJ,CCI,PSY等公式,全部基于pandas函数计算方法封装,简洁且高性能,能非常方便的应用在股票指标公式,股市期货量化框架分析,自动程序化交易,数字货币量化等领域,它是您最精练的股市量化工具。Python library with most stock market indicators.
Stars: ✭ 888 (+1332.26%)
Mutual labels:  stock, macd, kdj, boll
StockView
股票相关控件(分时图、五日分时图、自选股迷你分时图、资金趋势图、盈亏额/盈亏率)- (曲线图、折线图)
Stars: ✭ 87 (+40.32%)
Mutual labels:  stock, kline, stockview
QT StockFigure
QT显示股票分时线
Stars: ✭ 16 (-74.19%)
Mutual labels:  stock, kline
algorithmic-market-prediction
Implementation of Algorthmic Prediction of Candle Patterns
Stars: ✭ 21 (-66.13%)
Mutual labels:  stock, macd
Hycharts
柱状图、折/曲线图、K线图(主图、交易量图、辅助图), 图与图可以自由组合, 支持分页加载数据 -----> 低内存、低耗电、滑动缩放顺滑
Stars: ✭ 394 (+535.48%)
Mutual labels:  stock, kline
Klinechart
📈Lightweight k-line chart that can be highly customized. Zero dependencies. Support mobile.(可高度自定义的轻量级k线图,无第三方依赖,支持移动端)
Stars: ✭ 303 (+388.71%)
Mutual labels:  stock, kline
Hqchart
HQChart - H5, 微信小程序 沪深/港股/数字货币/期货/美股 K线图(kline),走势图,缩放,拖拽,十字光标,画图工具,截图,筹码图. 分析家语法,通达信语法,(麦语法),第3方数据替换接口
Stars: ✭ 1,126 (+1716.13%)
Mutual labels:  stock, kline
Kschart
k线图/kline/kchart,已经集成MA/EMA/MACD/KDJ/BOLL/RSI/WR/AVG等指标,新增指标及其方便。适用于股票/区块链交易所等种类App。Swift5编写,CPU/内存占用率极低,60FPS稳定运行。示例集成websocket,并接入币安数据(需VPN)。
Stars: ✭ 909 (+1366.13%)
Mutual labels:  stock, kline
Okklineswift
Draw the K-Line by Swift, support iOS & macOS
Stars: ✭ 406 (+554.84%)
Mutual labels:  stock, kline
OKKLineMin
OKKLineMin kline for min for learning for iPhone (support Swift5 & the latest Swift & iPhone & iOS 16)(min K线图 用于学习了解)
Stars: ✭ 23 (-62.9%)
Mutual labels:  stock, kline
bitcoin-stock-to-flow
Stock-to-Flow ratio and price for Bitcoin
Stars: ✭ 19 (-69.35%)
Mutual labels:  stock
openctp
CTP开放平台提供A股、港股、美股、期货、期权等全品种接入通道,通过提供中泰证券XTP、华鑫证券奇点、东方证券OST、东方财富证券EMT、盈透证券TWS等各通道的CTPAPI接口,CTP程序可以无缝对接各股票柜台。平台也提供了一套基于TTS交易系统的模拟环境,同样提供了CTPAPI兼容接口,可以替代Simnow,为CTP量化交易开发者提供7x24可用的模拟环境。
Stars: ✭ 389 (+527.42%)
Mutual labels:  stock
Steward
A stock portfolio manager that provides neural net based short-term predictions for stocks and natural language processing based analysis on community sentiments.
Stars: ✭ 25 (-59.68%)
Mutual labels:  stock
uzerp
uzERP - Open Source Business Management
Stars: ✭ 41 (-33.87%)
Mutual labels:  stock
RoboBull
A HackRU winner project. a user-friendly web-interface robo-adviser for novice traders that want to focus on day and short term trading. Project is using candlestick and moving average algorithms to predict suggestions (buy, sell, hold) for users. Product is also notifying users via SMS when the suggestion is changed; users are able to subscribe…
Stars: ✭ 12 (-80.65%)
Mutual labels:  stock
FinanceCenter
Fetching Financial Data (US/China)
Stars: ✭ 26 (-58.06%)
Mutual labels:  stock
getbhavcopy
Free NSE and BSE data downloader
Stars: ✭ 93 (+50%)
Mutual labels:  stock
d3-kagi
An open source javascript library to render beautiful Kagi charts using D3.js and pure Javascript
Stars: ✭ 26 (-58.06%)
Mutual labels:  stock
IEX CPP API
Unofficial C++ Lib for the IEXtrading API
Stars: ✭ 34 (-45.16%)
Mutual labels:  stock

介绍

StockChart是一款适用于Android的高扩展性、高性能股票图开发库,轻松完成各种子图的组合,还能灵活的定制自己的子图满足复杂的业务需求。

特点

  • 内置子图:K线图、时间条图、成交量图、MACD指标图、KDJ指标图
  • 内置指标:MA(移动平均线)、EMA(指数移动平均值)、BOLL(布林线)、MACD(指数平滑异同移动平均线)、KDJ(随机指标)
  • 支持自定义子图(以StockChart为内核,UI完全自己定制):若内置的子图样式(如K线图)无法满足您的需求或者您需要更多类型的指标图时,您可以通过自定义子图的方式来实现自己的子图。您甚至可以把内置的所有子图都当做你实现自定义子图的参考示例。如果您的项目是一个商业项目,可能更需要此功能来绘制自己需要的UI。这种设计可以避免基于源码修改,满足开闭原则

效果图

(若图片未显示,可能需要科学上网。)

插一条内推广告

阿里巴巴老虎集团(老虎证券) 2022各岗位内推,可发简历到我邮箱:[email protected]

用法

先明白几个概念

  • 所有要显示的图(内置的子图与自定义的子图)都是StockChart的子图。内置的子图:KChart(K线图)、TimeBarChart(时间条图)、VolumeChart(成交量图)、MacdChart(MACD指标图)、KdjChart(KDJ指标图)
  • 任何变化(如K线数据增加)都是通过修改配置去更新。全局配置:StockChartConfig,每个子图也有自己的配置如:KChartConfigKDJChartConfig
  • 逻辑坐标:原点是左下角,x轴从左到右变大,y轴从下到上变大。是最接近普通人理解股票图的坐标。
    • 逻辑坐标的x轴:固定规则,是这个数据集的下标,即从0开始,刻度为1。最小最大值范围是[0, kEntities.size - 1]。
    • 逻辑坐标的y轴:由子类各自根据实际情况提供。比如成交量图每个数据对应y轴上的值应该是成交量,比如K线图每个数据对应y轴上的值应该是价格。
  • 实际坐标:就是Android View的坐标体系,即最终绘制时View认识的坐标,原点是左上角,x轴从左到右变大,y轴从上到下变大。

基本使用

1. 集成

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation 'com.github.wangyiqian:StockChart:1.0.4'
}

2. 布局文件加入StockChart布局

<com.github.wangyiqian.stockchart.StockChart
    android:id="@+id/stock_chart"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

3. 设置StockChart的配置

val stockChartConfig = StockChartConfig()
stock_chart.setConfig(stockChartConfig)

4. 添加子图,将需要的子图的工厂添加给全局配置即可,如以下将添加三个子图:K线图、时间条、MACD指标图

// K线图的配置与工厂
val kChartConfig = KChartConfig()
val kChartFactory = KChartFactory(stockChart = stock_chart, childChartConfig = kChartConfig)

// 时间条图的配置与工厂
val timeBarConfig = TimeBarConfig()
val timeBarFactory = TimeBarFactory(stockChart = stock_chart, childChartConfig = timeBarConfig)

// MACD指标图的配置与工厂
val macdChartConfig = MacdChartConfig()
val macdChartFactory = MacdChartFactory(stockChart = stock_chart, childChartConfig = macdChartConfig)

// 将需要显示的子图的工厂加入全局配置
stockChartConfig.addChildCharts(kChartFactory, timeBarFactory, macdChartFactory)

5. 将K线数据传给全局配置

// 加载模拟数据
Data.loadDayData(this, 0) { kEntities: List<IKEntity> ->
    
    // 初始显示最后50条数据
    val pageSize = 50

    // 设置加载到的数据
    stockChartConfig.setKEntities(
        kEntities,
        showStartIndex = kEntities.size - pageSize,
        showEndIndex = kEntities.size - 1
    )

    // 通知更新K线图
    stock_chart.notifyChanged()
}

注意:任何配置的修改都需要调用StockChartnotifyChanged()方法去更新视图展示

使用进阶

详细请参考提供的示例(samples模块)

所有配置

全局配置StockChartConfig
字段 描述
kEntities K线数据
showStartIndex 初始显示区域的起始坐标
showEndIndex 初始显示区域的结束坐标
scrollAble 是否支持滑动
overScrollAble 是否支持"滑过头回弹"效果
overScrollDistance "滑过头回弹"最大距离
overScrollOnLoadMoreDistance "滑过头回弹"过程中触发加载更多需要的距离
scaleAble 是否支持双指缩放
scrollSmoothly 是否需要"平滑的"滑动。如果false,滑动时一个下标对应的内容要么全显示,要么不显示。
frictionScrollExceedLimit 超出滑动限制范围时拖动的"摩擦力"
scaleFactorMax 双指缩放最大缩放比例
scaleFactorMin 双指缩放最小缩放比例
showHighlightHorizontalLine 是否支持长按高亮横线
highlightHorizontalLineWidth 长按高亮横线宽度
highlightHorizontalLineColor 长按高亮横线颜色
showHighlightVerticalLine 是否支持长按高亮竖线
highlightVerticalLineWidth 长按高亮竖线宽度
highlightVerticalLineColor 长按高亮竖线颜色
riseColor 涨色值
downColor 跌色值
backgroundColor 背景色
gridHorizontalLineCount 背景网格横线数
gridVerticalLineCount 背景网格竖线数
gridLineColor 背景网格线条色
gridLineStrokeWidth 背景网格线条宽度
K线图配置KChartConfig
字段 描述
height 高度
marginTop 顶部外间距
marginBottom 底部外间距
onHighlightListener 长按回调
chartMainDisplayAreaPaddingTop 主数据显示区域的顶部内间距
chartMainDisplayAreaPaddingBottom 主数据显示区域的底部内间距
kChartType K线图类型
highlightLabelLeft 长按时高亮线左侧标签配置
highlightLabelTop 长按时高亮线顶部标签配置
highlightLabelRight 长按时高亮线右侧标签配置
highlightLabelBottom 长按时高亮线底部标签配置
lineChartColor 线形图的线条颜色
lineChartStrokeWidth 线形图的线条宽度
mountainChartColor 山峰图线条颜色
mountainChartStrokeWidth 山峰图的线条宽度
mountainChartLinearGradientColors 山峰图的封闭渐变色
candleChartLineStrokeWidth 蜡烛图的中间线宽度
hollowChartLineStrokeWidth 空心蜡烛图线条宽度
barChartLineStrokeWidth 美国线图(竹节图)线条宽度
costPrice 成本线价格
costPriceLineColor 成本线颜色
costPriceLineWidth 成本线宽度
indexStrokeWidth 指标线条宽度
barSpaceRatio 柱子之间的空间占比柱子宽度
index 需要展示的指标类型
indexColors 指标线的颜色
leftLabelConfig 左侧标签配置
rightLabelConfig 右侧标签配置
showAvgLine 是否显示分时均线。若需要显示,K线数据需带有分时均线价格。
avgLineColor 分时均线颜色
avgLineStrokeWidth 分时均线宽度
时间条图配置TimeBarConfig
字段 描述
height 高度
marginTop 顶部外间距
marginBottom 底部外间距
onHighlightListener 长按回调
chartMainDisplayAreaPaddingTop 主数据显示区域的顶部内间距
chartMainDisplayAreaPaddingBottom 主数据显示区域的底部内间距
backGroundColor 背景色
labelTextSize 标签文本大小
labelTextColor 标签文本色
highlightLabelTextSize 长按显示的标签文本大小
highlightLabelTextColor 长按显示的标签文本色
highlightLabelBgColor 长按显示的标签背景色
type 时间条样式
成交量图配置VolumeChartConfig
字段 描述
height 高度
marginTop 顶部外间距
marginBottom 底部外间距
onHighlightListener 长按回调
chartMainDisplayAreaPaddingTop 主数据显示区域的顶部内间距
chartMainDisplayAreaPaddingBottom 主数据显示区域的底部内间距
highlightLabelLeft 长按时高亮线左侧标签配置
highlightLabelRight 长按时高亮线右侧标签配置
barSpaceRatio 柱子之间的空间占比柱子宽度
volumeChartType 柱子样式
hollowChartLineStrokeWidth 柱子空心时的线条宽度
MACD指标图配置MacdChartConfig
字段 描述
height 高度
marginTop 顶部外间距
marginBottom 底部外间距
onHighlightListener 长按回调
chartMainDisplayAreaPaddingTop 主数据显示区域的顶部内间距
chartMainDisplayAreaPaddingBottom 主数据显示区域的底部内间距
highlightLabelLeft 长按时高亮线左侧标签配置
highlightLabelRight 长按时高亮线右侧标签配置
difLineColor dif线颜色
difLineStrokeWidth dif线宽度
deaLineColor dea线颜色
deaLineStrokeWidth dea线宽度
macdTextColor macd文字颜色
barSpaceRatio 柱子之间的空间占比柱子宽度
index 需要展示的指标配置
KDJ指标图配置KdjChartConfig
字段 描述
height 高度
marginTop 顶部外间距
marginBottom 底部外间距
onHighlightListener 长按回调
chartMainDisplayAreaPaddingTop 主数据显示区域的顶部内间距
chartMainDisplayAreaPaddingBottom 主数据显示区域的底部内间距
highlightLabelLeft 长按时高亮线左侧标签配置
highlightLabelRight 长按时高亮线右侧标签配置
kLineColor k线颜色
kLineStrokeWidth k线宽度
dLineColor d线颜色
dLineStrokeWidth d线宽度
jLineColor j线颜色
jLineStrokeWidth j线宽度
index 需要展示的指标配置
长按时高亮线的标签配置HighlightLabelConfig
字段 描述
bgColor 背景色
bgCorner 背景圆角
padding 内间距
textSize 文字大小
textColor 文字颜色
textFormat 显示的内容格式化
K线图标签配置LabelConfig
字段 描述
count 标签数
formatter 显示内容格式化
textSize 文字大小
textColor 文字颜色
horizontalMargin 水平外间距
marginTop 顶部外间距
marginBottom 底部外间距

如何自定义子图

三步走
  1. 提供子图的配置类,用于定义子图的各种配置,需要继承BaseChildChartConfig
  2. 提供子图的UI类,用于绘制UI细节,需要继承BaseChildChart
  3. 提供子图的工厂类,用于实例化子图,需要继承AbsChildChartFactory
示例
class CustomChartConfig(  
    height: Int = DEFAULT_CHILD_CHART_HEIGHT,  
  marginTop: Int = DEFAULT_CHILD_CHART_MARGIN_TOP,  
  marginBottom: Int = DEFAULT_CHILD_CHART_MARGIN_BOTTOM,  
  onHighlightListener: OnHighlightListener? = null,  
  chartMainDisplayAreaPaddingTop: Float = DEFAULT_CHART_MAIN_DISPLAY_AREA_PADDING_TOP,  
  chartMainDisplayAreaPaddingBottom: Float = DEFAULT_CHART_MAIN_DISPLAY_AREA_PADDING_BOTTOM,  
 var bigLabel: String? = null  
) : BaseChildChartConfig(  
    height,  
  marginTop,  
  marginBottom,  
  onHighlightListener,  
  chartMainDisplayAreaPaddingTop,  
  chartMainDisplayAreaPaddingBottom  
)
class CustomChart(
    stockChart: IStockChart,
    chartConfig: CustomChartConfig
) : BaseChildChart<CustomChartConfig>(stockChart, chartConfig) {
    
    override fun onKEntitiesChanged() {
        // 如果需要的话,在这里处理K先数据变化后要做的事  
    }

    override fun getYValueRange(startIndex: Int, endIndex: Int, result: FloatArray) {
        // 提供指定下标范围内[startIndex ~ endIndex],y轴逻辑坐标的范围值  
    }  

    override fun preDrawBackground(canvas: Canvas) {
        // ... 绘制细节 
    }

    override fun drawBackground(canvas: Canvas) {
        // ... 绘制细节  
    }

    override fun preDrawData(canvas: Canvas) {
        // ... 绘制细节
    }

    override fun drawData(canvas: Canvas) {
        // ... 绘制细节
    }

    override fun preDrawHighlight(canvas: Canvas) {
        // ... 绘制细节 
    }

    override fun drawHighlight(canvas: Canvas) {
        // ... 绘制细节 
    }

    override fun drawAddition(canvas: Canvas) {
        // ... 绘制细节 
    }
}
class CustomChartFactory(stockChart: IStockChart, childChartConfig: CustomChartConfig) :  
    AbsChildChartFactory<CustomChartConfig>(stockChart, childChartConfig) {  
    override fun createChart() = CustomChart(stockChart, childChartConfig)  
}
// 自定义子图的使用

// 自定义子图的配置与工厂
val customChartConfig = CustomChartConfig()
val customChartFactory = CustomChartFactory(stock_chart, customChartConfig)
// 添加子图
stockChartConfig.addChildCharts(customChartFactory)
// 更新UI
stock_chart.notifyChanged()
  • 详细请参考samples模块,里面有自定义子图的示例。

示例APK下载

stock_chart_apk

使用手机浏览器扫码下载安装,如需下载到本地请点击下载

反馈

感觉好用就点个Star呗~感激万分。 任何问题欢迎在Issues区提问,或者有更多需求请联系我。 我的邮箱:[email protected]

请作者喝杯咖啡呗

您的支持是我最大的动力! donate.jpg

Licenses

Copyright 2021 WangYiqian

Licensed under the Apache License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].