Skip to content

Commit

Permalink
feat: klinecharts v9.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
liihuu committed Feb 16, 2023
1 parent 824f890 commit 6e1a681
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 34 deletions.
14 changes: 7 additions & 7 deletions ng-sample/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ng-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@angular/platform-browser": "^15.1.0",
"@angular/platform-browser-dynamic": "^15.1.0",
"@angular/router": "^15.1.0",
"klinecharts": "^9.0.0",
"klinecharts": "^9.0.1",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.12.0"
Expand Down
25 changes: 13 additions & 12 deletions ng-sample/src/app/components/tooltip.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, AfterViewInit, OnDestroy } from '@angular/core';
import { init, dispose, Chart, Nullable, KLineData, TooltipShowRule, TooltipShowType } from 'klinecharts';
import { init, dispose, Chart, Nullable, CandleTooltipCustomCallbackData, TooltipShowRule, TooltipShowType } from 'klinecharts';

import generatedDataList from '../generatedDataList';

Expand Down Expand Up @@ -32,21 +32,22 @@ export class TooltipComponent implements AfterViewInit, OnDestroy {
tooltip: {
showType: candleShowType as TooltipShowType,
showRule: candleShowRule as TooltipShowRule,
custom: function (kLineData: KLineData) {
const change =
((kLineData.close - kLineData.open) / kLineData.open) * 100;
custom: (data: CandleTooltipCustomCallbackData) => {
const { prev, current } = data
const prevClose = (prev?.close ?? current.open)
const change = (current.close - prevClose) / prevClose * 100
return [
{ title: "open", value: kLineData.open.toFixed(2) },
{ title: "close", value: kLineData.close.toFixed(2) },
{ title: 'open', value: current.open.toFixed(2) },
{ title: 'close', value: current.close.toFixed(2) },
{
title: "Change: ",
title: 'Change: ',
value: {
text: `${change.toFixed(2)}%`,
color: change < 0 ? "#EF5350" : "#26A69A",
},
},
];
},
color: change < 0 ? '#EF5350' : '#26A69A'
}
}
]
}
}
},
technicalIndicator: {
Expand Down
2 changes: 1 addition & 1 deletion react-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@types/node": "^16.18.11",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.10",
"klinecharts": "^9.0.0",
"klinecharts": "^9.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
Expand Down
6 changes: 4 additions & 2 deletions react-sample/src/chart/ChartType.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useRef } from 'react'
import { init, dispose, Chart, CandleType, } from 'klinecharts'
import { init, dispose, Chart, CandleType, LineType } from 'klinecharts'
import generatedDataList from '../generatedDataList'
import Layout from '../Layout'

Expand All @@ -16,7 +16,9 @@ export default function ChartType () {
const chart = useRef<Chart | null>()

useEffect(() => {
chart.current = init('real-time-k-line')
chart.current = init('real-time-k-line', {
styles: { grid: { horizontal: { style: LineType.Dashed } } }
})
chart.current?.applyNewData(generatedDataList())
return () => {
dispose('real-time-k-line')
Expand Down
12 changes: 7 additions & 5 deletions react-sample/src/chart/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useRef, useState, useEffect } from 'react'
import { init, dispose, Chart, KLineData, TooltipShowRule, TooltipShowType } from 'klinecharts'
import { init, dispose, Chart, TooltipShowRule, TooltipShowType, CandleTooltipCustomCallbackData } from 'klinecharts'
import generatedDataList from '../generatedDataList'
import Layout from '../Layout'

Expand All @@ -9,11 +9,13 @@ function getTooltipOptions (candleShowType: TooltipShowType, candleShowRule: Too
tooltip: {
showType: candleShowType,
showRule: candleShowRule,
custom: (kLineData: KLineData) => {
const change = (kLineData.close - kLineData.open) / kLineData.open * 100
custom: (data: CandleTooltipCustomCallbackData) => {
const { prev, current } = data
const prevClose = (prev?.close ?? current.open)
const change = (current.close - prevClose) / prevClose * 100
return [
{ title: 'open', value: kLineData.open.toFixed(2) },
{ title: 'close', value: kLineData.close.toFixed(2) },
{ title: 'open', value: current.open.toFixed(2) },
{ title: 'close', value: current.close.toFixed(2) },
{
title: 'Change: ',
value: {
Expand Down
2 changes: 1 addition & 1 deletion vue-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore"
},
"dependencies": {
"klinecharts": "^9.0.0",
"klinecharts": "^9.0.1",
"vue": "^3.2.45"
},
"devDependencies": {
Expand Down
11 changes: 6 additions & 5 deletions vue-sample/src/chart/Tooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ function getTooltipOptions(candleShowType, candleShowRule, indicatorShowRule) {
tooltip: {
showType: candleShowType,
showRule: candleShowRule,
custom: function (kLineData) {
const change =
((kLineData.close - kLineData.open) / kLineData.open) * 100;
custom: (data) => {
const { prev, current } = data;
const prevClose = prev?.close ?? current.open;
const change = ((current.close - prevClose) / prevClose) * 100;
return [
{ title: "open", value: kLineData.open.toFixed(2) },
{ title: "close", value: kLineData.close.toFixed(2) },
{ title: "open", value: current.open.toFixed(2) },
{ title: "close", value: current.close.toFixed(2) },
{
title: "Change: ",
value: {
Expand Down

0 comments on commit 6e1a681

Please sign in to comment.