Home forums Chart Support Dynamic Data charts and events

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #29356

    I am attempting to create a game of this sort – https://www.bloomberg.com/features/2015-stock-chart-trading-game/

    I need to generate a dynamic charts for which I am thinking of this https://canvasjs.com/html5-javascript-dynamic-chart/.

    My question is how can i record data point values whenever mouse button is click down(buy) and up(sell).

    Whenever mouse is clicked down/up record the data point at the right end of the chart window.
    Down and Up is one complete trade/cycle of trade (for game purposes) – I have keep track of buy/sell data points and calculate the points/profits made in that chart replay.

    #29379

    @jamescho,

    You can achieve the above requirements by attaching mousedown and mouseup events to the chart container as shown in this JSFiddle.


    Shashi Ranjan
    Team CanvasJS

    #29410

    Thanks, your answer addresses my question.

    #29481

    @Shashi Ranjan

    Thanks helping with event recording.

    I have another followup questions –
    How can I restrict it to show only the latest 100 range of values and MAX value i.e stop the chart rendering at max nth value?
    Is there a way to pull the data from a DB?

    I looked at this, but this looks to be a static onetime rendering of values from DB

    Render Data from Database

    #29489

    @jamescho,

    You can use shift method to display only the latest 100 dataPoints in the chart. Please take a look at this updated JSFiddle for the same.


    Shashi Ranjan
    Team CanvasJS

    #29550

    @shashiranjan – thanks, but now the “Profit/Loss” calculations freeze after 100th value (datalength), wondering if the chart container boundaries are affected by use of shift

    #29574

    @jamescho,

    Please take a look at this updated JSFiddle.


    Shashi Ranjan
    Team CanvasJS

    #29674

    @shashiranjan – thanks, its working now.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.