读书人

Highcharts 汉语言文档翻译

发布时间: 2012-08-21 13:00:21 作者: rapoo

Highcharts 中文文档翻译

?

While the jQuery adapter is built into Highcharts and Highstock, the MooTools adapter and the Prototype adapter has to be included separately. Use this code to include Highcharts with MooTools:(因为jQuery适配器是内建于Hightcharts和Highstock,MooTools适配器和Prototype适配器要分开导入。使用以下的代码导入MooTools适配器。)
<script src="https://ajax.googleapis.com/ajax/libs/mootools/1.4.2/mootools-yui-compressed.js" type="text/javascript"></script><script src="/js/adapters/mootools-adapter.js" type="text/javascript"></script><script src="/js/highcharts.js" type="text/javascript"></script>
and use this code to include Highcharts with Prototype:(使用以下的代码去导入prototype适配器。)
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js" type="text/javascript"></script><script src="/js/adapters/prototype-adapter.js" type="text/javascript"></script><script src="/js/highcharts.js" type="text/javascript"></script>
If you're installing Highstock, the procedure is the same as above, except the JavaScript file name is highstock.js rather than highcharts.js.?*) Highcharts version 1.x relied on excanvas.js for rendering in IE. From Highcharts 2.0 (and all Highstock versions) IE VML rendering is build into the library.(安装Highstorck的时候,步骤和上面的一致,除了Javascript文件的名字是highcharts.js而不是highcharts.js.*。也就是说要用具体版本的hightcharts.js.*替换highcharts.js)
  • In a?script?tag in the?head?of your web page, or in a separate .js file, add the JavaScript code to initialize the chart. Note that the id of the div where you want to put the chart (see #3) is given in the?renderTo?option below:(在页面的head标签里的script标签中,或者在一个单独的.js文件里,添加以下代码去初始化图表。需要注意的时,你想放置图表所在div的id会被设置在下面代码中的renderTo?项:)
    var chart1; // globally available$(document).ready(function() {      chart1 = new Highcharts.Chart({         chart: {            renderTo: 'container',            type: 'bar'         },         title: {            text: 'Fruit Consumption'         },         xAxis: {            categories: ['Apples', 'Bananas', 'Oranges']         },         yAxis: {            title: {               text: 'Fruit eaten'            }         },         series: [{            name: 'Jane',            data: [1, 0, 4]         }, {            name: 'John',            data: [5, 7, 3]         }]      });   });
    The code above uses the jQuery specific way of launching code on document ready, as explained at the?jQuery website. If you use MooTools, instead of the$(document).ready()?syntax you do it slightly differently:(上面的代码使用jQuery自己的加载方法,这是在文档加载完成后执行,可以看jQuery website里的解释。如果你使用MooTools,会略有不同,就要用以下的代码去替换$(document).ready()??这样的语法。)
    <script type="text/javascript">   window.addEvent('domready', function() {      var chart1 = .......
    If you're inserting a Stock chart, there is a separate constructor method called?Highcharts.StockChart. In these chart, typically the data is supplied in a separate JavaScript array, either taken from a separate JavaScript file or by an Ajax call to the server.(如果你正在安装一个柱状图表,有一个单独的构造方法Highcharts.StockChart。通常在这里图表里,数据会是由一个单独的Javascript数组提供,也可以是一个单独的Javascript文件,或者用Ajax调用服务器里的数据。)
    var chart1; // globally available$(document).ready(function() {      chart1 = new Highcharts.StockChart({         chart: {            renderTo: 'container'         },         rangeSelector: {            selected: 1         },         series: [{            name: 'USD to EUR',            data: usdtoeur // predefined JavaScript array         }]      });   });
  • Add a div in your webpage. Give it an id refering to the renderTo option in #2, and set a specific width and height which will be the width and height of your chart.(添加一个div到你的页面中。给它设置一个id,要和#2里的renderTo选项对应。并且指定宽度和高度,这是图表的宽高。 )
    <div id="container" style="width: 100%; height: 400px"></div>
  • Optionally, you can apply a global theme to your charts. A theme is just a set of options that are applies globally through the Highcharts.setOptions method. The download package comes with four predefined themes. To apply a theme from one of these files, add this directly after the highcharts.js file inclusion:(另外,你可以给你的图表应用一个全局主题。一个主题就是一个选项值的集合,该选项值通过调用Highcharts.setOptions方法后会被全局应用。下载下面的包中有四个预置的主题,要应用其中的一个,在导入highcharts.js文件的后面直接添加上。)
    <script type="text/javascript" src="/js/themes/gray.js"></script>
    2. 如何设置选项How to set up the options

    Highcharts uses a JavaScript object structure to define the options. The options are nested into categories. The options are mainly strings and numbers, but some are arrays, other objects or even functions. When you initialize the chart using?new Highcharts.Chart, the options object is the first parameter you pass.(Highcharts使用一个Javascript对象结构去定义这些选项。选项被内嵌入分类。选项主要是字符串和数值,但有些是数组、其它对象甚至是方法。当你使用new Highcharts.Chart去初始化图表时,该选项对象是你第一个要传的参数。)

    If you want to apply a set of options to all charts on the same page, use?Highcharts.setOptions?like shown below.(如果你想要去应用一个选项集合到同一个页面中的所有图表,就像下面那样子使用Highcharts.setOptions。)

    See #3 above for an example of an options object. For more examples see the?Highcharts demo gallery?or the?Highstock demo gallery. For a full reference of the options available, see the?Highcharts options reference?and the?Highstock options reference.(看上面的#3的一个选项对象例子,更多的例子就看。。。。。。)

    3. 理解轴的概念Understanding axes

    Many of the examples in the Highcharts demo come with an xAxis with categories. However, it is important to understand when to use categories and when you are better off with a linear or datetime xAxis.(在Highcharts demo里的很多例子是和x轴和分类相关的。但是去理解什么时候去使用分类和什么时候去更好地使用线性或者一个时间x轴是很重要的。)

    Categories are groups of items, like for example "Apples", "Pears" and "Oranges", or "Red", "Green", "Blue", "Yellow". These categories have that in common that there are no intermediate values (there's no sliding transition between apples and pears). Also, if you leave one category out, the user isn't able to understand what is left out. Say if you print every second color of "Red", "Green", "Blue" or "Yellow", the user won't know what colors are missing. Therefore, Highchars doesn't have automatic methods to hide categories if they become to dense on the axis. If you have problems with overlapping axis labels, try either the?xAxis.labels.staggerLines?option, or give the labels a?rotation. If you find that you can skip category labels by the?xAxis.labels.step?option, chances are that you are better off using a linear or datetime axis.(分类就是一个项目的组合,像“Apples”,"Pears"和“Oranges”, 或者就是“Red”, "Green", "Blue", "Yellow"。这些分类有这样的共同点,它们都没有模棱两可的值,即在apples和pears里没有中间值。同样的,如果你)

    An xAxis of the?linear or datetime type?has the advantage that Highcharts is able to determine how close the data labels should be because it knows how to interpolate. The labels will by default be placed with approximately 100px between them, which can be changed in the?tickPixelInterval?option. If you have predictable categories like "Item1", "Item2", "Item3" or "2012-01-01", "2012-01-02", "2012-01-03" etc., linear or datetime axis types combined with anxAxis.labels.formatter?would probably be a better choice.(一个坐标或者日期时间类型的X轴有如下优势,Highcharts可以确定数据标签如何关闭,因为它知道如何插入数据。该标签会默认地相隔大约100像素左右放置,并且可以根据tickPixelInterval?选项改变。如果你已经你已经大概确定分类会像是"Item1","Item2","Item3"或者"2012-01-01", "2012-01-02", "2012-01-03"?等,那么坐标轴或者时间轴可以和xAxis.labels.formatter相结合,这会是一个更好的选择。)

    4. 预处理选项Preprocessing the options

    To get the most out of Highcharts, it is important to understand how the configuration object works and how it can be altered programmatically. These are some key concepts on JavaScript objects:(为了更好地使用Highcharts,理解配置对象是如何作用,和它可以如何改写是很重要的。这里有一些关于JavaScript对象的关键概念。)

  • 读书人网 >Web前端

    热点推荐