1

I am trying to get an array of objects from an API endpoint inside of a mongo DB. The trouble I am having is what syntax to use to plug in that data, and then get the chart to display that data from the DB.

Here is my array in the mongo shell and the same shows up in ARC so I know my back-end logic is good, the problem is bring it to the view (on the chart).

The x-axis will display the "_id" (so the dates will show on the bottom), and the y-axis will display the "count".

Here is what I have inside of my controller.

vm.lineChartOptions = {
            chart: {
                type: 'cumulativeLineChart',
                height: 450,
                margin: {
                    top: 20,
                    right: 20,
                    bottom: 60,
                    left: 65
                },
                x: function (d) { return d._id; },
                y: function (d) { return d.count; },

                color: d3.scale.category10().range(),
                duration: 300,
                useInteractiveGuideline: true,
                clipVoronoi: false,

                xAxis: {
                    axisLabel: 'Reservations',
                    tickFormat: function (d) {
                        return d3.time.format('%m/%d/%y')(new Date(d))
                    },
                    showMaxMin: false,
                    staggerLabels: true,
                },

                yAxis: {
                    axisLabel: 'Non-reservations',
                    tickFormat: function (d) {
                        return d3.format('.2')(d);
                    },
                    axisLabelDistance: 20
                },
                xDomain: [vm.xMinValue, vm.xMaxValue],
                yDomain: [customerMetrics.count]
            }
        };
        vm.lineChartData = [
            {
                key: "Reservations",
                values: [[customerMetrics._id, customerMetrics.count]]
                ,
                mean: 250
            }
4
  • please include code / output directly in the question (as text) instead of linking to a image Commented Jun 14, 2017 at 19:27
  • @woelliJ I added the code. Commented Jun 14, 2017 at 20:25
  • Look here: stackoverflow.com/questions/12786686/… Commented Jun 14, 2017 at 21:00
  • Have you tried putting a debugger statement above vm.lineChartData and looking at the shape of [[customerMetrics._id, customerMetrics.count]]? That doesn't look right to me. Shouldn't it just be customerMetrics? It should be an array with this shape [{ _id: '...', count: 15 }] Commented Jun 15, 2017 at 1:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.