2012-07-12 6 views
12

मुझे आश्चर्य है कि किसी ने मोबाइल और डेस्कटॉप दोनों पर अपने चार्ट को अच्छे लगने के लिए हाइचार्ट्स का उपयोग करके एक उत्तरदायी डिज़ाइन सफलतापूर्वक कार्यान्वित किया है।हाईचरस.जेएस चार्ट बनाना मोबाइल और डेस्कटॉप पर अच्छा लग रहा है

डिफ़ॉल्ट रूप से, जब आप ब्राउज़र स्क्रीन का आकार बदलते हैं तो हाईचार्ट फिर से स्केल करते हैं, बस एक्स-अक्ष टिक टिक टेक्स्ट और बार ग्राफ द्वारा घिरा हुआ हो जाता है और लंबा और बहुत पतला दिखता है (बहुत संपीड़ित)। मेरा मतलब समझने के लिए, आप this page पर जा सकते हैं और ब्राउज़र का आकार बदल सकते हैं।

मुझे लगता है कि इन मुद्दों को मूल संख्या के 1/3 कहने वाले डेटा बिंदुओं की मात्रा को कम करके संबोधित किया जा सकता है, हालांकि मुझे आश्चर्य है कि यह हाईचर्स एपीआई का उपयोग करके प्रोग्रामेटिक रूप से कैसे पूरा किया जाएगा। अगर यह एक अच्छा विचार नहीं लगता है तो मुझे अन्य विचारों या समाधानों में भी दिलचस्पी है, जो लोग मोबाइल पर हाईचार्ट्स का उपयोग करने के लिए आ सकते हैं (या शायद यहां तक ​​कि विभिन्न जेएस चार्टिंग लाइब्रेरीज़ जहां बहु-डिवाइस समाधान लागू करना आसान हो सकता है ?)।

+2

http://angulartutorial.blogspot.in/2014/03/responsive-highchart.html – Prashobh

+0

इस का संदर्भ लें और देखें कि यह मदद करता है - http://jsfiddle.net/Behseini/qheh4w0n/ –

उत्तर

17

समाधान अपेक्षाकृत सरल लगता है।

बस ग्राफ एक निश्चित चौड़ाई है देना नहीं है, यानी, चौड़ाई को परिभाषित नहीं है या width:100% सेट और, डेमो मैं उल्लेख, बार चार्ट चौड़ाई के विपरीत और साथ सलाखों के रूप में ज्यादा हटना होगा के रूप में ब्राउज़र की चौड़ाई है कम किया हुआ।

+0

यह उत्तर क्यों दिया गया था? –

4

यह शायद इस बात पर निर्भर करता है कि आप किस प्रकार के चार्ट प्रदर्शित कर रहे हैं। मोबाइल पर, यदि आप कॉलम चार्ट प्रदर्शित कर रहे हैं, तो आप चार्ट को घुमा सकते हैं ताकि यह बार चार्ट बन जाए।

यदि आप एक लाइन चार्ट प्रदर्शित कर रहे हैं, तो आप डेटा को "गुंजाइश" कर सकते हैं, ताकि आप केवल बिंदु प्राप्त करने के लिए आवश्यक कम से कम अंक प्रदर्शित कर रहे हों। जैसे ही आप ज़ूम इन करते हैं, वर्तमान दृश्य को फिट करने के लिए डेटा को दोबारा दोहराएं। यह कुछ हाथों से जुड़ी कुछ घटनाओं का उपयोग करके किया जा सकता है।

+0

यह एक समाधान-फिट होने की संभावना नहीं है-सब वास्तव में बिंदु है। आपको कंप्यूटर को बताना होगा कि आप @ टिमपेटर्सन क्या करना चाहते हैं और इसे सिर्फ आपके लिए अनुमान लगाने दें। – jcolebrand

0

एक उदाहरण बूटस्ट्रैप

<!DOCTYPE html> 
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta charset="utf-8" /> 
    <title>Highcharts data from JSON Response</title> 
     <style> 
     body{ 
      margin-top: 30px; 
      margin-left:40px; 
     } 
     .col-md-4{ 
     padding-left:5px !important; 
     padding-right:5px !important; 
     } 
     </style> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
    <script src="http://code.highcharts.com/highcharts.js"></script>  
<script src="https://code.highcharts.com/modules/exporting.js"></script> 
    <script type="text/javascript"> 
     // Data gathered from http://populationpyramid.net/germany/2015/ 

// Age categories 
var categories = ['0-4', '5-9', '10-14', '15-19', 
     '20-24', '25-29', '30-34', '35-39', '40-44', 
     '45-49', '50-54', '55-59', '60-64', '65-69', 
     '70-74', '75-79', '80-84', '85-89', '90-94', 
     '95-99', '100 + ']; 
$(document).ready(function() { 
    Highcharts.chart('container', { 
     chart: { 
      type: 'bar' 
     }, 

     xAxis: [{ 
      categories: categories, 
      reversed: false, 
      labels: { 
       step: 1 
      } 
     }, { // mirror axis on right side 
      opposite: true, 
      reversed: false, 
      categories: categories, 
      linkedTo: 0, 
      labels: { 
       step: 1 
      } 
     }], 
     yAxis: { 
      title: { 
       text: null 
      }, 
      labels: { 
       formatter: function() { 
        return Math.abs(this.value) + '%'; 
       } 
      } 
     }, 

     plotOptions: { 
      series: { 
       stacking: 'normal' 
      } 
     }, 

     tooltip: { 
      formatter: function() { 
       return '<b>' + this.series.name + ', age ' + this.point.category + '</b><br/>' + 
        'Population: ' + Highcharts.numberFormat(Math.abs(this.point.y), 0); 
      } 
     }, 

     series: [{ 
      name: 'Male', 
      data: [-2.2, -2.2, -2.3, -2.5, -2.7, -3.1, -3.2, 
       -3.0, -3.2, -4.3, -4.4, -3.6, -3.1, -2.4, 
       -2.5, -2.3, -1.2, -0.6, -0.2, -0.0, -0.0] 
     }, { 
      name: 'Female', 
      data: [2.1, 2.0, 2.2, 2.4, 2.6, 3.0, 3.1, 2.9, 
       3.1, 4.1, 4.3, 3.6, 3.4, 2.6, 2.9, 2.9, 
       1.8, 1.2, 0.6, 0.1, 0.0] 
     }] 
    }); 
    Highcharts.chart('container2', { 
     chart: { 
      type: 'bar' 
     }, 
     title: { 
      text: 'Population pyramid for Germany, 2015' 
     }, 
     subtitle: { 
      text: 'Source: <a href="http://populationpyramid.net/germany/2015/">Population Pyramids of the World from 1950 to 2100</a>' 
     }, 
     xAxis: [{ 
      categories: categories, 
      reversed: false, 
      labels: { 
       step: 1 
      } 
     }, { // mirror axis on right side 
      opposite: true, 
      reversed: false, 
      categories: categories, 
      linkedTo: 0, 
      labels: { 
       step: 1 
      } 
     }], 
     yAxis: { 
      title: { 
       text: null 
      }, 
      labels: { 
       formatter: function() { 
        return Math.abs(this.value) + '%'; 
       } 
      } 
     }, 

     plotOptions: { 
      series: { 
       stacking: 'normal' 
      } 
     }, 

     tooltip: { 
      formatter: function() { 
       return '<b>' + this.series.name + ', age ' + this.point.category + '</b><br/>' + 
        'Population: ' + Highcharts.numberFormat(Math.abs(this.point.y), 0); 
      } 
     }, 

     series: [{ 
      name: 'Male', 
      data: [-2.2, -2.2, -2.3, -2.5, -2.7, -3.1, -3.2, 
       -3.0, -3.2, -4.3, -4.4, -3.6, -3.1, -2.4, 
       -2.5, -2.3, -1.2, -0.6, -0.2, -0.0, -0.0] 
     }, { 
      name: 'Female', 
      data: [2.1, 2.0, 2.2, 2.4, 2.6, 3.0, 3.1, 2.9, 
       3.1, 4.1, 4.3, 3.6, 3.4, 2.6, 2.9, 2.9, 
       1.8, 1.2, 0.6, 0.1, 0.0] 
     }] 
    }); 
    Highcharts.chart('container3', { 
     chart: { 
      type: 'bar' 
     }, 
     title: { 
      text: 'Population pyramid for Germany, 2015' 
     }, 
     subtitle: { 
      text: 'Source: <a href="http://populationpyramid.net/germany/2015/">Population Pyramids of the World from 1950 to 2100</a>' 
     }, 
     xAxis: [{ 
      categories: categories, 
      reversed: false, 
      labels: { 
       step: 1 
      } 
     }, { // mirror axis on right side 
      opposite: true, 
      reversed: false, 
      categories: categories, 
      linkedTo: 0, 
      labels: { 
       step: 1 
      } 
     }], 
     yAxis: { 
      title: { 
       text: null 
      }, 
      labels: { 
       formatter: function() { 
        return Math.abs(this.value) + '%'; 
       } 
      } 
     }, 

     plotOptions: { 
      series: { 
       stacking: 'normal' 
      } 
     }, 

     tooltip: { 
      formatter: function() { 
       return '<b>' + this.series.name + ', age ' + this.point.category + '</b><br/>' + 
        'Population: ' + Highcharts.numberFormat(Math.abs(this.point.y), 0); 
      } 
     }, 

     series: [{ 
      name: 'Male', 
      data: [-2.2, -2.2, -2.3, -2.5, -2.7, -3.1, -3.2, 
       -3.0, -3.2, -4.3, -4.4, -3.6, -3.1, -2.4, 
       -2.5, -2.3, -1.2, -0.6, -0.2, -0.0, -0.0] 
     }, { 
      name: 'Female', 
      data: [2.1, 2.0, 2.2, 2.4, 2.6, 3.0, 3.1, 2.9, 
       3.1, 4.1, 4.3, 3.6, 3.4, 2.6, 2.9, 2.9, 
       1.8, 1.2, 0.6, 0.1, 0.0] 
     }] 
    }); 
}) 

    </script> 
</head> 
<body> 
<div class="col-md-12 row"> 
<div class="col-md-4"> 
hello 
</div> 
    <div class="col-md-8 row"> 
    <div class="col-md-4"><div id="container" style="height: 400px;border:1px solid;"></div></div> <div class="col-md-4"><div id="container2" style="height: 400px;border:1px solid;"></div></div> 
    <div class="col-md-4"><div id="container3" style="height: 400px;border:1px solid;"></div></div> 
    </div> 
    </div> 


</body> 
</html> 
1

साथ आप चार्ट कंटेनर div width:100% सेट कर सकते हैं। फिर बस हाईचार्ट चौड़ाई संपत्ति को हटा दें। मैंने इसे स्पार्कलाइन चार्ट के लिए हल किया। अब यह मोबाइल उत्तरदायी है।

Highcharts.chart('my-sparkline-chart, { 
     chart: { 
      type: 'areaspline', 
      height: '70', 
      //width: '189', //comment width property. 
      spacing: [0, 0, 0, 0], 
      backgroundColor: "transparent" 
     } 
... 
संबंधित मुद्दे