简体   繁体   English

如何格式化ExtJs图表轴?

[英]Howto format ExtJs chart axes?

I create a ExtJs chart with the following code and unfortunately I do not know how to style the xAxis and yAxis. 我使用以下代码创建一个ExtJs图表,不幸的是我不知道如何设置xAxis和yAxis的样式。 Could not find any help in the ExtJs documentation. 在ExtJs文档中找不到任何帮助。

Ext.create('Ext.chart.Chart', {
       renderTo: div,
       theme: 'Browser:gradients',
       width: div.offsetWidth,
       height: div.offsetHeight,
       animate: true,
       store: store,
       axes: [
              {
                  title: 'Number of Ratings',
                  type: 'Numeric',
                  position: 'left',
                  fields: ['data1', 'data2', 'data3'],
                  minimum: 0,
                  tips: {
                      trackMouse: true,
                      width: 110,
                      height: 25,
                      renderer: function (storeItem, item) {
                          this.setTitle(storeItem.get('name');
                      }
                  },
              },
              {
                  title: 'Rating Categories',
                  type: 'Category',
                  position: 'bottom',
                  fields: ['name'],
              }
          ],
       series: [
                {
            type: 'column', 
            title: createLegendTitles(response.ratingResults),
            xField: 'name',
            yField: ['data1','data2', 'data3'],
        }
       ],
});

How can I format the xAxis and the yAxis of the chart? 如何格式化图表的xAxis和yAxis? (eg setting colors, font size, font family, etc.) (例如设置颜色,字体大小,字体系列等)

Unfortunately, the Sencha documentation for this is either vague or incomplete. 不幸的是,Sencha的文档要么含糊不清,要么不完整。 Sometimes, you'll end up finding a particular feature by viewing the chart examples. 有时,您最终会通过查看图表示例来查找特定功能。 Other times, you have to go source diving. 其他时候,你必须去潜水源。 It's frustrating, I know. 我知道,这令人沮丧。

It sounds like you're trying to customize the styles of the axis labels. 听起来你正在尝试自定义轴标签的样式。 There's a config called label (shown in the example code on the documentation for Ext.chart.axis.Axis , but not in the config). 有一个名为label的配置(显示在Ext.chart.axis.Axis文档的示例代码中,但不在配置中)。 It takes an object of type Ext.chart.Label which itself has configs for color, font, orientation, a custom renderer function, rotation, display position, etc. You can get a summary here , but it too is rather incomplete. 它需要一个Ext.chart.Label类型的对象,它本身具有颜色,字体,方向,自定义渲染器功能,旋转,显示位置等的配置。您可以在此处获得摘要,但它也相当不完整。

If there's something else you're looking for, I can do what I can to point you in the right direction. 如果您正在寻找其他东西,我可以尽我所能为您指明正确的方向。 I've spent hours looking over the source code for my own project at work looking for answers just like this. 我花了几个小时查看我自己的项目的源代码,寻找像这样的答案。

EDIT: To edit the axis line itself, you may have to do some overriding/extending of the Ext.chart.axis.Axis class. 编辑:要编辑轴线本身,您可能需要对Ext.chart.axis.Axis类进行一些覆盖/扩展。 At the bottom of the drawAxis method, there's some code that looks like this: drawAxis方法的底部,有一些代码如下所示:

if (!me.axis) {
    me.axis = me.chart.surface.add(Ext.apply({
        type: 'path',
        path: path
    }, me.axisStyle));
}

It looks like that's where you want to add your code for applying styles to the axis. 看起来这就是您要添加代码以将样式应用于轴的位置。 The me.axisStyle property doesn't actually get set in the Axis class as far as I can tell, so you'll have to hunt around for it. 据我所知, me.axisStyle属性实际上并没有在Axis类中设置,因此你将不得不寻找它。 It may be a manual setting in the axis config, it may be generated by themes, or something else entirely. 它可能是轴配置中的手动设置,可能是由主题生成的,或者完全是其他内容。

This might work 这可能会奏效

axes: [
    {
        title: 'Number of Ratings',
        label: {
            renderer: function(v){
                return '<span class="numRatingsAxis">' + v + '</span>';
            }
        }
        ...
    }
]

I would like to supplement the answer here. 我想补充一下这里的答案。 If you're using the new sencha-charts package, you must put the renderer directly on the axis instead of inside of the label. 如果您使用的是新的sencha-charts包,则必须将渲染器直接放在轴上而不是标签内。 Eg: 例如:

axes: [{
    title: 'Number of Ratings',
    renderer: function(v){
        return '<span class="numRatingsAxis">' + v + '</span>';
    }
}]

See https://docs.sencha.com/extjs/5.1/whats_new/5.0/charts_upgrade_guide.html#Renderers 请参阅https://docs.sencha.com/extjs/5.1/whats_new/5.0/charts_upgrade_guide.html#Renderers

我不认为有这个属性,但你可以使用CSS格式化它们。

You can do it by setting the theme on the chart, check out the charting guide: 您可以通过在图表上设置主题来完成,查看图表指南:

http://docs.sencha.com/ext-js/4-0/#/guide/drawing_and_charting http://docs.sencha.com/ext-js/4-0/#/guide/drawing_and_charting

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM