score:2

chart js allows an array of pointstyles to be supplied instead of just 1. it also allows images to be supplied in place of a preset pointer style.

var image = document.getelementbyid('source');
var options = {
  type: 'line',
  data: {
    labels: ["red", "blue", "yellow", "green", "purple", "orange"],
    datasets: [{
        label: '# of votes',
        data: [12, -19, 3, 5, 2, 3],
        borderwidth: 1,
        pointstyle: ['triangle', image, 'triangle', 'triangle', 'triangle', 'triangle'],
        pointradius: '10',
        pointbackgroundcolor: 'red'
      },

    ],
    pointstyle: 'triangle'
  },
  options: {
    scales: {
      yaxes: [{
        ticks: {
          reverse: false
        }
      }]
    }
  }
}

var ctx = document.getelementbyid('chartjscontainer').getcontext('2d');
new chart(ctx, options);
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.3.0/chart.js"></script>
<canvas id="chartjscontainer" width="600" height="400"></canvas>
<div style="display:none;">
  <img id="source" src="https://image.flaticon.com/icons/png/128/25/25224.png">
</div>

to then make this dynamic you could map the data in the datset to produce the pointerstyle array

let pointerstyles = [12,-19,2,3,4].map(value=>{
 return value >=0 ? 'triangle' : 'other-triangle'
});

console.log(pointerstyles);


Related Query

More Query from same tag