KDemo

Project Url: zhangliangzs/KDemo
Introduction: Android 开发专业 k 线图表组件,支持 JDK,MACD,MA,VOL 等指标,后续指标陆续更新
More: Author   ReportBugs   
Tags:

专业 k 线图表组件,支持 JDK,MACD,MA,VOL,BOLL,EMA 等指标,后续指标陆续更新

image

android studio 开发工具中: 第一步:在工程 build.gradle 中添加如下代码

allprojects { repositories { ... maven { url "https://jitpack.io" } } } 第二步:在 dependency,添加如下代码

dependencies { compile 'com.github.zhangliangzs:KDemo:1.0.0' }

项目应用: 在布局文件中添加组件:

activity 中找到控件: KView mMyChartsView = (KView) findViewById(R.id.kview);

最主要的是数据的显示,数据 mode 的封装,主要封装在 MarketChartData 中:结构如下:

public class MarketChartData { long time = 0; double openPrice = 0; double closePrice = 0; double lowPrice = 0; double highPrice = 0; double vol = 0;

public MarketChartData() {

}

public long getTime() {
    return time;
}

public String getTime2() {
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    return sdf.format(time*1000);
}
public String getTime3() {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return sdf.format(time*1000);
}
public String getTime4() {
    SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
    return sdf.format(time*1000);
}
public void setTime(long time) {
    this.time = time;
}

public double getOpenPrice() {
    return openPrice;
}

public void setOpenPrice(double openPrice) {
    this.openPrice = openPrice;
}

public double getClosePrice() {
    return closePrice;
}

public void setClosePrice(double closePrice) {
    this.closePrice = closePrice;
}

public double getLowPrice() {
    return lowPrice;
}

public void setLowPrice(double lowPrice) {
    this.lowPrice = lowPrice;
}

public double getHighPrice() {
    return highPrice;
}

public void setHighPrice(double highPrice) {
    this.highPrice = highPrice;
}

public double getVol() {
    return vol;
}
public void setVol(double vol) {
    this.vol = vol;
}

}

new 个数组装载 model 数据: private List marketChartDataLists = new ArrayList(); 你的 activity 界面请求 json 数据,封装在这个模型中,在代码中添加

  mMyChartsView.setOHLCData(marketChartDataLists);
  mMyChartsView.postInvalidate();

  就能将图表数据显示出来

  主要方法:
        mMyChartsView.setClose();//关闭指标
        mMyChartsView.setMACDShow();//显示 macd
        mMyChartsView.setKDJShow();//显示 kdj

网络接口封住了,以下是 json 格式的数组,可以写入本地,加载本地数据显示效果,数组数据 0-5 依次为:时间戳,最低价,最高价,开盘价,收盘价,成交量 对应设置好 MarketChartData 模型数据,就能显示 { "des": "", "isSuc": true, "datas": [ [ 1473538260000, 4158.18, 4158.18, 4157.17, 4157.25, 5.739 ], [ 1473538320000, 4157.16, 4157.19, 4157.16, 4157.16, 7.8891 ], [ 1473538380000, 4157.18, 4157.32, 4157.16, 4157.32, 4.385 ], [ 1473538440000, 4157.32, 4158, 4157.32, 4158, 6.5561 ], [ 1473538500000, 4158, 4159.8, 4157.82, 4159.55, 9.477 ], [ 1473538560000, 4159.35, 4159.35, 4158.5, 4158.95, 52.7311 ], [ 1473538620000, 4159.03, 4159.27, 4157.41, 4159.07, 17.998 ], [ 1473538680000, 4158.71, 4160.07, 4158.38, 4158.65, 13.6951 ], [ 1473538740000, 4158.7, 4158.99, 4158.45, 4158.97, 4.678 ], [ 1473538800000, 4158.53, 4158.99, 4158.49, 4158.74, 0.6871 ], [ 1473538860000, 4158.71, 4159, 4158.57, 4158.81, 2.355 ], [ 1473538920000, 4158.71, 4158.85, 4156.22, 4157.1, 5.54 ], [ 1473538980000, 4156.51, 4157.32, 4153.76, 4154.39, 31.248 ], [ 1473539040000, 4154.37, 4155.33, 4153.98, 4155.33, 15.41 ], [ 1473539100000, 4155.22, 4157.92, 4154.92, 4157.4, 25.193 ], [ 1473539160000, 4157.61, 4157.89, 4156.73, 4157.67, 10.5521 ], [ 1473539220000, 4157.44, 4158.47, 4156.57, 4158.2, 21.6611 ], [ 1473539280000, 4158.19, 4158.19, 4158.04, 4158.04, 2.444 ], [ 1473539340000, 4158.08, 4158.75, 4158.04, 4158.15, 8.4531 ], [ 1473539400000, 4158.06, 4158.68, 4156.41, 4156.41, 0.4791 ], [ 1473539460000, 4156.24, 4156.55, 4155.94, 4155.95, 1.135 ], [ 1473539520000, 4155.96, 4156.31, 4155.34, 4155.34, 2.0731 ], [ 1473539580000, 4155.34, 4156.59, 4155.34, 4156.44, 18.49 ], [ 1473539640000, 4156.45, 4156.45, 4156.14, 4156.14, 1.9851 ], [ 1473539700000, 4156.14, 4156.14, 4156.08, 4156.09, 6.399 ], [ 1473539760000, 4156.09, 4156.09, 4156.01, 4156.01, 7.101 ], [ 1473539820000, 4156.01, 4156.01, 4155.65, 4155.65, 4.64 ], [ 1473539880000, 4155.65, 4156.55, 4155.65, 4156.55, 3.703 ], [ 1473539940000, 4156.44, 4156.44, 4155.02, 4155.71, 14.3431 ], [ 1473540000000, 4155.75, 4155.77, 4155.44, 4155.62, 17.19 ], [ 1473540060000, 4156.07, 4156.12, 4156, 4156, 5.018 ], [ 1473540120000, 4156.11, 4156.12, 4156.08, 4156.11, 0.4511 ], [ 1473540180000, 4156.08, 4156.12, 4156.08, 4156.11, 1.027 ], [ 1473540240000, 4156.08, 4156.11, 4155.03, 4155.03, 0.3991 ], [ 1473540300000, 4155.95, 4155.95, 4154, 4155.34, 0.6311 ], [ 1473540360000, 4155.46, 4156.42, 4155.24, 4156.41, 0.2121 ], [ 1473540420000, 4156.41, 4156.42, 4156.41, 4156.41, 1.365 ], [ 1473540480000, 4156.42, 4156.42, 4156.41, 4156.42, 2.4401 ], [ 1473540540000, 4156.41, 4156.42, 4155.54, 4156.37, 3.51 ], [ 1473540600000, 4155.3, 4156.58, 4155.26, 4155.77, 6.637 ], [ 1473540660000, 4156.16, 4156.82, 4154.68, 4155.89, 7.038 ], [ 1473540720000, 4155.35, 4155.97, 4154.88, 4155.11, 15.637 ], [ 1473540780000, 4155.1, 4155.13, 4154.83, 4155.12, 6.232 ], [ 1473540840000, 4155.12, 4155.97, 4155.12, 4155.89, 3.875 ], [ 1473540900000, 4156.4, 4158.42, 4156.4, 4157.96, 35.633 ], [ 1473540960000, 4158.09, 4158.09, 4157.92, 4157.93, 23.597 ], [ 1473541020000, 4157.93, 4157.99, 4157.28, 4157.99, 9.062 ], [ 1473541080000, 4158.89, 4159, 4157.71, 4159, 3.276 ], [ 1473541140000, 4158.59, 4159, 4158.35, 4158.65, 16.5481 ], [ 1473541200000, 4158.11, 4159, 4156.53, 4156.53, 3.702 ], [ 1473541260000, 4156.53, 4158.5, 4156.43, 4157.5, 26.321 ], [ 1473541320000, 4157.5, 4161.27, 4157.5, 4159.33, 28.8481 ], [ 1473541380000, 4159.2, 4160.07, 4158.26, 4158.91, 6.784 ], [ 1473541440000, 4159.11, 4159.11, 4156.92, 4157.79, 4.337 ], [ 1473541500000, 4157.8, 4158.5, 4157.37, 4157.79, 4.815 ], [ 1473541560000, 4158.5, 4158.5, 4157.34, 4157.59, 9.8121 ], [ 1473541620000, 4157.59, 4157.59, 4156.68, 4156.68, 20.271 ], [ 1473541680000, 4156.81, 4157.59, 4156.5, 4157.5, 3.901 ], [ 1473541740000, 4157.4, 4160.92, 4156.77, 4160.92, 5.362 ], [ 1473541800000, 4161.66, 4161.81, 4157.54, 4158.97, 32.3971 ], [ 1473541860000, 4158.97, 4158.99, 4158.19, 4158.89, 12.214 ], [ 1473541920000, 4158.61, 4160.13, 4158.39, 4159.96, 5.002 ], [ 1473541980000, 4159.96, 4160.91, 4157.36, 4158.59, 33.515 ], [ 1473542040000, 4158.57, 4158.57, 4156.72, 4157.1, 18.4281 ], [ 1473542100000, 4157.11, 4157.7, 4157.04, 4157.67, 13.911 ], [ 1473542160000, 4157.67, 4157.7, 4156.73, 4157.31, 8.591 ], [ 1473542220000, 4157.48, 4157.54, 4157.14, 4157.37, 2.638 ], [ 1473542280000, 4157.38, 4157.7, 4157.14, 4157.7, 9.021 ], [ 1473542340000, 4157.57, 4157.82, 4156.72, 4156.72, 33.336 ], [ 1473542400000, 4156.72, 4156.72, 4155.84, 4156.51, 40.0631 ], [ 1473542460000, 4156.42, 4157.69, 4155.8, 4156.96, 10.791 ], [ 1473542520000, 4157.39, 4157.7, 4156.82, 4157.36, 7.872 ], [ 1473542580000, 4157.55, 4157.71, 4157.49, 4157.71, 4.04 ], [ 1473542640000, 4157.59, 4157.71, 4156.71, 4157.71, 21.199 ], [ 1473542700000, 4157.61, 4157.81, 4157.49, 4157.81, 39.588 ], [ 1473542760000, 4157.81, 4158.21, 4157.78, 4158.21, 0.3501 ], [ 1473542820000, 4158.22, 4158.23, 4158.22, 4158.22, 15.46 ], [ 1473542880000, 4158.23, 4158.5, 4157.76, 4158.31, 18.359 ], [ 1473542940000, 4158.42, 4158.43, 4157.85, 4158.18, 0.2671 ], [ 1473543000000, 4158.47, 4158.89, 4157.91, 4158.21, 3.733 ], [ 1473543060000, 4157.94, 4158.77, 4157.94, 4158.33, 0.6351 ], [ 1473543120000, 4158.45, 4158.66, 4158.32, 4158.66, 0.8491 ], [ 1473543180000, 4158.57, 4158.67, 4158.3, 4158.3, 2.843 ], [ 1473543240000, 4158.19, 4158.75, 4156.14, 4156.15, 3.546 ], [ 1473543300000, 4156.14, 4157.15, 4154.31, 4154.48, 9.172 ], [ 1473543360000, 4153.66, 4153.78, 4152.85, 4152.86, 20.8951 ], [ 1473543420000, 4152.86, 4153.42, 4152.7, 4153.33, 8.639 ], [ 1473543480000, 4153.36, 4153.47, 4153.3, 4153.42, 6.3191 ], [ 1473543540000, 4153.42, 4154, 4153.4, 4154, 7.728 ], [ 1473543600000, 4153.84, 4154, 4152.78, 4154, 13.8521 ], [ 1473543660000, 4154, 4154, 4152.76, 4154, 10.4401 ], [ 1473543720000, 4153.99, 4154, 4151.78, 4153.99, 4.953 ], [ 1473543780000, 4153.98, 4153.98, 4152.26, 4153.15, 5.3241 ], [ 1473543840000, 4153.22, 4153.28, 4150, 4152.39, 15.197 ], [ 1473543900000, 4151.94, 4152.24, 4150.73, 4150.99, 16.9411 ], [ 1473543960000, 4150.99, 4152.07, 4149.77, 4151.92, 18.559 ], [ 1473544020000, 4150.63, 4152.3, 4150.63, 4151, 17.8541 ], [ 1473544080000, 4151.01, 4153.02, 4151, 4153.02, 6.375 ], [ 1473544140000, 4153.02, 4153.02, 4152.7, 4153.02, 4.223 ], [ 1473544200000, 4152.88, 4153.02, 4152.43, 4152.52, 2.075 ], [ 1473544260000, 4153.02, 4154.12, 4152.53, 4154.12, 5.406 ] }

如果有疑问请加 QQ:1179980507,一起完善和做好这个控件

IOS 版地址: https://github.com/zhiquan911/CHKLineChart

效果如下图: image

Apps
About Me
Google+: Trinea trinea
GitHub: Trinea