0

I'm new to HTML, Angular 2, and JavaScript so I'm not sure if this is possible. I'm using ng2-charts (which is derived from Chart.js) to create a linechart. Here's a snippet of my HTML:

<div class="col-md-6">
    <base-chart id="rLineChart" class="chart"
        [datasets]="rChartData"
        [labels]="rChartLabels"
        [colors]="rChartColours"
        [legend]="rChartLegend"
        [chartType]="rChartType"
        (chartHover)="chartHovered($event)"
        (chartClick)="chartClicked($event)">
    </base-chart>
</div>

As you can see, I've given the base-chart object the id "rLineChart". I want to get this chart object in an accompanying JavaScript file. I've tried using

var myChart = document.getElementById("rLineChart");

but that returns an HTMLElement, not the actual chart. Does anyone know how to go about retrieving the actual object? My ultimate goal is to retrieve the x y values of my chart (since ng2-charts doesn't seem to have a straightforward way of doing that). I've seen a function called getPointsAtEvent which seems like it may return point data, but I need the chart object in order to use it.

EDIT: Here's an image of my generated chart: enter image description here

Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299
Roka545
  • 3,404
  • 20
  • 62
  • 106
  • What are you trying to retrieve from the chart? Or what are you trying to do with the chart object? – Pedro Estrada Jun 03 '16 at 21:19
  • I'm trying to get the x and y values. I've added a picture of the chart to the original post. So I would like to get 0, 0.1, 0.2....1.0 for the y values and FAD 4, FAD 5....FAD 7 for the x values. – Roka545 Jun 03 '16 at 21:26
  • Try looking at this http://www.chartjs.org/docs/ and this http://stackoverflow.com/questions/17354163/dynamically-update-values-of-a-chartjs-chart – Pedro Estrada Jun 03 '16 at 21:42

0 Answers0