2017-02-15 3 views
1

Я использую высокий график и в настоящее время у меня проблема на нескольких диаграммах на странице. Проблема небольшая, у меня есть две диаграммы с загрузкой и печатью btn .. на обоих графиках, но первая загрузка btn работает нормально, а следующая - нет. Вот моя проблема http://jsfiddle.net/metalhead101/7f4194th/Несколько диаграмм на одной странице Highchart

JS

$(function() { 
    // Create the first chart 
    $('#chart-A').highcharts({ 
     chart: { 
      type: 'column' // Chart type (i.e. 'bar', 'column', 'spline' etc) 
     }, 
     title: { 
      text: 'Chart A' // Title for the chart 
     }, 
     xAxis: { 
      categories: ['Jane', 'John', 'Joe', 'Jack', 'jim'] 
      // Categories for the charts 
     }, 
     yAxis: { 
      min: 0, // Lowest value to show on the yAxis 
      title: { 
       text: 'Apple Consumption' // Title for the yAxis 
      } 
     }, 
     legend: { 
      enabled: false // Enable/Disable the legend 
     }, 
     credits: { 
      enabled: true, // Enable/Disable the credits 
      text: 'This is a credit' 
     }, 
     tooltip: { 
      shared: true // If you have multiple series then all points in each category will show up on one tooltip 
     }, exporting: { 
      buttons: { 
       contextButton: { 
        enabled: false 
       }, 
       exportButton: { 
        text: 'Download', 
        theme: { 
         fill: '#eee', 
         stroke: '#fff', 
         states: { 
          hover: { 
           fill: '#fff', 
           stroke: '#eee' 
          }, 
          select: { 
           fill: '#ddd', 
           stroke: '#0f0' 
          } 
         } 
        }, 
        _titleKey: 'contextButtonTitle', 
        // Use only the download related menu items from the default context button 
        menuItems: Highcharts.getOptions().exporting.buttons.contextButton.menuItems.splice(2) 
       }, 
       printButton: { 
        text: 'Print', 
        theme: { 
         fill: '#eee', 
         stroke: '#fff', 
         states: { 
          hover: { 
           fill: '#fff', 
           stroke: '#eee' 
          }, 
          select: { 
           fill: '#ddd', 
           stroke: '#0f0' 
          } 
         } 
        }, 
        _titleKey: 'printChart', 
        onclick: function() { 
         this.print(); 
        } 
       } 
      } 
     }, 
     series: [{ 
      name: 'Apples', // Name of your series 
      data: [5, 3, 8, 2, 4] // The data in your series 

     }] 
    }); 

    $('#chart-B').highcharts({ 
     chart: { 
      type: 'column' 
     }, 
     title: { 
      text: 'Chart B' 
     }, 
     xAxis: { 
      categories: ['Jane', 'John', 'Joe', 'Jack', 'jim'] 
     }, 
     yAxis: { 
      min: 0, 
      title: { 
       text: 'Miles during Run' 
      } 
     }, 
     legend: { 
      enabled: false 
     }, 
     credits: { 
      enabled: true, 
      text: 'You can have a link in here too', 
      href: 'http://www.google.com' 
     }, 
     tooltip: { 
      shared: true 
     }, exporting: { 
      buttons: { 
       contextButton: { 
        enabled: false 
       }, 
       exportButton: { 
        text: 'Download', 
        theme: { 
         fill: '#eee', 
         stroke: '#fff', 
         states: { 
          hover: { 
           fill: '#fff', 
           stroke: '#eee' 
          }, 
          select: { 
           fill: '#ddd', 
           stroke: '#0f0' 
          } 
         } 
        }, 
        _titleKey: 'contextButtonTitle', 
        // Use only the download related menu items from the default context button 
        menuItems: Highcharts.getOptions().exporting.buttons.contextButton.menuItems.splice(2) 
       }, 
       printButton: { 
        text: 'Print', 
        theme: { 
         fill: '#eee', 
         stroke: '#fff', 
         states: { 
          hover: { 
           fill: '#fff', 
           stroke: '#eee' 
          }, 
          select: { 
           fill: '#ddd', 
           stroke: '#0f0' 
          } 
         } 
        }, 
        _titleKey: 'printChart', 
        onclick: function() { 
         this.print(); 
        } 
       } 
      } 
     }, 
     series: [{ 
      name: 'Miles', 
      data: [2.4, 3.8, 6.1, 5.3, 4.1] 

     }] 
    }); 
}); 

Большое спасибо ...

+0

его хорошо создать одну кнопку загрузки для обеих диаграмм ??? – Darshak

+0

Пожалуйста, найдите любое решение, пожалуйста, обновите здесь, – Darshak

+0

благодарит за ответ. Нет. Я добавил параметр onlick, чтобы показать один график вовремя .. так что нужно два btn – metalhead101

ответ

1

Вы кнопку, чтобы определить первый в

var buttons = Highcharts.getOptions().exporting.buttons.contextButton.menuItems; 

И затем использовать этот buttons в каждом Highcharts

exporting: { 
     buttons: { 
      exportButton: { 
       text: 'Download', 
       theme: { 
        fill: '#eee', 
        stroke: '#fff', 
        states: { 
         hover: { 
          fill: '#fff', 
          stroke: '#eee' 
         }, 
         select: { 
          fill: '#ddd', 
          stroke: '#0f0' 
         } 
        } 
       }, 
       _titleKey: 'contextButtonTitle', 
       // Use only the download related menu items from the default context button 
       menuItems:buttons.slice(2) 
      }, 
     } 
     } 

Forked Fiddle

+0

Спасибо большое. Попробуй это. – metalhead101

+0

Является ли ответ полезным и решает вопрос –

+0

да, это было очень полезно и решило мою проблему .. спасибо alot – metalhead101

Смежные вопросы