HorizontalBarChart moveViewToX doesn't work
Summary
When using BarChart everything work as expected, but moveViewToX doesn't work on HorizontalBarChart. I've tested with the same code, only changing the XML, and the error is only affecting HorizontalBarChart
I've searched opened issues (most relevant was #2546 which is closed and the proposed solution didn't worked in my case) and searched on StackOverflow but I haven't found a solution yet.
Device:
Device: Xiaomi Redmi Note 4
Android Version 6.0
Library Version 3.1.0-alpha
Here is the code related, is written in Kotlin.
Here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.mikephil.charting.charts.HorizontalBarChart
android:id="@+id/priceAlertsChart"
android:layout_width="match_parent"
android:layout_height="300dp"/>
</LinearLayout>
and the kt file:
override fun onCreate(savedInstanceState: Bundle?) {
val priceAlerts = mutableListOf<PriceChangeInfo>()
for(i in 0..20) {
priceAlerts.add(i,PriceChangeInfo(i.toString()
,Random.nextDouble(-2.5,2.5)))
}
showPercentChangeDialog(priceAlerts.toTypedArray(), Date().time)
}
@SuppressLint("InflateParams")
private fun showPercentChangeDialog(priceChangeInfo:Array<Parcelable>?, lastUpdate:Long)
{
val items = priceChangeInfo?.map {
it as PriceChangeInfo
}?.reversed() ?: return
val v = layoutInflater.inflate(R.layout.price_alerts_dialogos,null)
// v.lastUpdateTextView.text=getString(R.string.changes_since,timeLapse(lastUpdate))
v.priceAlertsChart.apply {
xAxis.apply {
position = XAxis.XAxisPosition.BOTTOM
setDrawAxisLine(true)
setDrawGridLines(false)
granularity = .3f
labelCount = if(items.size>10)10 else items.size
valueFormatter = IAxisValueFormatter { value, _ ->
items[value.toInt()].symbol
}
}
withMultiple(axisLeft,axisRight){
setDrawAxisLine(true)
setDrawGridLines(true)
}
legend.isEnabled = false
setDrawBarShadow(false)
//setDrawValueAboveBar(true)
description.isEnabled = false
setPinchZoom(false)
setDrawGridBackground(false)
data = {
val green = Color.rgb(110, 190, 102)
val red = Color.rgb(211, 74, 88)
val entries = mutableListOf<BarEntry>()
val colors = mutableListOf<Int>()
items.forEachIndexed { index, info ->
colors.add(if(info.change>0) green else red)
entries.add(BarEntry(index.toFloat(),info.change.toFloat(),info.symbol))
}
val set1 = BarDataSet(entries,"changes").apply {
setDrawIcons(false)
setDrawValues(false)
setColors(colors)
valueFormatter = IValueFormatter {
_, entry, _, _ ->
formatNumber(entry.y.toDouble(),false,false,decimals = 2)+"%"
}
}
val dataSets = mutableListOf<IBarDataSet>().apply {
add(set1)
}
BarData(dataSets).apply {
setValueTextSize(10f)
barWidth = .4f
}
}()
setVisibleXRangeMaximum(10f)
//this doesn't work on HorizontalBarChart
moveViewToX(data.entryCount.toFloat())
}
AlertDialog.Builder(this).setTitle(R.string.price_alerts).setView(v)
.setPositiveButton(R.string.ok) { _: DialogInterface, _: Int ->
intent?.extras?.clear()
}.show()
}
//dependencies
fun<T> withMultiple(vararg args: T, block: T.() -> Unit) {
args.forEach {
it.apply (block)
}
}
data class PriceChangeInfo(var symbol:String, var change:Double):Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString()!!,
parcel.readDouble()) {}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(symbol)
parcel.writeDouble(change)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<PriceChangeInfo> {
override fun createFromParcel(parcel: Parcel): PriceChangeInfo {
return PriceChangeInfo(parcel)
}
override fun newArray(size: Int): Array<PriceChangeInfo?> {
return arrayOfNulls(size)
}
}
}
I've already opened an issue on github:
https://github.com/PhilJay/MPAndroidChart/issues/4397
Any tip | hack | possible solution will be highly appreciated. Thanks in advance.
mpandroidchart
add a comment |
Summary
When using BarChart everything work as expected, but moveViewToX doesn't work on HorizontalBarChart. I've tested with the same code, only changing the XML, and the error is only affecting HorizontalBarChart
I've searched opened issues (most relevant was #2546 which is closed and the proposed solution didn't worked in my case) and searched on StackOverflow but I haven't found a solution yet.
Device:
Device: Xiaomi Redmi Note 4
Android Version 6.0
Library Version 3.1.0-alpha
Here is the code related, is written in Kotlin.
Here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.mikephil.charting.charts.HorizontalBarChart
android:id="@+id/priceAlertsChart"
android:layout_width="match_parent"
android:layout_height="300dp"/>
</LinearLayout>
and the kt file:
override fun onCreate(savedInstanceState: Bundle?) {
val priceAlerts = mutableListOf<PriceChangeInfo>()
for(i in 0..20) {
priceAlerts.add(i,PriceChangeInfo(i.toString()
,Random.nextDouble(-2.5,2.5)))
}
showPercentChangeDialog(priceAlerts.toTypedArray(), Date().time)
}
@SuppressLint("InflateParams")
private fun showPercentChangeDialog(priceChangeInfo:Array<Parcelable>?, lastUpdate:Long)
{
val items = priceChangeInfo?.map {
it as PriceChangeInfo
}?.reversed() ?: return
val v = layoutInflater.inflate(R.layout.price_alerts_dialogos,null)
// v.lastUpdateTextView.text=getString(R.string.changes_since,timeLapse(lastUpdate))
v.priceAlertsChart.apply {
xAxis.apply {
position = XAxis.XAxisPosition.BOTTOM
setDrawAxisLine(true)
setDrawGridLines(false)
granularity = .3f
labelCount = if(items.size>10)10 else items.size
valueFormatter = IAxisValueFormatter { value, _ ->
items[value.toInt()].symbol
}
}
withMultiple(axisLeft,axisRight){
setDrawAxisLine(true)
setDrawGridLines(true)
}
legend.isEnabled = false
setDrawBarShadow(false)
//setDrawValueAboveBar(true)
description.isEnabled = false
setPinchZoom(false)
setDrawGridBackground(false)
data = {
val green = Color.rgb(110, 190, 102)
val red = Color.rgb(211, 74, 88)
val entries = mutableListOf<BarEntry>()
val colors = mutableListOf<Int>()
items.forEachIndexed { index, info ->
colors.add(if(info.change>0) green else red)
entries.add(BarEntry(index.toFloat(),info.change.toFloat(),info.symbol))
}
val set1 = BarDataSet(entries,"changes").apply {
setDrawIcons(false)
setDrawValues(false)
setColors(colors)
valueFormatter = IValueFormatter {
_, entry, _, _ ->
formatNumber(entry.y.toDouble(),false,false,decimals = 2)+"%"
}
}
val dataSets = mutableListOf<IBarDataSet>().apply {
add(set1)
}
BarData(dataSets).apply {
setValueTextSize(10f)
barWidth = .4f
}
}()
setVisibleXRangeMaximum(10f)
//this doesn't work on HorizontalBarChart
moveViewToX(data.entryCount.toFloat())
}
AlertDialog.Builder(this).setTitle(R.string.price_alerts).setView(v)
.setPositiveButton(R.string.ok) { _: DialogInterface, _: Int ->
intent?.extras?.clear()
}.show()
}
//dependencies
fun<T> withMultiple(vararg args: T, block: T.() -> Unit) {
args.forEach {
it.apply (block)
}
}
data class PriceChangeInfo(var symbol:String, var change:Double):Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString()!!,
parcel.readDouble()) {}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(symbol)
parcel.writeDouble(change)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<PriceChangeInfo> {
override fun createFromParcel(parcel: Parcel): PriceChangeInfo {
return PriceChangeInfo(parcel)
}
override fun newArray(size: Int): Array<PriceChangeInfo?> {
return arrayOfNulls(size)
}
}
}
I've already opened an issue on github:
https://github.com/PhilJay/MPAndroidChart/issues/4397
Any tip | hack | possible solution will be highly appreciated. Thanks in advance.
mpandroidchart
add a comment |
Summary
When using BarChart everything work as expected, but moveViewToX doesn't work on HorizontalBarChart. I've tested with the same code, only changing the XML, and the error is only affecting HorizontalBarChart
I've searched opened issues (most relevant was #2546 which is closed and the proposed solution didn't worked in my case) and searched on StackOverflow but I haven't found a solution yet.
Device:
Device: Xiaomi Redmi Note 4
Android Version 6.0
Library Version 3.1.0-alpha
Here is the code related, is written in Kotlin.
Here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.mikephil.charting.charts.HorizontalBarChart
android:id="@+id/priceAlertsChart"
android:layout_width="match_parent"
android:layout_height="300dp"/>
</LinearLayout>
and the kt file:
override fun onCreate(savedInstanceState: Bundle?) {
val priceAlerts = mutableListOf<PriceChangeInfo>()
for(i in 0..20) {
priceAlerts.add(i,PriceChangeInfo(i.toString()
,Random.nextDouble(-2.5,2.5)))
}
showPercentChangeDialog(priceAlerts.toTypedArray(), Date().time)
}
@SuppressLint("InflateParams")
private fun showPercentChangeDialog(priceChangeInfo:Array<Parcelable>?, lastUpdate:Long)
{
val items = priceChangeInfo?.map {
it as PriceChangeInfo
}?.reversed() ?: return
val v = layoutInflater.inflate(R.layout.price_alerts_dialogos,null)
// v.lastUpdateTextView.text=getString(R.string.changes_since,timeLapse(lastUpdate))
v.priceAlertsChart.apply {
xAxis.apply {
position = XAxis.XAxisPosition.BOTTOM
setDrawAxisLine(true)
setDrawGridLines(false)
granularity = .3f
labelCount = if(items.size>10)10 else items.size
valueFormatter = IAxisValueFormatter { value, _ ->
items[value.toInt()].symbol
}
}
withMultiple(axisLeft,axisRight){
setDrawAxisLine(true)
setDrawGridLines(true)
}
legend.isEnabled = false
setDrawBarShadow(false)
//setDrawValueAboveBar(true)
description.isEnabled = false
setPinchZoom(false)
setDrawGridBackground(false)
data = {
val green = Color.rgb(110, 190, 102)
val red = Color.rgb(211, 74, 88)
val entries = mutableListOf<BarEntry>()
val colors = mutableListOf<Int>()
items.forEachIndexed { index, info ->
colors.add(if(info.change>0) green else red)
entries.add(BarEntry(index.toFloat(),info.change.toFloat(),info.symbol))
}
val set1 = BarDataSet(entries,"changes").apply {
setDrawIcons(false)
setDrawValues(false)
setColors(colors)
valueFormatter = IValueFormatter {
_, entry, _, _ ->
formatNumber(entry.y.toDouble(),false,false,decimals = 2)+"%"
}
}
val dataSets = mutableListOf<IBarDataSet>().apply {
add(set1)
}
BarData(dataSets).apply {
setValueTextSize(10f)
barWidth = .4f
}
}()
setVisibleXRangeMaximum(10f)
//this doesn't work on HorizontalBarChart
moveViewToX(data.entryCount.toFloat())
}
AlertDialog.Builder(this).setTitle(R.string.price_alerts).setView(v)
.setPositiveButton(R.string.ok) { _: DialogInterface, _: Int ->
intent?.extras?.clear()
}.show()
}
//dependencies
fun<T> withMultiple(vararg args: T, block: T.() -> Unit) {
args.forEach {
it.apply (block)
}
}
data class PriceChangeInfo(var symbol:String, var change:Double):Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString()!!,
parcel.readDouble()) {}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(symbol)
parcel.writeDouble(change)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<PriceChangeInfo> {
override fun createFromParcel(parcel: Parcel): PriceChangeInfo {
return PriceChangeInfo(parcel)
}
override fun newArray(size: Int): Array<PriceChangeInfo?> {
return arrayOfNulls(size)
}
}
}
I've already opened an issue on github:
https://github.com/PhilJay/MPAndroidChart/issues/4397
Any tip | hack | possible solution will be highly appreciated. Thanks in advance.
mpandroidchart
Summary
When using BarChart everything work as expected, but moveViewToX doesn't work on HorizontalBarChart. I've tested with the same code, only changing the XML, and the error is only affecting HorizontalBarChart
I've searched opened issues (most relevant was #2546 which is closed and the proposed solution didn't worked in my case) and searched on StackOverflow but I haven't found a solution yet.
Device:
Device: Xiaomi Redmi Note 4
Android Version 6.0
Library Version 3.1.0-alpha
Here is the code related, is written in Kotlin.
Here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.mikephil.charting.charts.HorizontalBarChart
android:id="@+id/priceAlertsChart"
android:layout_width="match_parent"
android:layout_height="300dp"/>
</LinearLayout>
and the kt file:
override fun onCreate(savedInstanceState: Bundle?) {
val priceAlerts = mutableListOf<PriceChangeInfo>()
for(i in 0..20) {
priceAlerts.add(i,PriceChangeInfo(i.toString()
,Random.nextDouble(-2.5,2.5)))
}
showPercentChangeDialog(priceAlerts.toTypedArray(), Date().time)
}
@SuppressLint("InflateParams")
private fun showPercentChangeDialog(priceChangeInfo:Array<Parcelable>?, lastUpdate:Long)
{
val items = priceChangeInfo?.map {
it as PriceChangeInfo
}?.reversed() ?: return
val v = layoutInflater.inflate(R.layout.price_alerts_dialogos,null)
// v.lastUpdateTextView.text=getString(R.string.changes_since,timeLapse(lastUpdate))
v.priceAlertsChart.apply {
xAxis.apply {
position = XAxis.XAxisPosition.BOTTOM
setDrawAxisLine(true)
setDrawGridLines(false)
granularity = .3f
labelCount = if(items.size>10)10 else items.size
valueFormatter = IAxisValueFormatter { value, _ ->
items[value.toInt()].symbol
}
}
withMultiple(axisLeft,axisRight){
setDrawAxisLine(true)
setDrawGridLines(true)
}
legend.isEnabled = false
setDrawBarShadow(false)
//setDrawValueAboveBar(true)
description.isEnabled = false
setPinchZoom(false)
setDrawGridBackground(false)
data = {
val green = Color.rgb(110, 190, 102)
val red = Color.rgb(211, 74, 88)
val entries = mutableListOf<BarEntry>()
val colors = mutableListOf<Int>()
items.forEachIndexed { index, info ->
colors.add(if(info.change>0) green else red)
entries.add(BarEntry(index.toFloat(),info.change.toFloat(),info.symbol))
}
val set1 = BarDataSet(entries,"changes").apply {
setDrawIcons(false)
setDrawValues(false)
setColors(colors)
valueFormatter = IValueFormatter {
_, entry, _, _ ->
formatNumber(entry.y.toDouble(),false,false,decimals = 2)+"%"
}
}
val dataSets = mutableListOf<IBarDataSet>().apply {
add(set1)
}
BarData(dataSets).apply {
setValueTextSize(10f)
barWidth = .4f
}
}()
setVisibleXRangeMaximum(10f)
//this doesn't work on HorizontalBarChart
moveViewToX(data.entryCount.toFloat())
}
AlertDialog.Builder(this).setTitle(R.string.price_alerts).setView(v)
.setPositiveButton(R.string.ok) { _: DialogInterface, _: Int ->
intent?.extras?.clear()
}.show()
}
//dependencies
fun<T> withMultiple(vararg args: T, block: T.() -> Unit) {
args.forEach {
it.apply (block)
}
}
data class PriceChangeInfo(var symbol:String, var change:Double):Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString()!!,
parcel.readDouble()) {}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(symbol)
parcel.writeDouble(change)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<PriceChangeInfo> {
override fun createFromParcel(parcel: Parcel): PriceChangeInfo {
return PriceChangeInfo(parcel)
}
override fun newArray(size: Int): Array<PriceChangeInfo?> {
return arrayOfNulls(size)
}
}
}
I've already opened an issue on github:
https://github.com/PhilJay/MPAndroidChart/issues/4397
Any tip | hack | possible solution will be highly appreciated. Thanks in advance.
mpandroidchart
mpandroidchart
edited Jan 19 at 18:50
Raymond Arteaga
asked Jan 19 at 18:31
Raymond ArteagaRaymond Arteaga
834510
834510
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I've solved it using:
moveViewTo(0f,data.entryCount.f,YAxis.AxisDependency.LEFT)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54270146%2fhorizontalbarchart-moveviewtox-doesnt-work%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I've solved it using:
moveViewTo(0f,data.entryCount.f,YAxis.AxisDependency.LEFT)
add a comment |
I've solved it using:
moveViewTo(0f,data.entryCount.f,YAxis.AxisDependency.LEFT)
add a comment |
I've solved it using:
moveViewTo(0f,data.entryCount.f,YAxis.AxisDependency.LEFT)
I've solved it using:
moveViewTo(0f,data.entryCount.f,YAxis.AxisDependency.LEFT)
answered Jan 20 at 4:50
Raymond ArteagaRaymond Arteaga
834510
834510
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54270146%2fhorizontalbarchart-moveviewtox-doesnt-work%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown