douzhizao0270 2011-11-02 18:55
浏览 31

MySQL日期在Highstock中显示为年份

I have a Highstock graph and I've got the data from a MySQL database like is shown in this example.

The date field is a MySQL timestamp. When I situate the cursor over a value, only the year is shown instead of (Day, month day, year).

Any idea about why only the year is shown?

I'm using Codeigniter framework and the server side code looks like:

        $sql = "SELECT UNIX_TIMESTAMP(sop_date)*1000 AS sop_date, sop_price
                FROM share
                INNER JOIN share_operation
                    ON share_operation.sop_idsha = share.sha_id
                INNER JOIN share_operation_type
                    ON share_operation_type.sot_id = share_operation.sop_idsot";

        $params = array($sha_idcon, $sha_idwal);
        $query = $this->db->query($sql, $params);

        if ($query->num_rows() > 0) {
            $data = array();

            foreach ($query->result() as $i => $row) {
                $data[] = "[$row->sop_date, $row->sop_price]";
            }

            return ($data);
        }

Client side:

$(document).ready(function() {

      Highcharts.setOptions({
         lang: {
             months: ['Gener', 'Febrer', 'Març', 'Abril', 'Maig', 'Juny',
                    'Juliol', 'Agost', 'Setembre', 'Octubre', 'Novembre', 'Desembre'],
             weekdays: ['Dilluns', 'Dimarts', 'Dimecres', 'Dijous', 'Divendres', 'Dissabte', 'Diumenge'],
             rangeSelectorFrom: 'Des de',
             rangeSelectorTo: 'Fins'
         }
      });


      window.chart = new Highcharts.StockChart({
         chart : {
            renderTo : 'graphic'
         },

         rangeSelector : {
            selected : 1
         },

         title : {
            text : 'Xisco'
         },

         xAxis : {
            maxZoom : 14 * 24 * 3600000 // fourteen days
         },

         series : [{
            name : 'Xisco',                       
            data :  [<?php echo join($data, ',') ?>],                           
            tooltip: {
               yDecimals: 2
            }
         }]
      });
          });
  • 写回答

1条回答 默认 最新

  • dongliao8069 2011-11-04 10:07
    关注

    Enforcing a formatting might solve this issue.

    tooltip: {
       formatter: function() {
          return Highcharts.dateFormat('%e. %b %Y', this.x);
       }
    }
    

    More information is in the documentation. Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,