Skip to content
/ Chart.js Public
  • Notifications
  • Fork 11.9k
  • Star 63.6k
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jump to bottom

Reverse Scale? #129

Closed
midnyt-simlyn opened this issue Jun 1, 2013 · 19 comments
Closed

Reverse Scale? #129

midnyt-simlyn opened this issue Jun 1, 2013 · 19 comments
Labels
type: enhancement
Milestone
Rewrite axis/scal...

Comments

@midnyt-simlyn
Copy link

midnyt-simlyn commented Jun 1, 2013

Trying to make a graph where the scale goes from 1-20 from top top bottom (for a chart over league positions), is that possible?

@nnnick
Copy link
Member

nnnick commented Jun 5, 2013

Not right now. I'm currently collating features for the next major library release.

If you have some ideas on how an API for this feature could work let me know.

@thetaylor82
Copy link

thetaylor82 commented Feb 10, 2014

I need this urgently. Is this project dead?

@djn72
Copy link

djn72 commented Aug 2, 2014

This would be really useful, I have a simlar case where I want to display a graph of league positions over several weeks and the ability to "invert the scale" would be very useful.

Wondering if anyone is looking at adding an option to implement this?

I have hacked my data to achieve the results I want, but it's not pretty...

(1) invert my data sources by multiplying all data points by -1

(2) override the data labels with tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= (value * -1 ) %>"

(3) override the scale labels with scaleLabel: "<%=(value * -1)%>"

Someone else might find this workaround useful in the meantime.....

@reinvanleirsberghe
Copy link

reinvanleirsberghe commented Nov 26, 2014

+1

@ympbyc
Copy link

ympbyc commented Dec 11, 2014

Passing a negative value as scaleStepWidth worked for me.

chart.Line({......}, {
  scaleOverride: true,
  scaleSteps: 19,
  scaleStepWidth: -1,
  scaleStartValue: 20
});

@fulldecent fulldecent added the type: enhancement label Dec 29, 2014
@fulldecent fulldecent modified the milestone: Rewrite axis/scale code Mar 17, 2015
@fulldecent fulldecent removed the Potential label Mar 17, 2015
@derekperkins
Copy link
Contributor

derekperkins commented Jun 4, 2015

@praxeum Try @ympbyc 's solution in conjunction with the easier config of 2.0. The first alpha of Chart.js 2.0 has landed and should fix this issue. Check out the release and try it out! We've got a lot of momentum right now, so please help us test so we can launch 2.0 Gold by the end of the month.
https://github.com/nnnick/Chart.js/releases/tag/v2.0-alpha

I'm closing this issue for now, but if you have implementation questions or find bugs, please create a jsfiddle and post the link here and we'll reopen this issue and get it fixed.

@derekperkins derekperkins closed this as completed Jun 4, 2015
@rclations
Copy link

rclations commented Jun 15, 2015

I'm sorry if I'm totally missing something here, but scaleStepWidth doesn't appear to be anywhere in the 2.0-alpha codebase. Any idea how I can get this working?

@etimberg
Copy link
Member

etimberg commented Jun 15, 2015

@rclations I believe it got renamed. In your config, you could do something like the following

config = {
    scales: {
        yAxes: [{
            override: {
                 start: 10,
                 steps: 10,
                 stepWidth: -1
            }
        }]
    }
}

This is the code that uses it.

@rclations
Copy link

rclations commented Jun 15, 2015

thanks for the quick reply!

I dug around some more and found that it could be done like this in a kind of hacky way -

        var options = {
            scales: {
                yAxes: [
                    {
                        beginAtZero: true,
                        labels: {
                            userCallback: function(tick, index, ticks) {
                                return Math.abs(tick);
                            }
                        }
                    }
                ]
            }
        };

The override option has a bug in it - I'm getting a js error because the value is set to null in the source, so it doesn't like me passing an object.

Regardless, the override object would only let me really customize steps so I could prevent decimals in y-axis labels - I didn't find anything that would invert the scale. stepWidth does change the labels to step negatively, but doesn't change the chart data with it.

@etimberg
Copy link
Member

etimberg commented Jun 15, 2015

I'll look into the bugs tonight. It might just be easier to add a reverse option to the scale. Thanks for trying it out!

@rclations
Copy link

rclations commented Jun 15, 2015

you bet - having a reverse option on the scale would be fantastic

@rclations
Copy link

rclations commented Jul 9, 2015

any news on this? Could we reopen this ticket until this gets resolved?

@etimberg
Copy link
Member

etimberg commented Jul 10, 2015

@rclations I added a reverse option to the linear scale config in 76d2a78

var options = {
    scales: {
        yAxes: [
            {
                reverse: true, // will reverse the scale
            }
        ]
    }
};

@aaron-coding aaron-coding mentioned this issue Oct 9, 2016
Chart.js reverse yAxes option not transferring over ankane/chartkick#296
Closed
@nightwolfy
Copy link

nightwolfy commented Mar 17, 2017

To draw the y axes from top to down try this. This works for me

yAxes: [{
        ticks: {
          beginAtZero: true,
          reverse: true,
        },
        display: true,

      }]

@abddu1
Copy link

abddu1 commented Dec 4, 2017

Can the xAxis direction be reversed? We need it for RTL languages, to show the chart right to left, is this possible any other way?

@juniorcintra
Copy link

juniorcintra commented May 8, 2019

Can the xAxis direction be reversed? We need it for RTL languages, to show the chart right to left, is this possible any other way?

Any help? I need this too!

@kurkle
Copy link
Member

kurkle commented May 8, 2019

Same reverse option should work there (has been moved under ticks):

var options = {
  scales: {
    xAxes: [{
      ticks: {
        reverse: true, // will reverse the scale
      }
    }]
  }
};

@juniorcintra
Copy link

juniorcintra commented May 8, 2019

Same reverse option should work there (has been moved under ticks):

var options = {
  scales: {
    xAxes: [{
      ticks: {
        reverse: true, // will reverse the scale
      }
    }]
  }
};

I resolved this, but not on the chart.js configuration, but directly on javascript, before sent the arrays to the chart.js, using .reverse() function! :)

@DevidCIC
Copy link

DevidCIC commented Jun 14, 2019

@rclations I added a reverse option to the linear scale config in 76d2a78

var options = {
    scales: {
        yAxes: [
            {
                reverse: true, // will reverse the scale
            }
        ]
    }
};

This does not work for me, I have the 2.8.0 chart.js version. Anyone else with the same problem ?
Even if I put it under ticks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement
Projects
None yet
Development

No branches or pull requests

15 participants
@fulldecent @ympbyc @midnyt-simlyn @nnnick @thetaylor82 @rclations @derekperkins @reinvanleirsberghe @etimberg @djn72 @nightwolfy @abddu1 @DevidCIC @kurkle @juniorcintra

Footer

© 2024 GitHub, Inc.

两个鬼故事芊字起名的寓意汉正街小商品市场免费好使用的起名软件瑞字起名长津湖百度云资源亲爱的自己剧情介绍韭黄的做法刘德华恭喜发财歌词邓姓男人起名商标起名技巧如何给家纺店铺起名跨国公司起名起名字男孩2020免费八字测名口留香雪中送炭的意思新能源领域的科技公司起名码字精灵海 字起名黎米京廷全文免费阅读无弹窗酒庄起名叫什么好营养早餐加盟欧洲裸妇图片大全属羊的今年多大了大米商标起名字大全无限之虫族降临炒鸡的店铺起名大全游乐公司起名大全女孩起名鼠年芭比之仙子的秘密全集卖鸡的店铺起名大全少年生前被连续抽血16次?多部门介入两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”淀粉肠小王子日销售额涨超10倍高中生被打伤下体休学 邯郸通报单亲妈妈陷入热恋 14岁儿子报警何赛飞追着代拍打雅江山火三名扑火人员牺牲系谣言张家界的山上“长”满了韩国人?男孩8年未见母亲被告知被遗忘中国拥有亿元资产的家庭达13.3万户19岁小伙救下5人后溺亡 多方发声315晚会后胖东来又人满为患了张立群任西安交通大学校长“重生之我在北大当嫡校长”男子被猫抓伤后确诊“猫抓病”测试车高速逃费 小米:已补缴周杰伦一审败诉网易网友洛杉矶偶遇贾玲今日春分倪萍分享减重40斤方法七年后宇文玥被薅头发捞上岸许家印被限制高消费萧美琴窜访捷克 外交部回应联合利华开始重组专访95后高颜值猪保姆胖东来员工每周单休无小长假男子被流浪猫绊倒 投喂者赔24万小米汽车超级工厂正式揭幕黑马情侣提车了西双版纳热带植物园回应蜉蝣大爆发当地回应沈阳致3死车祸车主疑毒驾恒大被罚41.75亿到底怎么缴妈妈回应孩子在校撞护栏坠楼外国人感慨凌晨的中国很安全杨倩无缘巴黎奥运校方回应护栏损坏小学生课间坠楼房客欠租失踪 房东直发愁专家建议不必谈骨泥色变王树国卸任西安交大校长 师生送别手机成瘾是影响睡眠质量重要因素国产伟哥去年销售近13亿阿根廷将发行1万与2万面值的纸币兔狲“狲大娘”因病死亡遭遇山火的松茸之乡“开封王婆”爆火:促成四五十对奥巴马现身唐宁街 黑色着装引猜测考生莫言也上北大硕士复试名单了德国打算提及普京时仅用姓名天水麻辣烫把捣辣椒大爷累坏了

两个鬼故事 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化