Фильтрация столбцов, которых нет в диаграмме GOOGLE CHART - PullRequest
0 голосов
/ 04 декабря 2018

Я не уверен, будет ли это иметь смысл или это возможно.У меня есть диаграмма, в которой столбцы ниже

feis, танцоры не помещены, всплывающая подсказка, танцоры размещены, всплывающая подсказка, размещение, всплывающая подсказка.

, поэтому у меня есть 4 столбца, не включая подсказки.Но я хочу 2 дополнительных столбца только для фильтрации.Он не должен быть видимым или влиять на график в любом случае.Я хочу включить диапазон дат и фильтр столбцов.

Я попытался просто добавить столбцы, а затем скрыть их с помощью setview, но тогда диаграмма не будет рисоваться.

вот мой код без добавлениядополнительные столбцы

function comboChart(){
            var data = google.visualization.arrayToDataTable([
                ['feis', 'Dancers Not Placed', {type: 'string', role: 'tooltip'}, 'Dancers Placed', {type: 'string', role: 'tooltip'}, 'Placement', {type: 'string', role: 'tooltip'}],
                 ['Garden State Feis - 01-05-2014', -18, 'Total Dancers Not Placed: 18', 22, 'Total Dancers Placed: 22',  20, 'Lace\'s Placement: 20th Place'],['GEM CITY FEIS - 02-14-2018', -42, 'Total Dancers Not Placed: 42', 38, 'Total Dancers Placed: 38', - 1, 'Lace\'s Placement: 1st place'],['Broesler Feis - 07-09-2018', -15, 'Total Dancers Not Placed: 15', 15, 'Total Dancers Placed: 15',  1, 'Lace\'s Placement: 1st place'],['GEM CITY FEIS - 08-21-2018', -21, 'Total Dancers Not Placed: 21', 26, 'Total Dancers Placed: 26', - 2, 'Lace\'s Placement: 2nd place'],['Garden State Feis - 12-01-2018', -48, 'Total Dancers Not Placed: 48', 12, 'Total Dancers Placed: 12', - 15, 'Lace\'s Placement: 15th Place'],                    
            ]);

            // Create a dashboard.
    var dashboard = new google.visualization.Dashboard(
        document.getElementById('dashboard_div'));

    // Create a search filter, passing some options
    var searchfilter = new google.visualization.ControlWrapper({
      'controlType': 'StringFilter',
      'containerId': 'filter_div',
      'options': {
        'filterColumnLabel': 'feis',
        'ui': {
            label: 'Filter by feis'
        },
        'matchType':  'any'
      }
    });


             // Create a combo chart, passing some options
    var barChart = new google.visualization.ChartWrapper({
      'chartType': 'ComboChart',
      'containerId': 'combo_chart',
      'options': {
        tooltip: {isHtml: true},
                legend:'none',
                chartArea: {
                    height: '100%',
                    width: '100%',
                    top: 16,
                    right: 16,
                    bottom: 60,
                    left: 60
                },

                colors: ['#03a9f4', '#9ACB00', '#616161'],
                hAxis: {
                    title: 'Feis Competiton and date'
                },
                height: '100%',
                isStacked: true,
                legend: {
                    position: 'none'
                },
                pointSize: 6,
                series: {
                    2: {
                        type: 'line'
                    }
                },
                seriesType: 'bars',
                vAxis: {
                    ticks: [
                        {v: -40, f: '40'},
                        {v: -20, f: '20'},
                        0,
                        20,
                        40
                    ],
                    title: 'Placement'
                },
                width: '100%'
      },
        view: {
            columns: ['feis', 'Dancers Not Placed', 'Dancers Placed', 'Placement']
        }
    });


    // Establish dependencies, declaring that 'filter' drives 'pieChart',
    // so that the pie chart will only display entries that are let through
    // given the chosen slider range.
    dashboard.bind(searchfilter, barChart);

    // Draw the dashboard.
    dashboard.draw(data);
  }

РЕДАКТИРОВАТЬ

Диаграмма все еще не рисуется, я убрал дату, потому что подумал, что это может быть проблемой.Когда я удаляю дату и вспоминаю, график рисует, но не рисует, когда я их добавляю.

Это мой обновленный код:

            function majorChart(){
            var data = google.visualization.arrayToDataTable([
                ['feis', 'Dancers Not Placed', {type: 'string', role: 'tooltip'}, 'Dancers Placed', {type: 'string', role: 'tooltip'}, 'Placement', {type: 'string', role: 'tooltip'}, 'recalled'],
                 ['Garden State Feis - Jan-05-2014', -18, 'Total Dancers Not Placed: 18', 22, 'Total Dancers Placed: 22',  20, 'Lace\'s Placement: 20th Place', Yes],['Oireachtas MidAtlantic - Apr-01-2014', -14, 'Total Dancers Not Placed: 14', 30, 'Total Dancers Placed: 30',  14, 'Lace\'s Placement: 14th place', Yes],['GEM CITY FEIS - Feb-14-2018', -42, 'Total Dancers Not Placed: 42', 38, 'Total Dancers Placed: 38', - 1, 'Lace\'s Placement: 1st place', No],['Broesler Feis - Jul-09-2018', -15, 'Total Dancers Not Placed: 15', 15, 'Total Dancers Placed: 15',  1, 'Lace\'s Placement: 1st place', Yes],['GEM CITY FEIS - Aug-21-2018', -21, 'Total Dancers Not Placed: 21', 26, 'Total Dancers Placed: 26', - 2, 'Lace\'s Placement: 2nd place', No],['Garden State Feis - Dec-01-2018', -48, 'Total Dancers Not Placed: 48', 12, 'Total Dancers Placed: 12', - 15, 'Lace\'s Placement: 15th Place', No],                    
            ]);

            // Create a dashboard.
    var dashboard = new google.visualization.Dashboard(
        document.getElementById('major_chart'));

    // Create a search filter, passing some options
    var searchfilter = new google.visualization.ControlWrapper({
      'controlType': 'StringFilter',
      'containerId': 'filter_major',
      'options': {
        'filterColumnLabel': 'feis',
        'ui': {
            label: 'Filter by feis or year'
        },
        'matchType':  'any'
      }
    });



var colfilter = new google.visualization.ControlWrapper({
controlType: 'CategoryFilter',
containerId: 'col_filter_major',
options: {
  filterColumnLabel: 'recalled',
}
});        

             // Create a combo chart, passing some options
    var barChart = new google.visualization.ChartWrapper({
      'chartType': 'ComboChart',
      'containerId': 'major',
      'options': {
        tooltip: {isHtml: true},
                legend:'none',
                chartArea: {
                    height: '100%',
                    width: '100%',
                    top: 16,
                    right: 16,
                    bottom: 60,
                    left: 60
                },

                colors: ['#03a9f4', '#9ACB00', '#616161'],
                hAxis: {
                    title: 'Feis Competiton and date'
                },
                height: '100%',
                isStacked: true,
                legend: {
                    position: 'none'
                },
                pointSize: 6,
                series: {
                    2: {
                        type: 'line'
                    }
                },
                seriesType: 'bars',
                vAxis: {
                    ticks: [
                        {v: -40, f: '40'},
                        {v: -30, f: '30'},
                        {v: -20, f: '20'},
                        {v: -10, f: '10'},
                        0,
                        10,
                        20,
                        30,
                        40
                    ],
                    title: 'Placement'
                },
                width: '100%'
      },
        view: {
            columns: [0, 1, 2, 3, 4, 5]
        }

    });


    // Establish dependencies, declaring that 'filter' drives 'pieChart',
    // so that the pie chart will only display entries that are let through
    // given the chosen slider range.
    dashboard.bind(searchfilter, colfilter, barChart);

    // Draw the dashboard.
    dashboard.draw(data);
  }

РЕДАКТИРОВАТЬ 2

Хорошо, это мой обновленный код:

function majorChart(){
            var data = google.visualization.arrayToDataTable([
  ['feis', 'Dancers Not Placed', {type: 'string', role: 'tooltip'}, 'Dancers Placed', {type: 'string', role: 'tooltip'}, 'Placement', {type: 'string', role: 'tooltip'}, 'date', 'recalled', {type: 'string', role: 'annotation'}],

                ['Halloween Feis - Oct-27-2018', -36, 'Total Dancers Not Placed: 36', 30, 'Total Dancers Placed: 30',  1, 'Rob placed 1st out of 66 total dancers', new Date(10-27-2018), 'Yes', '1st place'],['North Coast Feis - Feb-03-2019', -44, 'Total Dancers Not Placed: 44', 34, 'Total Dancers Placed: 34',  11, 'Rob placed 11th out of 78 total dancers', new Date(02-03-2019), 'No', '11th place'],  ]);

      // Create a dashboard.
var dashboard = new google.visualization.Dashboard(
  document.getElementById('dashboard_div'));

// Create a search filter, passing some options
var searchfilter = new google.visualization.ControlWrapper({
'controlType': 'StringFilter',
'containerId': 'filter_major',
'options': {
  'filterColumnLabel': 'feis',
  'ui': {
      label: 'Filter by feis'
  },
  'matchType':  'any'
}
});

var datefilter = new google.visualization.ControlWrapper({
controlType: 'DateRangeFilter',
containerId: 'date_filter_major',
options: {
  filterColumnLabel: 'date',
}
});
var colfilter = new google.visualization.ControlWrapper({
controlType: 'CategoryFilter',
containerId: 'recalled_filter_major',
options: {
  filterColumnLabel: 'recalled',
    'ui': {
        label: 'Show Recalled'
    }
}

});

// Create a combo chart, passing some options
var barChart = new google.visualization.ChartWrapper({
'chartType': 'ComboChart',
'containerId': 'combo_chart',
'options': {
  tooltip: {isHtml: true},
          legend:'none',
          chartArea: {
              height: '100%',
              width: '100%',
              top: 16,
              right: 16,
              bottom: 60,
              left: 60
          },

          colors: ['#03a9f4', '#9ACB00', '#616161'],
          hAxis: {
              title: 'Feis Competiton and date'
          },
          height: '100%',
          isStacked: true,
          legend: {
              position: 'none'
          },
          pointSize: 6,
          series: {
              2: {
                  type: 'line'
              }
          },
          seriesType: 'bars',
          vAxis: {
              ticks: [
                  {v: -40, f: '40'},
                        {v: -30, f: '30'},
                        {v: -20, f: '20'},
                        {v: -10, f: '10'},
                        0,
                        10,
                        20,
                        30,
                        40
              ],
              title: 'Placement'
          },
          width: '100%'
},
view: {
    columns: [0, 1, 2, 3, 4, 5, 6, 9]
}
});

dashboard.bind([searchfilter, datefilter, colfilter], barChart);

dashboard.draw(data);
}

Фильтры появляются .. Но сама диаграмма не рисует.Фильтр даты также неверен ..

enter image description here

1 Ответ

0 голосов
/ 04 декабря 2018

при использовании view в оболочке элемента управления или диаграммы свойство
columns и rows должно быть индексами,
не метками ...

вместо меток столбцовздесь ...

columns: ['feis', 'Dancers Not Placed', 'Dancers Placed', 'Placement']

используйте индексы столбцов ...

columns: [0, 1, 2, 3, 4, 5, 6]

, затем вы можете добавить дополнительные столбцы в таблицу данных, которые диаграмма будет игнорировать.
см.следующий рабочий фрагмент ...

google.charts.load('current', {
  packages: ['controls']
}).then(function () {
  var data = google.visualization.arrayToDataTable([
      ['feis', 'Dancers Not Placed', {type: 'string', role: 'tooltip'}, 'Dancers Placed', {type: 'string', role: 'tooltip'}, 'Placement', {type: 'string', role: 'tooltip'}, 'date', 'column'],
      ['Garden State Feis - 01-05-2014', -18, 'Total Dancers Not Placed: 18', 22, 'Total Dancers Placed: 22',  20, 'Lace\'s Placement: 20th Place', new Date(2018, 11, 1), 'A'],
      ['GEM CITY FEIS - 02-14-2018', -42, 'Total Dancers Not Placed: 42', 38, 'Total Dancers Placed: 38', - 1, 'Lace\'s Placement: 1st place', new Date(2018, 11, 2), 'B'],
      ['Broesler Feis - 07-09-2018', -15, 'Total Dancers Not Placed: 15', 15, 'Total Dancers Placed: 15',  1, 'Lace\'s Placement: 1st place', new Date(2018, 11, 3), 'C'],
      ['GEM CITY FEIS - 08-21-2018', -21, 'Total Dancers Not Placed: 21', 26, 'Total Dancers Placed: 26', - 2, 'Lace\'s Placement: 2nd place', new Date(2018, 11, 4), 'D'],
      ['Garden State Feis - 12-01-2018', -48, 'Total Dancers Not Placed: 48', 12, 'Total Dancers Placed: 12', - 15, 'Lace\'s Placement: 15th Place', new Date(2018, 11, 5), 'E'],
  ]);

          // Create a dashboard.
  var dashboard = new google.visualization.Dashboard(
      document.getElementById('dashboard_div'));

  // Create a search filter, passing some options
  var searchfilter = new google.visualization.ControlWrapper({
    'controlType': 'StringFilter',
    'containerId': 'filter_div',
    'options': {
      'filterColumnLabel': 'feis',
      'ui': {
          label: 'Filter by feis'
      },
      'matchType':  'any'
    }
  });

  var datefilter = new google.visualization.ControlWrapper({
    controlType: 'DateRangeFilter',
    containerId: 'date_filter',
    options: {
      filterColumnLabel: 'date',
    }
  });
  var colfilter = new google.visualization.ControlWrapper({
    controlType: 'CategoryFilter',
    containerId: 'col_filter',
    options: {
      filterColumnLabel: 'column',
    }
  });

  // Create a combo chart, passing some options
  var barChart = new google.visualization.ChartWrapper({
    'chartType': 'ComboChart',
    'containerId': 'combo_chart',
    'options': {
      tooltip: {isHtml: true},
              legend:'none',
              chartArea: {
                  height: '100%',
                  width: '100%',
                  top: 16,
                  right: 16,
                  bottom: 60,
                  left: 60
              },

              colors: ['#03a9f4', '#9ACB00', '#616161'],
              hAxis: {
                  title: 'Feis Competiton and date'
              },
              height: '100%',
              isStacked: true,
              legend: {
                  position: 'none'
              },
              pointSize: 6,
              series: {
                  2: {
                      type: 'line'
                  }
              },
              seriesType: 'bars',
              vAxis: {
                  ticks: [
                      {v: -40, f: '40'},
                      {v: -20, f: '20'},
                      0,
                      20,
                      40
                  ],
                  title: 'Placement'
              },
              width: '100%'
    },
    view: {
        columns: [0, 1, 2, 3, 4, 5, 6]
    }
  });


  // Establish dependencies, declaring that 'filter' drives 'pieChart',
  // so that the pie chart will only display entries that are let through
  // given the chosen slider range.
  dashboard.bind([searchfilter, datefilter, colfilter], barChart);

  // Draw the dashboard.
  dashboard.draw(data);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="dashboard_div">
  <div id="filter_div"></div>
  <div id="date_filter"></div>
  <div id="col_filter"></div>
  <div id="combo_chart"></div>
</div>

ОБНОВЛЕНИЕ

существует проблема с вашим конструктором даты,
в следующем, дата должназаключенный в кавычки в виде строки.

new Date(10-27-2018) // <-- bad
new Date('10-27-2018') // <-- good

без кавычек, заявление равняется ...

new Date(-2035)  // <-- 10 minus 27 minus 2018 = -2035

, поэтому оно все еще работает, но вы получите неверную дату.

см. Следующий рабочий фрагмент ...

google.charts.load('current', {
  packages: ['controls', 'corechart']
}).then(function () {
  var data = google.visualization.arrayToDataTable([
    ['feis', 'Dancers Not Placed', {type: 'string', role: 'tooltip'}, 'Dancers Placed', {type: 'string', role: 'tooltip'}, 'Placement', {type: 'string', role: 'tooltip'}, 'date', 'recalled', {type: 'string', role: 'annotation'}],
    ['Halloween Feis - Oct-27-2018', -36, 'Total Dancers Not Placed: 36', 30, 'Total Dancers Placed: 30',  1, 'Rob placed 1st out of 66 total dancers', new Date('10-27-2018'), 'Yes', '1st place'],['North Coast Feis - Feb-03-2019', -44, 'Total Dancers Not Placed: 44', 34, 'Total Dancers Placed: 34',  11, 'Rob placed 11th out of 78 total dancers', new Date('02-03-2019'), 'No', '11th place'],
  ]);

  // Create a dashboard.
  var dashboard = new google.visualization.Dashboard(
    document.getElementById('dashboard_div'));

  // Create a search filter, passing some options
  var searchfilter = new google.visualization.ControlWrapper({
    'controlType': 'StringFilter',
    'containerId': 'filter_major',
    'options': {
      'filterColumnLabel': 'feis',
      'ui': {
          label: 'Filter by feis'
      },
      'matchType':  'any'
    }
  });

  var datefilter = new google.visualization.ControlWrapper({
    controlType: 'DateRangeFilter',
    containerId: 'date_filter_major',
    options: {
      filterColumnLabel: 'date',
    }
  });
  var colfilter = new google.visualization.ControlWrapper({
    controlType: 'CategoryFilter',
    containerId: 'recalled_filter_major',
    options: {
      filterColumnLabel: 'recalled',
        'ui': {
            label: 'Show Recalled'
        }
    }
  });

  // Create a combo chart, passing some options
  var barChart = new google.visualization.ChartWrapper({
    chartType: 'ComboChart',
    containerId: 'combo_chart',
    options: {
      tooltip: {isHtml: true},
      legend:'none',
      chartArea: {
          height: '100%',
          width: '100%',
          top: 16,
          right: 16,
          bottom: 60,
          left: 60
      },
      colors: ['#03a9f4', '#9ACB00', '#616161'],
      hAxis: {
          title: 'Feis Competiton and date'
      },
      height: '100%',
      isStacked: true,
      legend: {
          position: 'none'
      },
      pointSize: 6,
      series: {
          2: {
              type: 'line'
          }
      },
      seriesType: 'bars',
      vAxis: {
        ticks: [
          {v: -40, f: '40'},
          {v: -30, f: '30'},
          {v: -20, f: '20'},
          {v: -10, f: '10'},
          0,
          10,
          20,
          30,
          40
        ],
        title: 'Placement'
      },
      width: '100%'
    },
    view: {
        columns: [0, 1, 2, 3, 4, 5, 6, 9]
    }
  });

  dashboard.bind([searchfilter, datefilter, colfilter], barChart);
  dashboard.draw(data);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="dashboard_div">
  <div id="filter_major"></div>
  <div id="date_filter_major"></div>
  <div id="recalled_filter_major"></div>
  <div id="combo_chart"></div>
</div>
...