A demonstration project showcasing a professional trading chart implementation using Svelte and KLineCharts. This project serves as an example of how to integrate the ChartPro library into a Svelte application.
Clone the repository:
git clone https://github.com/wku/svelte-trading-chart.git
cd svelte-trading-chart
Install dependencies:
npm install
Start the development server:
npm run dev
Open your browser and navigate to http://localhost:5173
src/
āāā lib/
ā āāā chart-pro/ # ChartPro Library
ā āāā chart/ # Core chart component
ā āāā components/ # UI components
ā ā āāā chart-toolbar/ # Main toolbar
ā ā āāā drawing-tools/ # Drawing instruments
ā ā āāā indicators/ # Technical indicators
ā ā āāā modals/ # Settings and dialogs
ā āāā core/ # Core system
ā ā āāā datafeed.js # Data provider interface
ā ā āāā extensions.js # Chart extensions
ā ā āāā types.js # Type definitions
ā āāā stores/ # Svelte stores
ā ā āāā chartStore.js # Chart state management
ā ā āāā settingsStore.js# Settings management
ā āāā utils/ # Utilities
ā ā āāā constants.js # Application constants
ā ā āāā i18n.js # Internationalization
ā āāā index.js # Library entry point
āāā App.svelte # Main application component
āāā main.js # Application entry point
āāā app.css # Global styles
This demo showcases a modular Svelte architecture with:
<script>
import { ChartPro, DefaultDatafeed } from './lib/chart-pro';
const datafeed = new DefaultDatafeed();
</script>
<ChartPro {datafeed} />
<script>
import {
ChartPro,
DefaultDatafeed,
createSymbolInfo,
createPeriod,
SymbolType,
PeriodTimespan
} from './lib/chart-pro';
const datafeed = new DefaultDatafeed();
const symbol = createSymbolInfo('BTCUSDT', {
name: 'Bitcoin / Tether',
exchange: 'Binance',
type: SymbolType.CRYPTO
});
const period = createPeriod(15, PeriodTimespan.MINUTE, '15m');
</script>
<ChartPro
{datafeed}
{symbol}
{period}
theme="dark"
showToolbar={true}
showDrawingTools={true}
showIndicators={true}
/>
// Create your own datafeed implementation
class CustomDatafeed {
async getKLineData(symbol, period, from, to) {
// Fetch data from your API
const response = await fetch(`/api/chart-data/${symbol}`);
return response.json();
}
subscribe(symbol, period, callback) {
// Implement real-time data subscription
const ws = new WebSocket(`ws://your-api.com/ws/${symbol}`);
ws.onmessage = (event) => callback(JSON.parse(event.data));
}
}
Main chart component with full trading functionality
The demo uses KLineCharts 9.8.10 as the core charting engine and provides:
# Development server
npm run dev
# Production build
npm run build
# Preview production build
npm run preview
# Type checking
npm run check
# Linting
npm run lint
npm run build
The built files will be in the dist/
directory, ready for deployment.
This demo is perfect for:
Fully responsive design with touch-friendly controls for mobile trading.
{
"klinecharts": "^9.8.10"
}
The project uses minimal dependencies to keep it lightweight and fast.
git checkout -b feature/amazing-feature
)git commit -m 'Add amazing feature'
)git push origin feature/amazing-feature
)This project is licensed under the MIT License - see the LICENSE file for details.
/src/lib/chart-pro/README.md
for library documentationMade with ā¤ļø using Svelte + KLineCharts
This demo showcases the power of modern web technologies for building professional financial applications.