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

Add Scatter plot to stock chart #1591

Closed
shishima123 opened this issue Jun 28, 2024 · 4 comments
Closed

Add Scatter plot to stock chart #1591

shishima123 opened this issue Jun 28, 2024 · 4 comments

Comments

@shishima123
Copy link

Hello

When I try to add Graphics to the stock chart, it works. However, when zooming in on the chart, the lines outside the display area do not disappear; they are visible on both the left and right edges.

This demo works well, but it seems to have an issue with the stock chart.

Amcharts Demo

My JSFiddle

Additionally, is there a way to get the column width? I want the width of drawRect to be the same as the column width. Currently, it does not change when zooming in.

@tranmanhhungdn1201
Copy link

I got the same..hic

@zeroin
Copy link
Collaborator

zeroin commented Jun 28, 2024

Here is how I'd do it:

var canvasBullets = heatmapSeries.children.push(am5.Graphics.new(root, {}))
canvasBullets.set('draw', (display) => {

  var baseDuration = dateAxis.baseDuration();
  var position0 = dateAxis.valueToPosition(0);
  var position1 = dateAxis.valueToPosition(baseDuration);
  var cellWidth = dateAxis.get("renderer").positionToCoordinate(position1) - dateAxis.get("renderer").positionToCoordinate(position0);  

  // loop through all data items  
  
  for(let i = heatmapSeries.startIndex(); i < heatmapSeries.endIndex(); i++) {
    
    // set fill style from data context    
    var dataItem = heatmapSeries.dataItems[i];
    var dataContext = dataItem.dataContext
    if (dataContext) {
      const point = dataItem.get('point')
      if (point) {
        display.beginPath()
        display.beginFill(dataContext.strokeSettings.fill, dataContext.strokeSettings.fillOpacity)
        display.drawRect(point.x + cellWidth / 2, point.y, cellWidth, 1)
        display.endFill()
      }
    }
  }
})

I loop only through data items which are visible, as we do not calculate points of other items.

@shishima123
Copy link
Author

Thank you
You saved my day

Copy link

This issue is stale because it has been open 30 days with no activity. It will be closed in 5 days unless a new comment is added.

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

No branches or pull requests

4 participants