chartjs / chartjs-chart-financial

Chart.js module for charting financial securities
MIT License
743 stars 199 forks source link

How do i input the data for the candle stick? #29

Closed rashearth closed 6 years ago

rashearth commented 6 years ago

Hello. Its great that Chart.js now have a candle stick function! I would love to use this!

By the way, I have one question for candlestick chart. How do i input the data?

I think I need to input High, Low, Close, Open data, but i do not know how i could do this. Sorry for bothering, but could you kindly show me some simple samples for how i could input the data?

(The uploaded samples looks to be randomized data)

Thank you.

benmccann commented 6 years ago

Yes, the random data is generated here: https://github.com/chartjs/chartjs-chart-financial/blob/master/docs/utils.js

You need to create an object with o, h, l, c just like this random script does

rashearth commented 6 years ago

Thanks for your kind reply.

Usually for the charts.js, we need to input data below. Could you tell me how to input the data for the candlestick version? (How could I write it? Is it like o:105.31, h:105.67, l: 105.00, c:105.60 ?? I don't know the correct way to input data.)

var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
    type: 'candlestick',

       data: {
            labels: [

"2017.12.11",
"2017.12.12",

],
            datasets: [
                {
                    label: "Actual Data",
                    backgroundColor: "rgba(226,240,217,0.4)",
                    borderColor: "rgba(0,176,80,1)",
                    pointBackgroundColor: "rgba(0,176,80,1)",
                    pointBorderColor: "#fff",
                    pointHoverBackgroundColor: "#fff",
                    pointHoverBorderColor: "rgba(0,176,80,1)",
                    pointHitRadius: 10,
                    data: [

//"Could you give me some samples for how I could insert the data?"
**106.26,**
**106.29,**

]
                },
benmccann commented 6 years ago

data: [{o:105.31, h:105.67, l: 105.00, c:105.60}, {o:105.31, h:105.67, l: 105.00, c:105.60}]

rashearth commented 6 years ago

Thanks a lot!!