Высокие диаграммы: изменение размеров шкалы - PullRequest
0 голосов
/ 13 марта 2019

Допустим, у вас есть ось x , которая идет [0, 3, 6, ...] и ось y , которая похожа на [0, 5, 10, ...].

Highcharts обрабатывает эти значения, так что автоматически , так или иначе разница в 5 по оси y не выглядит больше , чем разница3 в направлении x.

Как вы можете изменить расстояния между значениями / сделать 5 на оси у таким же большим, как 5/3 изменения на оси х?(чтобы линия от (0,0) до точки (5,5) имела угол 45 °)

Пример кода:

$.getJSON('https://cdn.jsdelivr.net/gh/highcharts/highcharts@v7.0.0/samples/data/usdeur.json', function (data) {
  Highcharts.chart('container', {
      chart: {
        zoomType: 'x'
      },
      title: {
        text: 'USD to EUR exchange rate over time'
      },
      subtitle: {
        text: document.ontouchstart === undefined ? 'Click and drag in the plot area to zoom in' : 'Pinch the chart to zoom in'
      },
      xAxis: {
        type: 'datetime'
      },
      yAxis: {
        title: {
          text: 'Exchange rate'
        }
      },
      legend: {
        enabled: false
      },
      plotOptions: {
        area: {
          fillColor: {
            linearGradient: {
                x1: 0,
                y1: 0,
                x2: 0,
                y2: 1
            },
            stops: [
                [0, Highcharts.getOptions().colors[0]],
                [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
            ]
          },
          marker: {
            radius: 2
          },
          lineWidth: 1,
          states: {
            hover: {
              lineWidth: 1
            }
          },
          threshold: null
        }
      },
      series: [{
        type: 'area',
        name: 'USD to EUR',
        data: data
      }]
  });
});

взят из demo

1 Ответ

1 голос
/ 14 марта 2019

В событии load вы можете рассчитать и настроить высоту или ширину графика:

chart: {
    events: {
        load: function() {
            var xAxis = this.xAxis[0],
                yAxis = this.yAxis[0];

            // Adjust xAxis
            this.setSize(
                yAxis.height / (yAxis.max - yAxis.min) *
              (xAxis.max - xAxis.min) + this.plotLeft + this.chartWidth -
              (this.plotLeft + this.plotWidth),
              null,
              false
            );
        }
    }
},

Демо: http://jsfiddle.net/BlackLabel/64Lxutce/

или, если вы не хотите изменять размер, вы можете отрегулировать одну из крайностей оси:

chart: {
    events: {
        load: function() {
            var xAxis = this.xAxis[0],
                yAxis = this.yAxis[0],
                xAxisMax = xAxis.width /
                        (yAxis.height / (yAxis.max - yAxis.min)),
                yAxisMax = yAxis.height /
                        (xAxis.width / (xAxis.max - xAxis.min));

            if (xAxisMax < xAxis.max) {
                this.update({
                    yAxis: {
                        max: yAxisMax - yAxis.min
                    }
                }, true, true, false);
            } else {
                this.update({
                    xAxis: {
                        max: xAxisMax - xAxis.min
                    }
                }, true, true, false);
            }
        }
    }
},

Демонстрационная версия: http://jsfiddle.net/BlackLabel/w3byrL28/

Справочник по API:

https://api.highcharts.com/highcharts/chart.events.load

https://api.highcharts.com/class-reference/Highcharts.Chart#update

https://api.highcharts.com/class-reference/Highcharts.Chart#setSize

...