【问题标题】:Sencha Touch 2.1 changing cartesian chart axis values as whole numbersSencha Touch 2.1 将笛卡尔图表轴值更改为整数
【发布时间】:2013-03-18 13:47:51
【问题描述】:

Hi
我正在使用 sencha touch 2.1.1 图表以笛卡尔图表格式显示投票结果。我将轴类型指定为“整数”。我给图表商店的输入值总是只有整数(比如 1,2,3...)。但是绘制的图形轴包含小数,但我的轴不需要小数。
如何解决这个问题。提前致谢。

Ext.define("KBurra1.view.PollChart",{
extend:"Ext.chart.CartesianChart",
requires:['Ext.data.JsonStore','Ext.chart.axis.Numeric','Ext.chart.axis.Category','Ext.chart.series.Bar'],
config:{
    store:null,
//id:"poll_chart",
height:'200px',
flipXY: true,
axes: [{
    type: 'numeric',
    minimum:0,
    //maximum:3,
    //increment:1,
    position: 'bottom',
    title: 'Number of Votes',
    grid: {
        odd: {
            opacity: 1,
            fill: '#dddc',
            stroke: '#bbb',
            lineWidth: 1
        },

    },



}, {
    type: 'category',
    position: 'left',
    grid: true,
    label: {
        rotate: {
            degrees:330
        },

    }
}],
series: [{
    //title : ['data1'],
    type: 'bar',
    xField: 'answer',
    yField: ['votecount'],
    style: {

        fill:'#57a4f7',
        minGapWidth:5,

    },
    stacked : false
}]
}

});

【问题讨论】:

  • 我不明白你的意思,所以你想要 1,2,3,4 而不是 0.00、0.05、0.10、0.15?
  • 你是对的。我需要 1、2、3、4 而不是 0.00、0.05、0.10、0.15。如果你知道帮我解决这个问题。
  • 有时投票数是 2 或 3 的意思,如果我们将最大值设置为 20,则条形的长度在移动设备中非常小。

标签: sencha-touch-2 sencha-charts


【解决方案1】:

您可以使用内置的 javascript 函数“toFixed(0)”,这将给它 0 个小数位。此外,如果您想要 1 个小数位,只需输入 1 而不是 0。

要在图表中使用它,请使用一个小函数将渲染属性添加到轴上。在我的应用程序中,我处理数以百万计的数字,所以我除以 1000000,然后只显示 1 个小数。

axes: [
                {
                    type: 'numeric',
                    position: 'left',
                    fields: ['population','phones'],
                    minimum: 0,
                    renderer: function (value) {
                                value = value / 1000000;
                                return value.toFixed(1);
                            },
                    grid: true
                },

在您的情况下,只需乘以 100 并使用 toFixed(0)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    相关资源
    最近更新 更多