股票图表时间轴按钮和日期字段左对齐图表

时间:2017-12-13 07:09:29

标签: button highcharts highstock datefilter leftalign

我需要指南制作我的图表,如附带的屏幕截图所示。 我一直在使用HighCharts,但无法找到合适的选项或配置。以下是我所需设计的屏幕截图:

enter image description here

我还将小提琴链接附加到我用于实现这些设计要求的当前实现。

My Fiddle

HTML:

"apps" : [
    ...
    ...
    "styles" : [
       "styles.css",
       "css/Styles.less"
    ]
]

JavaScript的:

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<div id="container" style="height: 400px; min-width: 310px"></div>

如果有人可以指导我做正确的配置或造型来实现这一点。

感谢。

2 个答案:

答案 0 :(得分:1)

我能够得到this far. Highcharts x,y坐标使用起来有点难度,但你需要在buttonPositioninputPosition和{{{{}}上做更多样式1}} (see screenshot)将它们移到右侧:

HTML:

Title

JavaScript的:

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js">
</script>
<div id="container" style="height: 400px; min-width: 310px"></div>

图例似乎没有呈现 - 请检查以确保您的数据格式正确,并尝试使用Highcharts.stockChart('container', { chart: { marginLeft: 300, }, navigator: { enabled: false }, scrollbar: { enabled: false }, title : { text : 'Activity', x: -280 }, rangeSelector: { x: 0, verticalAlign: 'middle', buttonPosition: { align: 'left', y: 20, x: -140 }, inputPosition: { align: 'left', y: 15, x: -280 }, allButtonsEnabled: true, buttons: [{ type: 'month', count: 3, text: 'Daily', dataGrouping: { forced: true, units: [['day', [1]]] } }, { type: 'year', count: 1, text: 'Weekly', dataGrouping: { forced: true, units: [['week', [1]]] } }, { type: 'all', text: 'Monthly', dataGrouping: { forced: true, units: [['month', [1]]] } }], buttonTheme: { width: 60 }, selected: 2 }, legend: { width: 100, align: 'left', x: 0, // = marginLeft - default spacingLeft y: -100, itemWidth: 100, borderWidth: 1 }, xAxis: { type: 'datetime', dateTimeLabelFormats: { month: '%e. %b', year: '%b' } }, series: [{ name: 'Label 1', color: "#00aade", data: [[1501545600000, 5], [1504224000000,4], [1506816000000, 6],[1509494400000,5]] }, { name: 'Label 2', color: "#8cc63e", data: [[1501545600000, 1], [1504224000000,0], [1506816000000, 2],[1509494400000,0]] }] }); x

答案 1 :(得分:1)

这是我能得到的最接近的

http://jsfiddle.net/0yax1bav/5/

在左侧添加间距:

chart: {
    spacingLeft: 300,
},

将图例移到左侧:

legend: {
    enabled: true,
    align: 'left',
    verticalAlign: 'top',
    layout: 'vertical',
    x: -250,
    y: 150
},

将标题移到左侧:

title : {
    align: 'left',
    x: -280,
    text : 'Activity',
    floating: true
},

向左移动范围:

rangeSelector: {
    floating: true,
    x: 0,
    verticalAlign: 'middle',
    buttonPosition: {
        align: 'left',
        y: 20,
        x: -140
    },
    inputPosition: {
        align: 'left',
        y: 15,
        x: -280
    },
    ...

禁用导出按钮:

exporting:{
    buttons:{
        contextButton: {
            enabled: false
        }
    }
}
Highcharts.stockChart('container', {
  chart: {
    spacingLeft: 300,
  },
  legend: {
        enabled: true,
        align: 'left',
        verticalAlign: 'top',
        layout: 'vertical',
        x: -250,
        y: 150
    },
  navigator: {
    enabled: false
  },
  scrollbar: {
    enabled: false
  },
  exporting:{
    buttons:{
        contextButton: {
            enabled: false
        }
    }
  },
  title : {
    align: 'left',
    x: -280,
    text : 'Activity',
    floating: true
  },
  rangeSelector: {
    floating: true,
    x: 0,
    verticalAlign: 'middle',
    buttonPosition: {
            align: 'left',
            y: 20,
            x: -140
        },
    inputPosition: {
           align: 'left',
           y: 15,
           x: -280
    },
    allButtonsEnabled: true,
    buttons: [{
      type: 'month',
      count: 3,
      text: 'Daily',
      dataGrouping: {
        forced: true,
        units: [['day', [1]]]
      }
    }, {
      type: 'year',
      count: 1,
      text: 'Weekly',
      dataGrouping: {
        forced: true,
        units: [['week', [1]]]
      }
    }, {
      type: 'all',
      text: 'Monthly',
      dataGrouping: {
        forced: true,
        units: [['month', [1]]]
      }
    }],
    buttonTheme: {
      width: 60
    },
    selected: 2
  },
  xAxis: {
    type: 'datetime',
    dateTimeLabelFormats: {
      month: '%e. %b',
      year: '%b'
    }
  },
  series: [{
    name: 'Label 1',
    color: "#00aade",
    data: [[1501545600000, 5], [1504224000000,4], [1506816000000, 6],[1509494400000,5]]
  },
  {
    name: 'Label 2',
    color: "#8cc63e",
    data: [[1501545600000, 1], [1504224000000,0], [1506816000000, 2],[1509494400000,0]]
  }]
});