बिंदुओं को कस्टमाइज़ करना

खास जानकारी

कई Google चार्ट में, डेटा वैल्यू सटीक पॉइंट पर दिखाई जाती हैं. लाइन चार्ट, लाइनों से जुड़े हुए इन पॉइंट का सिर्फ़ एक सेट होता है और स्कैटर चार्ट सिर्फ़ पॉइंट होते हैं.

स्कैटर चार्ट को छोड़कर सभी चार्ट में, ये पॉइंट डिफ़ॉल्ट रूप से शून्य साइज़ के होते हैं. pointSize विकल्प की मदद से, उनका साइज़ और pointShape विकल्प की मदद से उनके आकार को कंट्रोल किया जा सकता है.

ऊपर, आपको छह सीरीज़ वाला एक चार्ट दिख सकता है. हर सीरीज़ में pointSize 30 है, लेकिन अलग-अलग pointShape हैं.

        var options = {
          legend
: 'none',
          hAxis
: { minValue: 0, maxValue: 7 },
         
pointSize: 30,
          series
: {
               
0: { pointShape: 'circle' },
               
1: { pointShape: 'triangle' },
               
2: { pointShape: 'square' },
               
3: { pointShape: 'diamond' },
               
4: { pointShape: 'star' },
               
5: { pointShape: 'polygon' }
           
}

       
};
  <head>
   
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
   
<script type="text/javascript">
      google
.charts.load("current", {packages:["corechart"]});
      google
.charts.setOnLoadCallback(drawChart);
     
function drawChart() {
       
var data = google.visualization.arrayToDataTable
           
([['X', '1', '2', '3', '4', '5', '6'],
             
[1, 2, null, null, null, null, null],
             
[2, null, 3, null, null, null, null],
             
[3, null, null, 4, null, null, null],
             
[4, null, null, null, 5, null, null],
             
[5, null, null, null, null, 6, null],
             
[6, null, null, null, null, null, 7]
       
]);

       
var options = {
          legend
: 'none',
         
pointSize: 30,
          series
: {
               
0: { pointShape: 'circle' },
               
1: { pointShape: 'triangle' },
               
2: { pointShape: 'square' },
               
3: { pointShape: 'diamond' },
               
4: { pointShape: 'star' },
               
5: { pointShape: 'polygon' }
           
}

       
};

       
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart
.draw(data, options);
     
}
   
</script>
 
</head>
 
<body>
   
<div id="chart_div" style="width: 900px; height: 500px;"></div>
 
</body>
</html>

कुछ आसान उदाहरण

पिछले सेक्शन के चार्ट से अलग, ज़्यादातर चार्ट में सिर्फ़ एक सीरीज़ होती है. यहां 20 पॉइंट वाले सर्कुलर पॉइंट वाले लाइन चार्ट का उदाहरण दिया गया है:

चूंकि डिफ़ॉल्ट pointShape मंडली है, इसलिए हम इसे विकल्पों से बाहर छोड़ सकते हैं:

        var options = {
          legend
: 'none',
          hAxis
: { minValue: 0, maxValue: 9 },
          curveType
: 'function',
         
pointSize: 20,
     
};
  <head>
   
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
   
<script type="text/javascript">
      google
.charts.load("current", {packages:["corechart"]});
      google
.charts.setOnLoadCallback(drawChart);
     
function drawChart() {
       
var data = google.visualization.arrayToDataTable
           
([['X', 'Y'],
             
[1, 3],
             
[2, 2.5],
             
[3, 3],
             
[4, 4],
             
[5, 4],
             
[6, 3],
             
[7, 2.5],
             
[8, 3]
       
]);

       
var options = {
          legend
: 'none',
          hAxis
: { minValue: 0, maxValue: 9 },
          curveType
: 'function',
         
pointSize: 20,
       
};

       
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart
.draw(data, options);
   
}
   
</script>
 
</head>
 
<body>
   
<div id="chart_div" style="width: 900px; height: 500px;"></div>
 
</body>
</html>

इसे "गोल" से किसी दूसरे आकार में बदला जा सकता है. इसके लिए, pointShape को "त्रिकोण", "स्क्वेयर", "डायमंड", "स्टार" या "पॉलीगॉन" पर सेट करें:

        var options = {
          legend
: 'none',
          hAxis
: { minValue: 0, maxValue: 9 },
          colors
: ['#795548'],
          pointSize
: 20,
         
pointShape: 'square'
       
};
  <head>
   
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
   
<script type="text/javascript">
      google
.charts.load("current", {packages:["corechart"]});
      google
.charts.setOnLoadCallback(drawChart);
     
function drawChart() {
       
var data = google.visualization.arrayToDataTable
           
([['X', 'Y'],
             
[1, 3],
             
[2, 2.5],
             
[3, 3],
             
[4, 4],
             
[5, 4],
             
[6, 3],
             
[7, 2.5],
             
[8, 3]
       
]);

       
var options = {
          legend
: 'none',
          hAxis
: { minValue: 0, maxValue: 9 },
          colors
: ['#795548'],
          pointSize
: 20,
         
pointShape: 'square'
       
};

       
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart
.draw(data, options);
   
}
   
</script>
 
</head>
 
<body>
   
<div id="chart_div" style="width: 900px; height: 500px;"></div>
 
</body>
</html>

'स्टार' और 'पॉलीगॉन' आकृतियों से आप पक्षों की संख्या कस्टमाइज़ कर सकते हैं, दोनों की डिफ़ॉल्ट संख्या पांच होती है. कुछ चार-तरफ़ा तारे:

        var options = {
          legend
: 'none',
          hAxis
: { minValue: 0, maxValue: 9 },
          colors
: ['#EF851C'],
          pointSize
: 30,
         
pointShape: { type: 'star', sides: 4 }
       
};
<html>
 
<head>
   
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
   
<script type="text/javascript">
      google
.charts.load("current", {packages:["corechart"]});
      google
.charts.setOnLoadCallback(drawChart);
     
function drawChart() {
       
var data = google.visualization.arrayToDataTable
           
([['X', 'Y'],
             
[1, 3],
             
[2, 2.5],
             
[3, 3],
             
[4, 4],
             
[5, 4],
             
[6, 3],
             
[7, 2.5],
             
[8, 3]
       
]);

       
var options = {
          legend
: 'none',
          hAxis
: { minValue: 0, maxValue: 9 },
          colors
: ['#EF851C'],
          pointSize
: 30,
         
pointShape: { type: 'star', sides: 4 }
       
};

       
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart
.draw(data, options);
   
}
   
</script>
 
</head>
 
<body>
   
<div id="chart_div" style="width: 900px; height: 500px;"></div>
 
</body>
</html>

dent विकल्प की मदद से, स्टार को अपनी पसंद के मुताबिक बनाया जा सकता है. इससे यह कंट्रोल किया जाता है कि तारा कितना अवतल है. जब डेंट शून्य के करीब होगा, तो स्टारफ़िश की तरह स्टारफ़िश का दिखेगा. जैसे-जैसे डेंट एक के पास आएगा, यह समबाहु पॉलीगॉन से बड़ा होकर उड़ जाएगा.

यहां पर पांच साइड वाले तारों के लिए 0.05 से 0.8 के बीच डेंट दिए गए हैं:

var options = {
    legend
: 'none',
    hAxis
: { textPosition: 'none' },
    vAxis
: { textPosition: 'none', gridlines: { count: 0 },
             baselineColor
: 'white' },
    colors
: ['#E94D20', '#ECA403', '#63A74A',
             
'#15A0C8', '#4151A3', '#703593', '#981B48'],
    pointSize
: 20,
    annotations
: { stemColor: 'white', textStyle: { fontSize: 16 } },
    series
: {
       
0: { pointShape: { type: 'star', sides: 5, dent: 0.05 } },
       
1: { pointShape: { type: 'star', sides: 5, dent: 0.1 } },
       
2: { pointShape: { type: 'star', sides: 5, dent: 0.2 } },
       
3: { pointShape: { type: 'star', sides: 5 } },
       
4: { pointShape: { type: 'star', sides: 5, dent: 0.5 } },
       
5: { pointShape: { type: 'star', sides: 5, dent: 0.7 } },
       
6: { pointShape: { type: 'star', sides: 5, dent: 0.8 } },
   
}
};
<html>
 
<head>
   
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
   
<script type="text/javascript">
      google
.charts.load("current", {packages:["corechart"]});
      google
.charts.setOnLoadCallback(drawChart);
     
function drawChart() {
         
var data = new google.visualization.DataTable();
          data
.addColumn('string', 'Element');
          data
.addColumn('number', 'A');
          data
.addColumn( { type: 'string', role: 'annotation' });
          data
.addColumn('number', 'B');
          data
.addColumn( { type: 'string', role: 'annotation' });
          data
.addColumn('number', 'C');
          data
.addColumn( { type: 'string', role: 'annotation' });
          data
.addColumn('number', 'D');
          data
.addColumn( { type: 'string', role: 'annotation' });
          data
.addColumn('number', 'E');
          data
.addColumn( { type: 'string', role: 'annotation' });
          data
.addColumn('number', 'F');
          data
.addColumn( { type: 'string', role: 'annotation' });
          data
.addColumn('number', 'G');
          data
.addColumn( { type: 'string', role: 'annotation' });
          data
.addRow(['A', 1, "dent: 0.05", , , , , , , , , , , , null]);
          data
.addRow(['B', , , 1, "dent: 0.1", , , , , , , , , , null]);
          data
.addRow(['C', , , , , 1, "dent: 0.2", , , , , , , , null]);
          data
.addRow(['D', , , , , , , 1, "default", , , , , , null]);
          data
.addRow(['E', , , , , , , , , 1, "dent: 0.5", , , , null]);
          data
.addRow(['F', , , , , , , , , , , 1, "dent: 0.7", , null]);
          data
.addRow(['G', , , , , , , , , , , , , 1, "dent: 0.8"]);

         
var options = {
              legend
: 'none',
              hAxis
: { textPosition: 'none' },
              vAxis
: { textPosition: 'none', gridlines: { count: 0 },
                       baselineColor
: 'white' },
              colors
: ['#E94D20', '#ECA403', '#63A74A',
                       
'#15A0C8', '#4151A3', '#703593', '#981B48'],
              pointSize
: 20,
              annotations
: { stemColor: 'white', textStyle: { fontSize: 16 } },
              series
: {
                 
0: { pointShape: { type: 'star', sides: 5, dent: 0.05 } },
                 
1: { pointShape: { type: 'star', sides: 5, dent: 0.1 } },
                 
2: { pointShape: { type: 'star', sides: 5, dent: 0.2 } },
                 
3: { pointShape: { type: 'star', sides: 5 } },
                 
4: { pointShape: { type: 'star', sides: 5, dent: 0.5 } },
                 
5: { pointShape: { type: 'star', sides: 5, dent: 0.7 } },
                 
6: { pointShape: { type: 'star', sides: 5, dent: 0.8 } },
             
}
         
};

         
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
          chart
.draw(data, options);
   
}
   
</script>
 
</head>
 
<body>
   
<div id="chart_div" style="width: 900px; height: 500px;"></div>
 
</body>
</html>

घुमाव

सभी बिंदु आकृतियों को डिग्री में दिए गए rotation विकल्प से घुमाया जा सकता है. उदाहरण के लिए, हम अपने त्रिभुजों को 180 डिग्री घुमाकर नीचे दिए गए एरिया चार्ट में नीचे की ओर पॉइंट बना सकते हैं:

        var options = {
          legend
: 'none',
          colors
: ['#15A0C8'],
          pointSize
: 30,
         
pointShape: { type: 'triangle', rotation: 180 }
       
};
  <head>
   
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
   
<script type="text/javascript">
      google
.charts.load("current", {packages:["corechart"]});
      google
.charts.setOnLoadCallback(drawChart);
     
function drawChart() {
       
var data = google.visualization.arrayToDataTable
           
([['X', 'Y'],
             
[1, 3],
             
[2, 2.5],
             
[3, 2],
             
[4, 3],
             
[5, 4.5],
             
[6, 6.5],
             
[7, 9],
             
[8, 12]
       
]);

       
var options = {
          legend
: 'none',
          colors
: ['#15A0C8'],
          pointSize
: 30,
         
pointShape: { type: 'triangle', rotation: 180 }
       
};

       
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
        chart
.draw(data, options);
   
}
   
</script>
 
</head>
 
<body>
   
<div id="chart_div" style="width: 900px; height: 500px;"></div>
 
</body>
</html>

अलग-अलग पॉइंट को पसंद के मुताबिक बनाना

डिफ़ॉल्ट रूप से, किसी पॉइंट पर लागू की गई स्टाइल, सीरीज़ के सभी पॉइंट पर लागू होती हैं. अगर आपको किसी खास डेटा पॉइंट का रंग-रूप बदलना है, तो उसे स्टाइल में बदला जा सकता है.

इस चार्ट में, हमने एक पॉइंट का साइज़ बढ़ाया है, ओपैसिटी को 0.3 तक कम कर दिया है, और उसका आकार और रंग बदला है:

<html>
 
<head>
   
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
   
<script type="text/javascript">
      google
.charts.load('current', {'packages':['corechart']});
      google
.charts.setOnLoadCallback(drawChart);

     
function drawChart() {
       
var data = google.visualization.arrayToDataTable
           
([['X', 'Y', {'type': 'string', 'role': 'style'}],
             
[1, 3, null],
             
[2, 2.5, null],
             
[3, 3, null],
             
[4, 4, null],
             
[5, 4, null],
             
[6, 3, 'point { size: 18; shape-type: star; fill-color: #a52714; }'],
             
[7, 2.5, null],
             
[8, 3, null]
       
]);

       
var options = {
          legend
: 'none',
          hAxis
: { minValue: 0, maxValue: 9 },
          curveType
: 'function',
          pointSize
: 7,
          dataOpacity
: 0.3
       
};

       
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart
.draw(data, options);
   
}
   
</script>
 
</head>
 
<body>
   
<div id="chart_div" style="width: 900px; height: 500px;"></div>
 
</body>
</html>

ये शैली कस्टमाइज़ेशन उपलब्ध हैं:

  • fill-color (इसे हेक्स स्ट्रिंग के तौर पर दिखाया जाता है.)
  • shape-dent
  • shape-rotation
  • shape-sides
  • shape-type
  • stroke-color (इसे हेक्स स्ट्रिंग के तौर पर दिखाया जाता है.)
  • stroke-width (इसे हेक्स स्ट्रिंग के तौर पर दिखाया जाता है.)
  • size
  • visible (बिंदु दिख रहा है या नहीं.)

ओपैसिटी को किसी स्टाइल से नहीं, बल्कि dataOpacity विकल्प से कंट्रोल किया जाता है.