For some reason, the preview shows a different palette than the one I have in Color.kt and Theme.kt. ie. Primary is Color(0xFFA43D00) in Color.kt, but #00658D in the Layout inspector.
I probably messed up something. I didn't like the default palette, so I went to Material Theme Builder and made a custom one. Exported as Jetpack Compose, opened the file, and copy/pasted the contents color information form the exported Theme.kt to the ui/theme/Theme.kt file (without touching anything else, like the package name or the Theme composable):
private val LightColorScheme = lightColorScheme(
primary = md_theme_light_primary,
onPrimary = md_theme_light_onPrimary,
primaryContainer = md_theme_light_primaryContainer,
onPrimaryContainer = md_theme_light_onPrimaryContainer,
secondary = md_theme_light_secondary,
onSecondary = md_theme_light_onSecondary,
secondaryContainer = md_theme_light_secondaryContainer,
onSecondaryContainer = md_theme_light_onSecondaryContainer,
tertiary = md_theme_light_tertiary,
onTertiary = md_theme_light_onTertiary,
tertiaryContainer = md_theme_light_tertiaryContainer,
onTertiaryContainer = md_theme_light_onTertiaryContainer,
error = md_theme_light_error,
errorContainer = md_theme_light_errorContainer,
onError = md_theme_light_onError,
onErrorContainer = md_theme_light_onErrorContainer,
background = md_theme_light_background,
onBackground = md_theme_light_onBackground,
surface = md_theme_light_surface,
onSurface = md_theme_light_onSurface,
surfaceVariant = md_theme_light_surfaceVariant,
onSurfaceVariant = md_theme_light_onSurfaceVariant,
outline = md_theme_light_outline,
inverseOnSurface = md_theme_light_inverseOnSurface,
inverseSurface = md_theme_light_inverseSurface,
inversePrimary = md_theme_light_inversePrimary,
surfaceTint = md_theme_light_surfaceTint,
outlineVariant = md_theme_light_outlineVariant,
scrim = md_theme_light_scrim,
)
private val DarkColorScheme = darkColorScheme(
primary = md_theme_dark_primary,
onPrimary = md_theme_dark_onPrimary,
primaryContainer = md_theme_dark_primaryContainer,
onPrimaryContainer = md_theme_dark_onPrimaryContainer,
secondary = md_theme_dark_secondary,
onSecondary = md_theme_dark_onSecondary,
secondaryContainer = md_theme_dark_secondaryContainer,
onSecondaryContainer = md_theme_dark_onSecondaryContainer,
tertiary = md_theme_dark_tertiary,
onTertiary = md_theme_dark_onTertiary,
tertiaryContainer = md_theme_dark_tertiaryContainer,
onTertiaryContainer = md_theme_dark_onTertiaryContainer,
error = md_theme_dark_error,
errorContainer = md_theme_dark_errorContainer,
onError = md_theme_dark_onError,
onErrorContainer = md_theme_dark_onErrorContainer,
background = md_theme_dark_background,
onBackground = md_theme_dark_onBackground,
surface = md_theme_dark_surface,
onSurface = md_theme_dark_onSurface,
surfaceVariant = md_theme_dark_surfaceVariant,
onSurfaceVariant = md_theme_dark_onSurfaceVariant,
outline = md_theme_dark_outline,
inverseOnSurface = md_theme_dark_inverseOnSurface,
inverseSurface = md_theme_dark_inverseSurface,
inversePrimary = md_theme_dark_inversePrimary,
surfaceTint = md_theme_dark_surfaceTint,
outlineVariant = md_theme_dark_outlineVariant,
scrim = md_theme_dark_scrim,
)
same with the Color.kt file
val md_theme_light_primary = Color(0xFFA43D00)
val md_theme_light_onPrimary = Color(0xFFFFFFFF)
val md_theme_light_primaryContainer = Color(0xFFFFDBCD)
val md_theme_light_onPrimaryContainer = Color(0xFF360F00)
val md_theme_light_secondary = Color(0xFF006782)
val md_theme_light_onSecondary = Color(0xFFFFFFFF)
val md_theme_light_secondaryContainer = Color(0xFFBBEAFF)
val md_theme_light_onSecondaryContainer = Color(0xFF001F29)
val md_theme_light_tertiary = Color(0xFF006B5A)
val md_theme_light_onTertiary = Color(0xFFFFFFFF)
val md_theme_light_tertiaryContainer = Color(0xFF79F8DC)
val md_theme_light_onTertiaryContainer = Color(0xFF00201A)
val md_theme_light_error = Color(0xFFBA1A1A)
val md_theme_light_errorContainer = Color(0xFFFFDAD6)
val md_theme_light_onError = Color(0xFFFFFFFF)
val md_theme_light_onErrorContainer = Color(0xFF410002)
val md_theme_light_background = Color(0xFFFFFBFF)
val md_theme_light_onBackground = Color(0xFF221B00)
val md_theme_light_surface = Color(0xFFFFFBFF)
val md_theme_light_onSurface = Color(0xFF221B00)
val md_theme_light_surfaceVariant = Color(0xFFF5DED6)
val md_theme_light_onSurfaceVariant = Color(0xFF53433E)
val md_theme_light_outline = Color(0xFF85736D)
val md_theme_light_inverseOnSurface = Color(0xFFFFF0C0)
val md_theme_light_inverseSurface = Color(0xFF3A3000)
val md_theme_light_inversePrimary = Color(0xFFFFB597)
val md_theme_light_shadow = Color(0xFF000000)
val md_theme_light_surfaceTint = Color(0xFFA43D00)
val md_theme_light_outlineVariant = Color(0xFFD8C2BA)
val md_theme_light_scrim = Color(0xFF000000)
val md_theme_dark_primary = Color(0xFFFFB597)
val md_theme_dark_onPrimary = Color(0xFF591D00)
val md_theme_dark_primaryContainer = Color(0xFF7D2D00)
val md_theme_dark_onPrimaryContainer = Color(0xFFFFDBCD)
val md_theme_dark_secondary = Color(0xFF60D4FE)
val md_theme_dark_onSecondary = Color(0xFF003545)
val md_theme_dark_secondaryContainer = Color(0xFF004D62)
val md_theme_dark_onSecondaryContainer = Color(0xFFBBEAFF)
val md_theme_dark_tertiary = Color(0xFF5ADBC0)
val md_theme_dark_onTertiary = Color(0xFF00382E)
val md_theme_dark_tertiaryContainer = Color(0xFF005144)
val md_theme_dark_onTertiaryContainer = Color(0xFF79F8DC)
val md_theme_dark_error = Color(0xFFFFB4AB)
val md_theme_dark_errorContainer = Color(0xFF93000A)
val md_theme_dark_onError = Color(0xFF690005)
val md_theme_dark_onErrorContainer = Color(0xFFFFDAD6)
val md_theme_dark_background = Color(0xFF221B00)
val md_theme_dark_onBackground = Color(0xFFFFE264)
val md_theme_dark_surface = Color(0xFF221B00)
val md_theme_dark_onSurface = Color(0xFFFFE264)
val md_theme_dark_surfaceVariant = Color(0xFF53433E)
val md_theme_dark_onSurfaceVariant = Color(0xFFD8C2BA)
val md_theme_dark_outline = Color(0xFFA08D86)
val md_theme_dark_inverseOnSurface = Color(0xFF221B00)
val md_theme_dark_inverseSurface = Color(0xFFFFE264)
val md_theme_dark_inversePrimary = Color(0xFFA43D00)
val md_theme_dark_shadow = Color(0xFF000000)
val md_theme_dark_surfaceTint = Color(0xFFFFB597)
val md_theme_dark_outlineVariant = Color(0xFF53433E)
val md_theme_dark_scrim = Color(0xFF000000)
val seed = Color(0xFFF26419)
val Olivine = Color(0xFFA1C182)
val Sunglow = Color(0xFFFFCB3D)
val light_Olivine = Color(0xFF3F6918)
val light_onOlivine = Color(0xFFFFFFFF)
val light_OlivineContainer = Color(0xFFBFF290)
val light_onOlivineContainer = Color(0xFF0D2000)
val dark_Olivine = Color(0xFFA4D577)
val dark_onOlivine = Color(0xFF1A3700)
val dark_OlivineContainer = Color(0xFF295000)
val dark_onOlivineContainer = Color(0xFFBFF290)
val light_Sunglow = Color(0xFF775A00)
val light_onSunglow = Color(0xFFFFFFFF)
val light_SunglowContainer = Color(0xFFFFDF97)
val light_onSunglowContainer = Color(0xFF251A00)
val dark_Sunglow = Color(0xFFF2C031)
val dark_onSunglow = Color(0xFF3E2E00)
val dark_SunglowContainer = Color(0xFF5A4400)
val dark_onSunglowContainer = Color(0xFFFFDF97)
Just replaced the old color information with the new one. It feels like this is not the right way to do it though... Thank you in advanced for your help.
Please check this answer. Same case.
You can remove the code responsible for dynamic colors in your theme.kt file.
To know more about Dynamic Colors, please refer this documentation page.
val darkTheme = isSystemInDarkTheme()
val dynamicColor = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
val colors = when {
// dynamicColor && darkTheme - > dynamicDarkColorScheme(LocalContext.current)
// dynamicColor && !darkTheme - > dynamicLightColorScheme(LocalContext.current)
darkTheme - > darkColorScheme
else - > lightColorScheme
}
Related
In the code below I get an error Val cannot be reassigned, I dont know how can I recreate the object ? i am new to kotlin and I am just trying to update a code that i found somewhere... trying to understand how to modify it.
I understand it is final and it is being called from another class like this
another class
val polyLine = RoadManager.buildRoadOverlay(road)
PanRoad = newRoad(
polyLine = polyLine,
colorRoad = colorRoad,
roadWidth = roadWidth,
showPoiMarker = showPoiMarker,
listInterestPoints = listInterestPoints,
)
I tried changin it to val to var like this var polyLine = RoadManager.buildRoadOverlay(road) still nothing.
Below is the class that is giving errors
private fun newRoad(
polyLine: Polyline,
colorRoad: Int?,
showPoiMarker: Boolean,
listInterestPoints: List<GeoPoint>,
roadWidth: Float,
bitmapIcon: Bitmap? = null,
): PanRoad {
print(message = "pannam createRoad called")
polyLine.setOnClickListener { _, _, eventPos ->
methodChannel.invokeMethod("receiveSinglePress", eventPos?.toHashMap())
true
}
/// set polyline color
val polygonPaint = Paint().apply {
color = Color.BLUE
style = Paint.Style.FILL
}
val outlinerPaint = Paint().apply {
color = Color.DKGRAY
style = Paint.Style.STROKE
strokeWidth = 2f
}
polyLine.outlinePaint = Paint().apply {
color = colorRoad ?: Color.GREEN
style = Paint.Style.STROKE
strokeWidth = 2f
strokeCap = Cap.ROUND
strokeJoin = Paint.Join.ROUND
}
val iconsRoads = customRoadMarkerIcon
when {
(iconsRoads.isEmpty() && bitmapIcon != null) -> {
iconsRoads[Constants.STARTPOSITIONROAD] = bitmapIcon
iconsRoads[Constants.MIDDLEPOSITIONROAD] = bitmapIcon
iconsRoads[Constants.ENDPOSITIONROAD] = bitmapIcon
}
iconsRoads.isNotEmpty() && bitmapIcon != null -> {
iconsRoads[Constants.MIDDLEPOSITIONROAD] = bitmapIcon
if (!iconsRoads.containsKey(Constants.STARTPOSITIONROAD)) {
iconsRoads[Constants.STARTPOSITIONROAD] = bitmapIcon
}
if (!iconsRoads.containsKey(Constants.ENDPOSITIONROAD)) {
iconsRoads[Constants.ENDPOSITIONROAD] = bitmapIcon
}
}
}
val PanRoad = PanRoad(
context,
map!!,
interestPoint = if (showPoiMarker) listInterestPoints else emptyList(),
showInterestPoints = showPoiMarker
)
PanRoad.let { roadF ->
if (showPoiMarker) {
roadF.markersIcons = iconsRoads
}
polyLine.outlinePaint.strokeWidth = roadWidth
roadF.road = polyLine
folderRoad.items.add(roadF)
}
return PanRoad
}
The error occurs at polyLine.outlinePaint
I assume the Polyline class you're working with is from org.osmdroid.views.overlay, which only provides a getOutlinePaint as can be seen in its JavaDoc. However, there is no setOutlinePaint. From Kotlins point of view outlinePaint is therefore a val which cannot be reassigned.
It think instead of reassigning the outlinePaint field you instead want to retrieve a reference to the Paint object stored in the field and modify it directly. Something like the following might work, however I'm unable to verify this at the moment.
val outlinePaint = polyLine.outlinePaint
outlinePaint.color = Color.GREEM
outlinePaint.style = Paint.Style.STROKE
or if using apply is preferred
polyLine.outlinePaint.apply {
color = Color.GREEM
style = Paint.Style.STROKE
}
what I want to achieve
what I have
I want to show icons on the xAxis above time but line chart takes icon and places them on the value where temperature is shown. I have searched a lot but could not find the answer. Any help would be appreciated. I have tried a lot of things but all in vein.
private fun setTempChart(hour: ArrayList<Hour>, id: String) {
val entries: MutableList<Entry> = ArrayList()
for (i in hour.indices) {
val code = hour[i].condition.code
val icon =
if (hour[i].is_day == 1) requireActivity().setIconDay(code) else requireActivity().setIconNight(
code
)
entries.add(Entry(i.toFloat(), sharedPreference.temp?.let {
hour[i].temp_c.setCurrentTemperature(
it
).toFloat()
}!!))
}
val dataSet = LineDataSet(entries, "")
dataSet.apply {
lineWidth = 0f
setDrawCircles(false)
setDrawCircleHole(false)
isHighlightEnabled = false
valueTextColor = Color.WHITE
setColors(Color.WHITE)
valueTextSize = 12f
mode = LineDataSet.Mode.CUBIC_BEZIER
setDrawFilled(true)
fillColor = Color.WHITE
valueTypeface = typeface
isDrawIconsEnabled
setDrawIcons(true)
valueFormatter = object : ValueFormatter() {
override fun getFormattedValue(value: Float): String {
return String.format(Locale.getDefault(), "%.0f", value)
}
}
}
val lineData = LineData(dataSet)
chart.apply {
description.isEnabled = false
axisLeft.setDrawLabels(false)
axisRight.setDrawLabels(false)
legend.isEnabled = false
axisLeft.setDrawGridLines(false)
axisRight.setDrawGridLines(false)
axisLeft.setDrawAxisLine(false)
axisRight.setDrawAxisLine(false)
setScaleEnabled(false)
data = lineData
setVisibleXRange(8f, 8f)
animateY(1000)
xAxis.apply {
setDrawAxisLine(false)
textColor = Color.WHITE
setDrawGridLines(false)
setDrawLabels(true)
position = XAxis.XAxisPosition.BOTTOM
textSize = 12f
valueFormatter = MyAxisFormatter(hour, id)
isGranularityEnabled = true
granularity = 1f
labelCount = entries.size
}
}
}
I am using MPAndroidChart library
There isn't a nice built-in way to draw icons like that, but you can do it by making a custom extension of the LineChartRenderer and overriding drawExtras. Then you can get your icons from R.drawable.X and draw them on the canvas wherever you want. There is some work to figure out where to put them to line up with the data points, but you can copy the logic from drawCircles to find that.
Example Custom Renderer
inner class MyRenderer(private val context: Context,
private val iconY: Float,
private val iconSizeDp: Float,
chart: LineDataProvider,
animator: ChartAnimator,
viewPortHandler: ViewPortHandler)
: LineChartRenderer(chart, animator, viewPortHandler) {
private var buffer: FloatArray = listOf(0f,0f).toFloatArray()
override fun drawExtras(c: Canvas) {
super.drawExtras(c)
val iconSizePx = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
iconSizeDp,
resources.displayMetrics
)
// get the icons you want to draw
val cloudy = ContextCompat.getDrawable(context, R.drawable.cloudy)
val sunny = ContextCompat.getDrawable(context, R.drawable.sunny)
if( cloudy == null || sunny == null ) {
throw RuntimeException("Missing drawables")
}
// Determine icon width in pixels
val w = iconSizePx
val h = iconSizePx
val dataSets = mChart.lineData.dataSets
val phaseY = mAnimator.phaseY
for(dataSet in dataSets) {
mXBounds.set(mChart, dataSet)
val boundsRange = mXBounds.range + mXBounds.min
val transformer = mChart.getTransformer(dataSet.axisDependency)
for(j in mXBounds.min .. boundsRange) {
val e = dataSet.getEntryForIndex(j) ?: break
buffer[0] = e.x
buffer[1] = iconY * phaseY
transformer.pointValuesToPixel(buffer)
if( !mViewPortHandler.isInBoundsRight(buffer[0])) {
break
}
if( !mViewPortHandler.isInBoundsLeft(buffer[0]) ||
!mViewPortHandler.isInBoundsY(buffer[1])) {
continue
}
// Draw the icon centered under the data point, but at a fixed
// vertical position. Here the icon "sits on top" of the
// specified iconY value
val left = (buffer[0]-w/2).roundToInt()
val right = (buffer[0]+w/2).roundToInt()
val top = (buffer[1]-h).roundToInt()
val bottom = (buffer[1]).roundToInt()
// Alternately, use this to center the icon at the
// "iconY" value
//val top = (buffer[1]-h/2).roundToInt()
//val bottom = (buffer[1]+h/2).roundToInt()
// Use whatever logic you want to select which icon
// to use at each position
val icon = if( e.y > 68f ) {
sunny
}
else {
cloudy
}
icon.setBounds(left, top, right, bottom)
icon.draw(c)
}
}
}
}
Using the Custom Renderer
val iconY = 41f
val iconSizeDp = 40f
chart.renderer = MyRenderer(this, iconY, iconSizeDp,
chart, chart.animator, chart.viewPortHandler)
(other formatting)
val chart = findViewById<LineChart>(R.id.chart)
chart.axisRight.isEnabled = false
val yAx = chart.axisLeft
yAx.setDrawLabels(false)
yAx.setDrawGridLines(false)
yAx.setDrawAxisLine(false)
yAx.axisMinimum = 40f
yAx.axisMaximum = 80f
val xAx = chart.xAxis
xAx.setDrawLabels(false)
xAx.position = XAxis.XAxisPosition.BOTTOM
xAx.setDrawGridLines(false)
xAx.setDrawAxisLine(false)
xAx.axisMinimum = 0.5f
xAx.axisMaximum = 5.5f
xAx.granularity = 0.5f
val x = listOf(0,1,2,3,4,5,6)
val y = listOf(60,65,66,70,65,50,55)
val e = x.zip(y).map { Entry(it.first.toFloat(), it.second.toFloat())}
val line = LineDataSet(e, "temp")
line.setDrawValues(true)
line.setDrawCircles(false)
line.circleRadius = 20f // makes the text offset up
line.valueTextSize = 20f
line.color = Color.BLACK
line.lineWidth = 2f
line.setDrawFilled(true)
line.fillColor = Color.BLACK
line.fillAlpha = 50
line.mode = LineDataSet.Mode.CUBIC_BEZIER
line.valueFormatter = object : ValueFormatter() {
override fun getFormattedValue(value: Float): String {
return "%.0f F".format(value)
}
}
chart.data = LineData(line)
chart.description.isEnabled = false
chart.legend.isEnabled = false
Gives the desired effect
abstract class MainActivity : AppCompatActivity(), Parcelable {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main))
val a = findViewById<TextView>(R.id.editTextNumberDecimal)
val b = findViewById<TextView>(R.id.editTextNumberDecimal2)
val c = findViewById<TextView>(R.id.editTextNumberDecimal3)
val e = findViewById<TextView>(R.id.editTextNumberDecimal4)
val f = findViewById<TextView>(R.id.editTextNumberDecimal5)
val g = findViewById<TextView>(R.id.editTextNumberDecimal6)
val n = findViewById<TextView>(R.id.editTextNumberDecimal13)
val h = findViewById<EditText>(R.id.editTextNumberDecimal7)
val i = findViewById<EditText>(R.id.editTextNumberDecimal8)
val j = findViewById<EditText>(R.id.editTextNumberDecimal9)
val k = findViewById<EditText>(R.id.editTextNumberDecimal10)
val l = findViewById<EditText>(R.id.editTextNumberDecimal11)
val m = findViewById<EditText>(R.id.editTextNumberDecimal12)
val o = findViewById<EditText>(R.id.editTextNumberDecimal14)
val bt = findViewById<Button>(R.id.button)
bt.setOnClickListener {
val fm = a.text.toString().toFloat()
val s = b.text.toString().toFloat()
val kmod1 = c.text.toString().toFloat()
val kmod2 = e.text.toString().toFloat()
val d1 = f.text.toString().toFloat()
val t = g.text.toString().toFloat()
val n1 = n.text.toString().toFloat()
val fk = (fm - (1.645 * s)).toFloat()
val ftk = 1.3 * fk
val fvk = 0.15 * fk
val fck = 0.1 * fk
val fmk = 1.1 * fk
val kmod = (kmod1 * kmod2 * 0.8).toFloat()
val fcd: Float = kmod * fk / 2
h.setText(fcd.toString())
val ftd = (kmod * ftk / 1.8).toFloat()
i.setText(ftd.toString())
val fvd = (kmod * fvk / 2).toFloat()
j.setText(fvd.toString())
val fcd1 = (kmod * fck / 2).toFloat()
k.setText(fcd1.toString())
val fmd = (kmod * fmk / 1.8).toFloat()
l.setText(fmd.toString())
val d = d1 - 2 * t
when I build the app it says that is Build Sucessfully but when I try to run it on the emulator, It keeps stopping.
the app is the calculator type It read some numbers as strings, turn them into floats numbers for it calculate and it writes the resulte as string again
val chartView = holder.hcopbar
chartView.addFont(R.font.nsregular)
chartView.plugins = ArrayList(Arrays.asList("drilldown"))
val options = HIOptions()
val chart = HIChart()
chart.type = "column"
chart.backgroundColor = HIColor.initWithHexValue("F2F9FC")
options.chart = chart
val title = HITitle()
title.text = ""
options.title = title
val credits = HICredits()
credits.enabled = false
options.credits=credits
val export = HIExporting()
export.enabled=false
options.exporting = export
val xAxis = HIXAxis()
xAxis.type = "category"
options.xAxis=ArrayList(listOf(xAxis))
val yAxis = HIYAxis()
yAxis.title = HITitle()
yAxis.title.text = ""
yAxis.visible = false
options.yAxis=ArrayList(listOf(yAxis))
val plotOptions = HIPlotOptions()
plotOptions.series = HISeries()
plotOptions.series.dataLabels = ArrayList<Any>()
options.plotOptions = plotOptions
val tooltip = HITooltip()
tooltip.headerFormat = "<span style=\"font-size:11px\">{series.name}</span><br>"
tooltip.pointFormat =
"<span style=\"color:{point.color}\">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>"
options.tooltip = tooltip
val columncolors = ArrayList<String>()
columncolors.add("#FBB519")
columncolors.add("#F5716F")
columncolors.add("#00B9C4")
columncolors.add("#ABC22A")
columncolors.add("#CA56AF")
columncolors.add("#CA56AF")
val series1 = HIColumn()
series1.name = ""
series1.colorByPoint = true
series1.colors = columncolors
val map1: HashMap<String, Any> = HashMap()
map1["name"] = "Hyderabad"
map1["y"] = 56.33
map1[""]
map1["drilldown"] = "Microsoft"
val map2: HashMap<String, Any> = HashMap()
map2["name"] = "Vijayawada"
map2["y"] = 24.03
map2["drilldown"] = "Chrome"
val map3: HashMap<String, Any> = HashMap()
map3["name"] = "Secundrabad"
map3["y"] = 18.38
map3["drilldown"] = "Firefox"
val map4: HashMap<String, Any> = HashMap()
map4["name"] = "Kakinada"
map4["y"] = 14.77
map4["drilldown"] = "Safari"
val map5: HashMap<String, Any> = HashMap()
map5["name"] = "Nellore"
map5["y"] = 21.50
map5["drilldown"] = "Opera"
val map6: HashMap<String, Any> = HashMap()
map6["name"] = "Kurnool"
map6["y"] = 30.00
map6["drilldown"] = "null"
val series1_data = ArrayList<HashMap<String, Any>>()
series1_data.add(map1)
series1_data.add(map2)
series1_data.add(map3)
series1_data.add(map4)
series1_data.add(map5)
series1_data.add(map6)
series1.data = ArrayList(series1_data)
val series = ArrayList<HISeries>()
series.add(series1)
options.series = series
val drilldown = HIDrilldown()
val series2 = HIColumn()
series2.name = "Hyderabad"
series2.id = "Microsoft"
val object1 = arrayOf<Any>("Quarter1", 24.13)
val object2 = arrayOf<Any>("Quarter2", 17.2)
val object3 = arrayOf<Any>("Quarter3", 8.11)
val object4 = arrayOf<Any>("Quarter4", 5.33)
val series_list = ArrayList<Any>()
series_list.add(object1)
series_list.add(object2)
series_list.add(object3)
series_list.add(object4)
series2.data =
ArrayList(series_list)
val series3 = HIColumn()
series3.name = "Vijayawada"
series3.id = "Chrome"
val object5 = arrayOf<Any>("Quarter1", 24.13)
val object6 = arrayOf<Any>("Quarter2", 17.2)
val object7 = arrayOf<Any>("Quarter3", 8.11)
val object8 = arrayOf<Any>("Quarter4", 5.33)
val series_list1 = ArrayList<Any>()
series_list1.add(object5)
series_list1.add(object6)
series_list1.add(object7)
series_list1.add(object8)
series3.data =
ArrayList(series_list1)
val series4 = HIColumn()
series4.name = "Secundrabad"
series4.id = "Firefox"
val object9 = arrayOf<Any>("Quarter1", 24.13)
val object10 = arrayOf<Any>("Quarter2", 17.2)
val object11 = arrayOf<Any>("Quarter3", 8.11)
val object12 = arrayOf<Any>("Quarter4", 5.33)
val series_list2 = ArrayList<Any>()
series_list2.add(object9)
series_list2.add(object10)
series_list2.add(object11)
series_list2.add(object12)
series4.data =
ArrayList(series_list2)
val series5 = HIColumn()
series5.name = "Kakinada"
series5.id = "Safari"
val object13 = arrayOf<Any>("Quarter1", 24.13)
val object14= arrayOf<Any>("Quarter2", 17.2)
val object15 = arrayOf<Any>("Quarter3", 8.11)
val object16 = arrayOf<Any>("Quarter4", 5.33)
val series_list3 = ArrayList<Any>()
series_list3.add(object13)
series_list3.add(object14)
series_list3.add(object15)
series_list3.add(object16)
series5.data =
ArrayList(series_list3)
val seriesList = ArrayList<HISeries>()
seriesList.add(series2)
seriesList.add(series3)
seriesList.add(series4)
seriesList.add(series5)
drilldown.series = ArrayList(seriesList)
options.drilldown = drilldown
chartView.setOptions(options);
placing column values on top of each column in orange marked places and need to remove series name as it has in green marked circle
Above is my code from that i got output as in that attached screenshot and my requirements are :
i need to remove Series name on bottom of the chart.
Each bar should show its value on top of the each bar.
Each bar description text is aligned cross vertically and i need to make it as flat aligned text.
Kindly help me in meeting my requirements.
Thanks in advance
Solutions are as below:-
1.`
var legend = HILegend()
legend.enabled = false
options.legend = legend
`
2.`
val plotOptions = HIPlotOptions()
plotOptions.series = HISeries()
val dataLabels = HIDataLabels()
dataLabels.format = "{y}"
dataLabels.enabled = true
dataLabels.color = HIColor.initWithHexValue("#F2F9FC")
plotOptions.series.dataLabels = arrayListOf(dataLabels)
// plotOptions.series.dataLabels = ArrayList<Any>()
options.plotOptions = plotOptions
`
3.`
val xAxis = HIXAxis()
xAxis.type = "category"
xAxis.labels = HILabels()
xAxis.labels.enabled = true
xAxis.labels.rotation =0
xAxis.labels.style = HICSSObject()
xAxis.labels.style.fontFamily = "nsregular"
xAxis.labels.style.fontSize = "10px"
options.xAxis=ArrayList(listOf(xAxis))
`
I don't know why using this Fragment can make the problem , it seems that isIconSpaceReserved = false is useful for not preferenceCagory
class TFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
val context = preferenceManager.context
val screen = preferenceManager.createPreferenceScreen(context)
val category1 = PreferenceCategory(context)
category1.title = "button"
category1.summary = "what is the problem"
category1.key = "bbb"
val swithButton = SwitchPreferenceCompat(context)
swithButton.title = "button"
swithButton.summary = "summary"
swithButton.key = "sss"
swithButton.isIconSpaceReserved = false
val swithButton2 = EditTextPreference(context)
swithButton2.title = "edit"
val swithButton3 = SeekBarPreference(context)
swithButton3.title = "seekbar"
swithButton3.value = 1
screen.addPreference(category1)
category1.addPreference(swithButton)
val category2 = PreferenceCategory(context)
category2.title = "category2"
screen.addPreference(category2)
category2.addPreference(swithButton2)
category2.addPreference(swithButton3)
preferenceScreen = screen
}
style is normal, I try so many ways but it's useless.
now, I tried the 'androidx.preference:preference:1.1.0-alpha01' , so lucky, It fixed the bug that the isIconSpaceReserved was not supported for PreferenceCategory.
override fun setPreferenceScreen(preferenceScreen: PreferenceScreen?) {
super.setPreferenceScreen(preferenceScreen)
if (preferenceScreen != null) {
val count = preferenceScreen.preferenceCount
for (i in 0 until count) {
if (preferenceScreen.getPreference(i) is PreferenceCategory) {
val category = preferenceScreen.getPreference(i) as PreferenceCategory
val childCount = category.preferenceCount
for (j in 0 until childCount) {
category.getPreference(j).isIconSpaceReserved = false
}
}
preferenceScreen.getPreference(i).isIconSpaceReserved = false
}
}
}