【问题标题】:How to correct index and current date如何更正索引和当前日期
【发布时间】:2022-06-16 19:24:05
【问题描述】:

这个 highcharts 图表库出现以下错误。 我需要将日期更新为当前日期,并且相应日期的日期会出现在索引中。

只需从 Highcharts.chart 更改为 Highcharts.stockChart。 (附图)

enter image description here

enter image description here

从这里带来数据和图表

function datagrafico(base_url){
                                        
 $.ajax({
   url: base_url + "index.php/Admin/getDataDias",
   type:"POST",
   dataType:"json",
   success:function(data){
      var dias = new Array();
      var montos = new Array();
      $.each(data,function(key, value){
           dias.push(value.fecha_actualizacion);
           valor = Number(value.monto);
           montos.push(valor);
        });
        graficar(dias,montos);
        }
       });
      }

function graficar(dias, montos){
                                        
                                        
    Highcharts.stockChart('grafico', {
      chart: {
      renderTo: 'container',
      type: 'column'
    },
    title: {
       text: 'Monto acumulado por ventas diarias'
    },
    subtitle: {
        text: ''
    },
    xAxis: {
        categories: dias,
        crosshair: true
        },
                                        
    yAxis: {
        min: 0,
        title: {
            text: 'Monto Acumulado (Colombiano)'
        }
    },
                                        
    tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">Monto: </td>' +
            '<td style="padding:0"><b>{point.y} Colombiano</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
    },
    plotOptions: {
            column: {
                pointPadding: 0,
                borderWidth: 0
            },
            series:{
                dataLabels:{
                        enabled:true,
                        formatter:function(){
                        return Highcharts.numberFormat(this.y)
                }

            }
        }
    },
    rangeSelector: {
            inputPosition: {
                align: 'right',
                x: 0,
                y: 0
            },
        },
        series: [{
            name: 'dias',
            data: montos

        }]
    });

控制器:

public function getDataDias(){
        
        $resultados = $this->model_venta->montos();
        echo json_encode($resultados);
    }

和型号:

public function montos(){
    $this->db->select("fecha_actualizacion, SUM(total) as monto");
    $this->db->from("venta");
    $this->db->where("pago_id","2");
    $this->db->where("estado","1");
    $this->db->group_by('DATE(fecha_actualizacion)');
    $this->db->order_by('DATE(fecha_actualizacion)');
    $resultados = $this->db->get();
    return $resultados->result();
}

【问题讨论】:

    标签: php codeigniter charts highcharts


    【解决方案1】:

    在您的示例中,您将 Highcharts 更改为 Higcharts Stock,它们相似但从其他 API 构建图表。请查看 Stock documentation 他们,在 xAxis 中没有类别选项。

    Highcharts Stock 轴的标准数据格式为毫秒格式,您需要更改数据格式才能放入图表中。

       series: [{
         type: 'column',
         data: [
           [1592314200000, 165428800],
           [1592400600000, 114406400],
           [1592487000000, 96820400],
           [1592573400000, 264476000],
           [1592832600000, 135445200],
           [1592919000000, 212155600]
         ],
       }]
    

    下面是用于比较建筑的 Highchart 和 Higcharts Stock 示例。

    Highchart 演示:https://jsfiddle.net/BlackLabel/sw3qr5p9/

    Highchart 股票演示:https://jsfiddle.net/BlackLabel/drnup1tx/

    【讨论】:

      猜你喜欢
      • 2022-07-06
      • 1970-01-01
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-23
      相关资源
      最近更新 更多