我想用ChartJs多个数据工具提示

时间:2017-01-15 14:21:18

标签: javascript php jquery html css

我想当我悬停点时,它会显示多个工具提示,就像下方图像一样。

我也在向下显示我的代码。

I want to as like this image

My code seems like this.

    <div class="col-sm-6"> <!-- My Html Code -->
        <h4 class="heading">Aylık Tıklanma ve Görüntülenme</h4>
        <canvas id="myLineChart" width="300" height="250"></canvas>
    </div> <!-- My Html Code -->


<div class="">  <!-- My JS-Php Code -->
        <script type="text/javascript">
        var canvas = document.getElementById('myLineChart');
        new Chart(canvas, {
        type: 'line',
        data: {
        labels: ["<?php echo ayGetir("-11"); ?>","<?php echo ayGetir("-10"); ?>","<?php echo ayGetir("-9"); ?>","<?php echo ayGetir("-8"); ?>","<?php echo ayGetir("-7"); ?>","<?php echo ayGetir("-6"); ?>","<?php echo ayGetir("-5"); ?>","<?php echo ayGetir("-4"); ?>","<?php echo ayGetir("-3"); ?>","<?php echo ayGetir("-2"); ?>","<?php echo ayGetir("-1"); ?>","<?php echo ayGetir("now"); ?>"],
        datasets: [{
          label: 'Tıklanma',
          yAxisID: 'A',
          data: ["<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-11")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-10")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-9")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-8")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-7")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-6")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-5")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-4")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-3")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-2")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-1")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("now")); ?>"],
          backgroundColor: "rgba(0,255,0,0.2)",
          pointBorderColor: "rgba(75,192,192,1)",
          pointHoverBackgroundColor: "rgba(75,192,192,1)",
        pointRadius: 4,


          }, {
          label: 'Görüntülenme',
          yAxisID: 'B',
          data: ["<?php echo impGetir($connectDb,$userr,aySayiGetir2("-11")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-10")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-9")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-8")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-7")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-6")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-5")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-4")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-3")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-2")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-1")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("now")); ?>"],
          backgroundColor: "rgba(255,255,0,0.4)",
          pointRadius: 4,
          pointBorderColor: "rgba(75,192,192,1)",
          pointHoverBackgroundColor: "rgba(75,192,192,1)",

        }]
        },
            options: {
                scales: {
                  yAxes: [{
                    id: 'A',
                    type: 'linear',
                    position: 'left',
                  }, {
                    id: 'B',
                    type: 'linear',
                    position: 'right'
                  }]
                }
            }
        });
        </script>

    </div><!-- My JS-Php Code -->

但我想像第一张图片一样,因为我的另一点并没有表现出来。(它留在后面)

如果你知道怎么做,我需要你的帮助。谢谢你的帮助..

1 个答案:

答案 0 :(得分:0)

<强>解决

解决方案在这里;

<div class="">  <!-- line chart -->
        <script type="text/javascript">
        var canvas = document.getElementById('myLineChart');
        new Chart(canvas, {
        type: 'line',
        data: {
        labels: ["<?php echo ayGetir("-11"); ?>","<?php echo ayGetir("-10"); ?>","<?php echo ayGetir("-9"); ?>","<?php echo ayGetir("-8"); ?>","<?php echo ayGetir("-7"); ?>","<?php echo ayGetir("-6"); ?>","<?php echo ayGetir("-5"); ?>","<?php echo ayGetir("-4"); ?>","<?php echo ayGetir("-3"); ?>","<?php echo ayGetir("-2"); ?>","<?php echo ayGetir("-1"); ?>","<?php echo ayGetir("now"); ?>"],
        datasets: [{
          label: 'Tıklanma',
          yAxisID: 'A',
          data: ["<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-11")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-10")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-9")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-8")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-7")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-6")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-5")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-4")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-3")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-2")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("-1")); ?>","<?php echo clickGetir($connectDb,$userr,aySayiGetir2("now")); ?>"],
          backgroundColor: "rgba(0,255,0,0.2)",
          pointBorderColor: "rgba(75,192,192,1)",
          //pointHoverBackgroundColor: "rgba(75,192,192,1)",
          pointRadius: 4,
          fill: false
        },
        {
          label: 'Görüntülenme',
          yAxisID: 'B',
          data: ["<?php echo impGetir($connectDb,$userr,aySayiGetir2("-11")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-10")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-9")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-8")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-7")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-6")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-5")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-4")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-3")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-2")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("-1")); ?>","<?php echo impGetir($connectDb,$userr,aySayiGetir2("now")); ?>"],
          backgroundColor: "rgba(255,255,0,0.4)",
          pointRadius: 4,
          pointBorderColor: "rgba(75,192,192,1)",
          //pointHoverBackgroundColor: "rgba(75,192,192,1)",
          fill: false
        }]
        },
            options: {
                tooltips: { // this code
                    mode: 'label', // this code
                }, // this code
                scales: {
                  yAxes: [{
                    id: 'A',
                    type: 'linear',
                    position: 'left',
                  }, {
                    id: 'B',
                    type: 'linear',
                    position: 'right'
                  }]
                }
            }
        });
        </script>

    </div>

Yeahha :) (Seem like this)