-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1551 from tradingview/add-more-examples-and-demos
Move demo examples from JSfiddle onto documentation site
- Loading branch information
Showing
32 changed files
with
3,715 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
globals: { | ||
document: false, | ||
createChart: false, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// remove-start | ||
// Lightweight Charts™ Example: Compare multiple series | ||
// https://tradingview.github.io/lightweight-charts/tutorials/how_to/compare-multiple-series | ||
|
||
// remove-end | ||
// hide-start | ||
let randomFactor = 25 + Math.random() * 25; | ||
const samplePoint = i => | ||
i * | ||
(0.5 + | ||
Math.sin(i / 10) * 0.2 + | ||
Math.sin(i / 20) * 0.4 + | ||
Math.sin(i / randomFactor) * 0.8 + | ||
Math.sin(i / 500) * 0.5) + | ||
200; | ||
|
||
function generateLineData(numberOfPoints = 500) { | ||
randomFactor = 25 + Math.random() * 25; | ||
const res = []; | ||
const date = new Date(Date.UTC(2018, 0, 1, 12, 0, 0, 0)); | ||
for (let i = 0; i < numberOfPoints; ++i) { | ||
const time = (date.getTime() / 1000); | ||
const value = samplePoint(i); | ||
res.push({ | ||
time, | ||
value, | ||
}); | ||
|
||
date.setUTCDate(date.getUTCDate() + 1); | ||
} | ||
|
||
return res; | ||
} | ||
// hide-end | ||
const chartOptions = { | ||
layout: { | ||
textColor: CHART_TEXT_COLOR, | ||
background: { type: 'solid', color: CHART_BACKGROUND_COLOR }, | ||
}, | ||
}; | ||
// remove-line | ||
/** @type {import('lightweight-charts').IChartApi} */ | ||
const chart = createChart(document.getElementById('container'), chartOptions); | ||
|
||
const lineSeriesOne = chart.addLineSeries({ color: LINE_LINE_COLOR }); | ||
const lineSeriesTwo = chart.addLineSeries({ color: LINE_LINE2_COLOR }); | ||
const lineSeriesThree = chart.addLineSeries({ color: LINE_LINE3_COLOR }); | ||
|
||
const lineSeriesOneData = generateLineData(); | ||
const lineSeriesTwoData = generateLineData(); | ||
const lineSeriesThreeData = generateLineData(); | ||
|
||
lineSeriesOne.setData(lineSeriesOneData); | ||
lineSeriesTwo.setData(lineSeriesTwoData); | ||
lineSeriesThree.setData(lineSeriesThreeData); | ||
|
||
chart.timeScale().fitContent(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
title: Compare multiple series | ||
sidebar_label: Compare multiple series | ||
description: | ||
An example of how to compare multiple series on a single price scale | ||
pagination_prev: null | ||
pagination_next: null | ||
keywords: | ||
- compare | ||
- series | ||
--- | ||
|
||
This Multi-Series Comparison Example illustrates how an assortment of data | ||
series can be integrated into a single chart for comparisons. Simply use the | ||
charting API to create multiple series (such as `addLineSeries`). | ||
|
||
If you would like an unique price scales for each individual series, | ||
particularly when dealing with data series with divergent value ranges, then | ||
take a look at the [Two Price Scales Example](../how_to/two-price-scales.mdx). | ||
|
||
import UsageGuidePartial from '../_usage-guide-partial.mdx'; | ||
import CodeBlock from '@theme/CodeBlock'; | ||
import code from '!!raw-loader!./compare-multiple-series.js'; | ||
|
||
<CodeBlock | ||
replaceThemeConstants | ||
chart | ||
className="language-js" | ||
hideableCode | ||
chartOnTop | ||
codeUsage={<UsageGuidePartial />} | ||
> | ||
{code} | ||
</CodeBlock> |
Oops, something went wrong.