Вопрос

I'm puzzled...

I'm trying to create a serial amchart with multiple Y-axis, but I would like them to use the same X-axis. Amcharts.com has a demo (http://www.amcharts.com/demos/multiple-value-axes/)

I've put my output on JSfiddle for you to see: http://jsfiddle.net/2cMMF/3/ As you can see the the years are displayed twice on the X-axis,

This script I have copied, but I can seem to get it right. The only thing that is different is the chartData:

  function generateChartData() {
            var chartData = [];
            var xAxis;
            var yAxis;

            @for(j <- 0 until totalAmountForms){
                @for(i <- 0 until data.get(j).length) {
                yAxis = @data.get(j).get(i)
                xAxis = @label.get(j).get(i)
                @if(j==0){
                    chartData.push({
                        values1: yAxis,
                        categories: xAxis
                });
                }
                @if(j==1){
                    chartData.push({
                        values2: yAxis,
                        categories: xAxis
                });
                }
                @if(j==2){
                    chartData.push({
                        values3: yAxis,
                        categories: xAxis
                });
                }
                @if(j==3){
                    chartData.push({
                        values4: yAxis,
                        categories: xAxis
                });
                }
                @if(j==4){
                    chartData.push({
                        values5: yAxis,
                        categories: xAxis
                });
                }
            }
            }
            return chartData;  
            }

Any idea on what I might been doing wrong here? I've also tried to generate the xAxis once, but just get "undefined" in the graph X-axis. Here is where I give the xAxis to the graph:

"categoryField":"categories",
                "categoryAxis": {
                "parseDate": false,
                "axisColor": "#DADADA",
                "minorGridEnabled": true
            }

I'm using the Play Framework together with Scala (the code is valid, and compiles, but is not showing the graphs right).

Это было полезно?

Решение

Okey, guys!

The answer was to simply push the "values" to chartData together with "categories". See example below:

function generateChartData() {
            var chartData = [];
            var xAxis;
            var yAxis1;
            var yAxis2;
            var yAxis3;
            var yAxis4;
            var yAxis5;

                @if(totalAmountForms==1){
                    @for(i <- 0 until data.get(0).length) {
                        xAxis = @label.get(0).get(i)
                        yAxis1 = @data.get(0).get(i)

                    chartData.push({
                        values1: yAxis1,
                        categories: xAxis
                });
                    }
                }
                @if(totalAmountForms==2){
                    @for(i <- 0 until data.get(1).length) {
                        xAxis = @label.get(0).get(i)
                        yAxis1 = @data.get(0).get(i)
                        yAxis2 = @data.get(1).get(i)

                    chartData.push({
                        values1: yAxis1,
                        values2: yAxis2,
                        categories: xAxis
                });
                    }
                }
                @if(totalAmountForms==3){
                    @for(i <- 0 until data.get(2).length) {
                        xAxis = @label.get(0).get(i)
                        yAxis1 = @data.get(0).get(i)
                        yAxis2 = @data.get(1).get(i)
                        yAxis3 = @data.get(2).get(i)

                    chartData.push({
                        values1: yAxis1,
                        values2: yAxis2,
                        values3: yAxis3,
                        categories: xAxis
                });
                    }
                }
                @if(totalAmountForms==4){
                    @for(i <- 0 until data.get(3).length) {
                        xAxis = @label.get(0).get(i)
                        yAxis1 = @data.get(0).get(i)
                        yAxis2 = @data.get(1).get(i)
                        yAxis3 = @data.get(2).get(i)
                        yAxis4 = @data.get(3).get(i)

                    chartData.push({
                        values1: yAxis1,
                        values2: yAxis2,
                        values3: yAxis3,
                        values4: yAxis4,
                        categories: xAxis
                });
                    }
                }
                @if(totalAmountForms==5){
                    @for(i <- 0 until data.get(4).length) {
                        xAxis = @label.get(0).get(i)
                        yAxis1 = @data.get(0).get(i)
                        yAxis2 = @data.get(1).get(i)
                        yAxis3 = @data.get(2).get(i)
                        yAxis4 = @data.get(3).get(i)
                        yAxis5 = @data.get(4).get(i)

                    chartData.push({
                        values1: yAxis1,
                        values2: yAxis2,
                        values3: yAxis3,
                        values4: yAxis4,
                        values5: yAxis5,
                        categories: xAxis
                });
                    }
                }
            return chartData;  
            }

Not the best code I've written, but it works for now...

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top