Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Candlestick and Crosshair plugin not working #93

Open
jaredgibb opened this issue Mar 4, 2021 · 1 comment
Open

Candlestick and Crosshair plugin not working #93

jaredgibb opened this issue Mar 4, 2021 · 1 comment

Comments

@jaredgibb
Copy link

jaredgibb commented Mar 4, 2021

I have installed the crosshair plugin and am using chartJS 3.0 to take advantage of the candlestick charts but the crosshair does not appear. are these things compatible together? my data appear. the crosshair does not

the tags i am using

	<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
		<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://dd7tel2830j4w.cloudfront.net/f1614793727236x392906938665549250/chartjs-chart-financial.js"></script>
<script scr="https://cdn.jsdelivr.net/npm/chartjs-plugin-crosshair"></script>

and the chart code which also works

 var divID = "chartContainer" + properties.chartid
  var chartID = "myChart" + properties.chartid
  instance.canvas.append('<div id="' + divID + '"></div>')
  document.getElementById(divID).innerHTML = '&nbsp;';
  document.getElementById(divID).innerHTML = '<canvas id=' + chartID + ' width="' + properties.bubble.width() + '" height="' + properties.bubble.height() + '"></canvas>';







  var ctx = document.getElementById(chartID).getContext('2d');
  var chart = new Chart(ctx, {
    type: 'candlestick',
    data: {
      datasets: [{
        label: 'CHRT - Chart.js Corporation',
        data: getData()
      }]
    },
    options: {
      scales: {
        y: {
          min: 0,
          max: 500
        }
      },
      tooltips: {
        mode: "interpolate",
        intersect: false
      },
      plugins: {
        crosshair: {
          line: {
            color: '#F66', // crosshair line color
            width: 3, // crosshair line width
            dashPattern: [5, 5] // crosshair line dash pattern
          },
          sync: {
            enabled: true, // enable trace line syncing with other charts
            group: 1, // chart group
            suppressTooltips: false // suppress tooltips when showing a synced tracer
          },
          zoom: {
            enabled: true, // enable zooming
            zoomboxBackgroundColor: 'rgba(66,133,244,0.2)', // background color of zoom box 
            zoomboxBorderColor: '#48F', // border color of zoom box
            zoomButtonText: 'Reset Zoom', // reset zoom button text
            zoomButtonClass: 'reset-zoom', // reset zoom button class
          },
          callbacks: {
            beforeZoom: function(start, end) { // called before zoom, return false to prevent zoom
              return true;
            },
            afterZoom: function(start, end) { // called after zoom
            }
          }
        }
      }
    }
  });

    
    
    
    
    
    
    

  function getData() {
    var dates = properties.time.get(0, properties.time.length())
    var opens = properties.open.get(0, properties.open.length())
    var highs = properties.high.get(0, properties.high.length())
    var lows = properties.low.get(0, properties.low.length())
    var closes = properties.close.get(0, properties.close.length())

    let data = []

    for (i = 0; i < dates.length; i++) {
      data.push({
        t: dates[i].valueOf(),
        o: opens[i],
        h: highs[i],
        l: lows[i],
        c: closes[i]
      })
    }

    console.log(data)

    return data
  }

  chart.update()


@firebird631
Copy link

It need x for time and not t in data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants