highcharts / highcharts-ios

iOS wrapper for Highcharts.
Other
127 stars 39 forks source link

How to display column dataLabels ? #305

Closed barotbhavesh closed 4 years ago

barotbhavesh commented 4 years ago

How to display column Data labels same like showing the image in below

Screenshot 2020-04-21 at 4 59 48 PM

Please share code in swift (I am trying to code but getting so many errors)

ihnatmoisieiev commented 4 years ago

Hello @barotbhavesh,

please check datalabels.rotation API Reference.

See the demo below:

let options = HIOptions()

let xAxis = HIXAxis()
xAxis.categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
options.xAxis = [xAxis]

let plotOptions = HIPlotOptions()
plotOptions.series = HISeries()

let dataLabels = HIDataLabels()
dataLabels.enabled = true
dataLabels.rotation = 270
dataLabels.y = -15

plotOptions.series.dataLabels = [dataLabels]

options.plotOptions = plotOptions

let column = HIColumn()
column.data = [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
options.series = [column]
barotbhavesh commented 4 years ago

If I am using stacking in HIColumn then how to display data in the single tooltip like in this image Screenshot 2020-04-23 at 9 51 28 AM

ihnatmoisieiev commented 4 years ago

@barotbhavesh you should use stackLabels in this case.

Please check the demo:

let options = HIOptions()

let chart = HIChart()
chart.type = "column"
options.chart = chart

let xAxis = HIXAxis()
xAxis.categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
options.xAxis = [xAxis]

let yAxis = HIYAxis()
yAxis.stackLabels = HIStackLabels()
yAxis.stackLabels.enabled = true
yAxis.stackLabels.style = HICSSObject()
yAxis.stackLabels.style.color = "black"
yAxis.stackLabels.rotation = 270
yAxis.stackLabels.x = 5
yAxis.stackLabels.y = 15
options.yAxis = [yAxis]

let plotOptions = HIPlotOptions()
plotOptions.column = HIColumn()
plotOptions.column.stacking = "normal"
plotOptions.column.pointPadding = 0
plotOptions.column.groupPadding = 0

let dataLabels = HIDataLabels()
dataLabels.enabled = false
plotOptions.column.dataLabels = [dataLabels]

options.plotOptions = plotOptions

let column1 = HIColumn()
column1.data = [29.9, 71.5, 106.4, 129.2, 144.0, 176.0]

let column2 = HIColumn()
column2.data = [144.0, 176.0, 135.6, 148.5, 216.4, 194.1]

options.series = [column1, column2]
barotbhavesh commented 4 years ago

Can we set short Value in data labels Just Example:- $ 23.92k or $ 44.34M

ihnatmoisieiev commented 4 years ago

@barotbhavesh sure, just use stackLabels.formatter.
Please see stackLabels.formatter API docs.

In this case, It could be something like:

yAxis.stackLabels.formatter = HIFunction(jsFunction: "function() { if (this.total > 1000000) { return '$ ' + Highcharts.numberFormat(this.total / 1000000, 2) + 'M'; } else if (this.total > 1000) { return '$ ' + Highcharts.numberFormat(this.total / 1000, 2) + 'k'; } else { return '$ ' +this.total; } }")
barotbhavesh commented 4 years ago

thank's It's working but data label not in the center if I am using column.maxPointWidth = NSNumber(value: 40) and in top data label hide if HIYAxis() value is not high please check-in the image Screenshot 2020-05-18 at 4 42 05 PM

ihnatmoisieiev commented 4 years ago

@barotbhavesh, please adjust yAxis.stackLabels.x param.

Regarding the second question, try to change the formatter:

yAxis.stackLabels.formatter = HIFunction(jsFunction: "function() { if (this.value < 1) { return false; } else if (this.total > 1000000) { return '$ ' + Highcharts.numberFormat(this.total / 1000000, 2) + 'M'; } else if (this.total > 1000) { return '$ ' + Highcharts.numberFormat(this.total / 1000, 2) + 'k'; } else { return '$ ' +this.total; } }")
barotbhavesh commented 4 years ago

For @ihnatmoisieiev this

please adjust yAxis.stackLabels.x param.

    yAxisFirst.stackLabels = HIStackLabels()
    yAxisFirst.stackLabels.enabled = true
    yAxisFirst.stackLabels.style = HICSSObject()
    yAxisFirst.stackLabels.style.color = "gray"
    yAxisFirst.stackLabels.style.fontSize = "12"
    yAxisFirst.stackLabels.rotation = 270
    yAxisFirst.stackLabels.x = 13
    yAxisFirst.stackLabels.y = 10
    yAxisFirst.stackLabels.formatter = HIFunction(jsFunction: "function() { if (this.total > 1000000) { return '$ ' + Highcharts.numberFormat(this.total / 1000000, 2) + 'M'; } else if (this.total > 1000) { return '$ ' + Highcharts.numberFormat(this.total / 1000, 2) + 'k'; } else { return '$ ' + this.total; } }")

I am facing issue in Data label (also issue in $0 value data label)

Screenshot 2020-05-19 at 2 54 57 PM

ihnatmoisieiev commented 4 years ago

@barotbhavesh please use formatter from the my previous comment https://github.com/highcharts/highcharts-ios/issues/305#issuecomment-630668332

barotbhavesh commented 4 years ago

Not working the same issue facing.

https://user-images.githubusercontent.com/48505333/82309635-fdeb4600-99e0-11ea-841c-186cc00ba801.png

ihnatmoisieiev commented 4 years ago

@barotbhavesh a small typo in the formatter. Please use the following:

yAxis.stackLabels.formatter = HIFunction(jsFunction: "function() { if (this.total < 1) { return false; } else if (this.total > 1000000) { return '$ ' + Highcharts.numberFormat(this.total / 1000000, 2) + 'M'; } else if (this.total > 1000) { return '$ ' + Highcharts.numberFormat(this.total / 1000, 2) + 'k'; } else { return '$ ' +this.total; } }")
barotbhavesh commented 4 years ago

I am trying See my code @ihnatmoisieiev

yAxisSecond.stackLabels = HIStackLabels() yAxisSecond.stackLabels.enabled = true yAxisSecond.stackLabels.style = HICSSObject() yAxisSecond.stackLabels.style.color = "gray" yAxisSecond.stackLabels.style.fontSize = "12" yAxisSecond.stackLabels.rotation = 270 yAxisSecond.stackLabels.x = 13 yAxisSecond.stackLabels.y = 10 yAxisSecond.stackLabels.formatter = HIFunction(jsFunction: "function() { if (this.total < 1) { return false; } else if (this.total > 1000000) { return '$ ' + Highcharts.numberFormat(this.total / 1000000, 2) + 'M'; } else if (this.total > 1000) { return '$ ' + Highcharts.numberFormat(this.total / 1000, 2) + 'k'; } else { return '$ ' +this.total; } }")

Same issue not get success

Screenshot 2020-05-21 at 2 55 55 PM

ihnatmoisieiev commented 4 years ago

@barotbhavesh please try the following config:

yAxis.stackLabels = HIStackLabels()
yAxis.stackLabels.enabled = true
yAxis.stackLabels.crop = false
yAxis.stackLabels.overflow = "hidden"
yAxis.stackLabels.style = HICSSObject()
yAxis.stackLabels.style.color = "gray"
yAxis.stackLabels.style.fontSize = "12"
yAxis.stackLabels.rotation = 270
yAxis.stackLabels.x = 13
yAxis.stackLabels.y = 10
yAxis.stackLabels.formatter = HIFunction(jsFunction: "function() { if (this.total < 1) { return false; } else if (this.total > 1000000) { return '$ ' + Highcharts.numberFormat(this.total / 1000000, 2) + 'M'; } else if (this.total > 1000) { return '$ ' + Highcharts.numberFormat(this.total / 1000, 2) + 'k'; } else { return '$ ' + Highcharts.numberFormat(this.total, 2); } }")

It works for me.

barotbhavesh commented 4 years ago

Yes its working thank you so much but in without stacking I am using this code

let dataLabels = HIDataLabels() dataLabels.enabled = true dataLabels.crop = false dataLabels.overflow = "hidden" dataLabels.style = HIStyle() dataLabels.style.color = "gray" dataLabels.style.fontSize = "12" dataLabels.rotation = 270 dataLabels.y = 0

column.dataLabels = [dataLabels]

then chart showing

Screenshot 2020-05-25 at 11 21 05 AM

ihnatmoisieiev commented 4 years ago

@barotbhavesh please share your series data.

barotbhavesh commented 4 years ago

let column = HIColumn() column.linkedTo = "columnScatter" column.data = aryDicColumn1Value column.colorByPoint = NSNumber(value: true) column.colors = aryColorColumn

let dataLabels = HIDataLabels() dataLabels.enabled = true dataLabels.crop = false dataLabels.overflow = "hidden" dataLabels.style = HIStyle() dataLabels.style.color = "gray" dataLabels.style.fontSize = "12" dataLabels.rotation = 270 dataLabels.y = 0 //'dataLabels.formatter = HIFunction(jsFunction: "function() { if (this.total > 1000000) { return '$ ' + Highcharts.numberFormat(this.total / 1000000, 2) + 'M'; } else if (this.total > 1000) { return '$ ' + Highcharts.numberFormat(this.total / 1000, 2) + 'k'; } else { return '$ ' + this.total; } }")

column.dataLabels = [dataLabels]

options.series = [columnScatter, lineScatter, column, line]

ihnatmoisieiev commented 4 years ago

@barotbhavesh it is not series data.

Please share the following data:

columnScatter.data = ...

lineScatter.data = ...

column1.data = ...

line2.data = ...

or your all config with HIOptions object.

barotbhavesh commented 4 years ago

let columnScatter = HIScatter() columnScatter.id = "columnScatter" columnScatter.marker = HIMarker() columnScatter.marker.symbol = "url((base64ImgFirst))"

let lineScatter = HIScatter() lineScatter.id = "lineScatter" lineScatter.marker = HIMarker() lineScatter.marker.symbol = "url((base64ImgSecond))"

column1.data = [51550.75,29988.64,0, 216.56]

line2.data = [28410.45,15879.97,0,0]

options.series = [columnScatter, lineScatter, column1, line2] let options = HIOptions() options.chart = chart options.credits = credits options.title = title options.xAxis = [xaxis] options.yAxis = [yAxis] options.tooltip = tooltip options.exporting = exporting options.credits = credits collection.viewCharts.options = options

ihnatmoisieiev commented 4 years ago

@barotbhavesh please share full config of HIOptions object. I don't here there column1, line2.

barotbhavesh commented 4 years ago

let options = HIOptions() options.series = [columnScatter, lineScatter, column1, line2] options.chart = chart options.credits = credits options.title = title options.xAxis = [xaxis] options.yAxis = [yAxis] options.tooltip = tooltip options.exporting = exporting options.credits = credits collection.viewCharts.options = options

sebastianbochan commented 4 years ago

Hi @barotbhavesh, Let me explain how our support and debugging process work.

To increase the efficiency of support and time of resolving problems, please share your chart's details with all used values, parameters etc. The config should not contain the references to external variables, which are not attached, so we are not able to predict what is there.

Example: options.title = title

Instead of that, we expect to have

options.title = "Loreum ipsum"

etc.

Moreover the config should be full and complex, so when we "copy/paste" to our config, the demo runs.

barotbhavesh commented 4 years ago

Okay @sebastianbochan I am sharing my code or my API response please help me as soon as possible because I need to upload app on the app store

This is API Response

{"Message":"","ResponseStatus":true,"ResponseData":[{"companyID":0,"key":"Entity Avg","keyID":"","data":[{"color":"#0096d0","isDetailTransacion":false,"key":"May'20","Recommendations":null,"data":[{"percentage":65.62,"value":23420.32,"key":"Parts","color":"#f3ba17"},{"percentage":34.38,"value":12268.31,"key":"Labor","color":"#114b91"},{"percentage":0,"value":0,"key":"Other","color":"#26afe0"},{"percentage":0,"value":0,"key":"Unclassified","color":"#007275"},{"percentage":100,"value":35688.63,"key":"Total","color":"#000080"}]},{"color":null,"isDetailTransacion":false,"key":"May'19","Recommendations":null,"data":[{"percentage":62.46,"value":43699.16,"key":"Parts","color":"#fdf1d3"},{"percentage":37.12,"value":25969.18,"key":"Labor","color":"#d2ddea"},{"percentage":0,"value":0,"key":"Other","color":"#d6eff9"},{"percentage":0.42,"value":296.67,"key":"Unclassified","color":"#c5e7e8"},{"percentage":100,"value":69965.01,"key":"Total","color":"#6363EC"}]},{"color":null,"isDetailTransacion":false,"key":"Variance","Recommendations":null,"data":[{"key":"Parts","percentage":0,"color":"#f3ba17","value":-20278.83},{"key":"Labor","percentage":0,"color":"#114b91","value":-13700.87},{"key":"Other","percentage":0,"color":"#26afe0","value":0},{"key":"Unclassified","percentage":0,"color":"#007275","value":-296.67},{"key":"Total","percentage":0,"value":-34276.37,"color":"#000080"}]},{"color":null,"isDetailTransacion":false,"key":"Variance %","Recommendations":null,"data":[{"value":0,"color":"#f3ba17","key":"Parts","percentage":-46.41},{"value":0,"color":"#114b91","key":"Labor","percentage":-52.76},{"value":0,"color":"#26afe0","key":"Other","percentage":0},{"value":0,"color":"#007275","key":"Unclassified","percentage":-100},{"value":0,"color":"#000080","key":"Total","percentage":-48.99}]}]}],"ErrorData":null}

This is My Code

var aryColorColumn1 = [HIColor]() var aryDicColumn1Value = [NSNumber]()

var yAxisMaxValue = 0 var strSelectMonthorYear = ""

    let credits = HICredits()
    credits.enabled = false

    let exporting = HIExporting()
    exporting.enabled = false

    let imgDataFirst =  imageLiteral(resourceName: "graph").pngData()!
    let base64ImgFirst = "data:image/png;base64," + imgDataFirst.base64EncodedString()

    let imgDataSecond =  imageLiteral(resourceName: "line").pngData()!
    let base64ImgSecond = "data:image/png;base64," + imgDataSecond.base64EncodedString()

let columnScatter = HIScatter() columnScatter.id = "columnScatter" columnScatter.marker = HIMarker() columnScatter.marker.symbol = "url((base64ImgFirst))"

    let lineScatter = HIScatter()
    lineScatter.id = "lineScatter"
    lineScatter.marker = HIMarker()
    lineScatter.marker.symbol = "url(\(base64ImgSecond))"

let title = HITitle() title.text = ""

    let chart = HIChart()
    chart.events = HIEvents()
    chart.plotBackgroundColor = HIColor()
    chart.backgroundColor = HIColor(uiColor: UIColor.clear)

        strSelectMonthorYear = COMMON_SHARED.convertStaticDateFormaterInString(date, StrYearDateFormat: DATE_FORMAT_YY, StrMonthDateFormat: DATE_FORMAT_MMM, strMiddleFormat: "\'")

        _ = aryFinancialAnalysis.filter { (dicFinancialAnalysis) -> Bool in
            _ = dicFinancialAnalysis.aryFADataModel.filter { (dicFAData) -> Bool in
                _ = dicFAData.aryFASubDataModel.filter { (dicFASubData) -> Bool in
                    if dicFASubData.key != "Total" && dicFAData.key == strSelectMonthorYear {
                        arySeriesName.append((dicFASubData.key))
                    }

                    if dicFAData.key != "Variance" && dicFAData.key != "Variance %" {
                        aryXCategoryName.append(dicFAData.key)
                    }

                    return true
                }
                return true
            }
            return true
        }

arySeriesName = COMMON_SHARED.uniq(source: arySeriesName) aryXCategoryName = COMMON_SHARED.uniq(source: aryXCategoryName)

        _ = aryFinancialAnalysis[0].aryFADataModel.filter { (dicFAData) -> Bool in
            _ = dicFAData.aryFASubDataModel.filter { (dicFASubData) -> Bool in
                if dicFASubData.key != "Total" && dicFAData.key == strSelectMonthorYear {
                    if strReportType == "1" {
                        aryDicLine1Value.append(NSNumber(value: dicFASubData.value))
                    } else if strReportType == "2" || strReportType == "8" || strReportType == "9" {
                        aryDicLine1Value.append(NSNumber(value: dicFASubData.fltPercentage))
                    }
                }

                if dicFAData.key == strSelectMonthorYear {
                    strLine1Color = dicFAData.color
                    hiLine1Color = HIColor(hexValue:dicFAData.color)
                }

                let strColumn1Color = dicFASubData.color.replacingOccurrences(of: "#", with: "", options: NSString.CompareOptions.literal, range: nil)
                aryColorColumn1.append(HIColor(hexValue:strColumn1Color))

                if dicFASubData.key != "Total" && dicFAData.key != strSelectMonthorYear && dicFAData.key != "Variance" && dicFAData.key != "Variance %" {
                    if strReportType == "1" {
                        aryDicColumn1Value.append(NSNumber(value: dicFASubData.value))
                        if Int(dicFASubData.value) > yAxisMaxValue {
                            yAxisMaxValue = Int(dicFASubData.value)
                        }
                    } else if strReportType == "2" || strReportType == "8" || strReportType == "9" {
                        aryDicColumn1Value.append(NSNumber(value: dicFASubData.fltPercentage))
                    }

                    let strLine1Color = dicFASubData.color.replacingOccurrences(of: "#", with: "", options: NSString.CompareOptions.literal, range: nil)
                    aryColorLine1.append(HIColor(hexValue:strLine1Color))
                }
                return true
            }
            return true
        }

let xaxis = HIXAxis() xaxis.categories = arySeriesName

    let yAxis = HIYAxis()
    yAxis.title = HITitle()
    yAxis.labels = HILabels()

let tooltip = HITooltip() tooltip.headerFormat = ""

yAxis.title.text = "Revenue $" yAxis.labels.formatter = HIFunction(jsFunction: "function() { if (this.value > 1000000) { return '$' + this.value / 1000000 + 'M'; } else if (this.value > 1000) { return '$' + this.value / 1000 + 'k'; } else { return '$' + this.value; } }")

        tooltip.formatter = HIFunction(jsFunction: "function() { if (this.y > 1000000) { return '$' + Highcharts.numberFormat(this.y / 1000000, 2) + 'M'; } else if (this.y > 1000) { return '$' + Highcharts.numberFormat(this.y / 1000, 2) + 'k'; } else { return '$' + Highcharts.numberFormat(this.y, 2); } }")

let column1 = HIColumn() if aryXCategoryName.count > 0 && aryXCategoryName.indices.contains(1) { columnScatter.name = aryXCategoryName[1] } column1.linkedTo = "columnScatter" column1.data = aryDicColumn1Value column1.colorByPoint = NSNumber(value: true) column1.colors = aryColorColumn1 let dataLabels = HIDataLabels() dataLabels.enabled = true dataLabels.rotation = 270 dataLabels.y = -15 column1.dataLabels = [dataLabels]

let line2 = HIAreaspline()

let colorValue = UIColor(hexString: strLine1Color) line2.data = aryDicLine1Value line2.linkedTo = "lineScatter" lineScatter.name = strSelectMonthorYear line2.color = hiLine1Color line2.fillColor = HIColor(linearGradient: [ "x1": NSNumber(value: 0), "x2": NSNumber(value: 0), "y1": NSNumber(value: 0), "y2": NSNumber(value: 1) ], stops: [[NSNumber(value: 0), "rgb((Int(colorValue.rgba.red 255)),(Int(colorValue.rgba.green 255)),(Int(colorValue.rgba.blue 255)))"], [NSNumber(value: 1), "rgba((Int(colorValue.rgba.red 255)),(Int(colorValue.rgba.green 255)),(Int(colorValue.rgba.blue 255)),(0))"]])

let options = HIOptions() options.chart = chart options.credits = credits options.title = title options.xAxis = [xaxis] options.yAxis = [yAxis] options.tooltip = tooltip options.series = [columnScatter, lineScatter, column1, line2] options.exporting = exporting options.credits = credits collection.viewCharts.options = options

Thank you so much for the help

sebastianbochan commented 4 years ago

Hi @barotbhavesh, The code refers to external sources. For example:

aryXCategoryName = COMMON_SHARED.uniq(source: aryXCategoryName)

We are not able to reproduce and run app with this kind of references. Please simplify the code as much as possible and use i.e static strings. The simplest code should introduce the issue.

barotbhavesh commented 4 years ago

@sebastianbochan please add the below code

func uniq<S : Sequence, T : Hashable>(source: S) -> [T] where S.Iterator.Element == T {
    var buffer = [T]()
    var added = Set<T>()
    for elem in source {
        if !added.contains(elem) {
            buffer.append(elem)
            added.insert(elem)
        }
    }
    return buffer
}
sebastianbochan commented 4 years ago

Hi @barotbhavesh, The code refers to external sources. Unfortunately I was not able to reproduce and run app with this kind of references. Please simplify the code as much as possible (HOWTO: https://github.com/highcharts/highcharts-ios/issues/305#issuecomment-633974053) and use i.e static strings. The simplest code should introduce the issue.

barotbhavesh commented 4 years ago

hey @sebastianbochan gm

can you share you demo code so I'll check in my system if your code not helpful for me then I'll share my simple code.

Please share your demo code

sebastianbochan commented 4 years ago

Hi @barotbhavesh, You can find our demos (including the code) here: https://www.highcharts.com/ios/demo. In all samples the problem is not visible, so please edit only options which are crucial for reporting the issue and paste all of them here.

barotbhavesh commented 4 years ago

can you share the logic of Display Data label because I know how to display the chart but I don't know how to display data label so only share display data label code no need to whole project code.

barotbhavesh commented 4 years ago

I am trying to my self But need help

Screenshot 2020-06-03 at 8 19 35 PM

How to add $ sign like the value is 545454.23232323 so need to add $ and also need to show in short value like $54.23K or etc. Please help me as soon as possible

sebastianbochan commented 4 years ago

@ihnatmoisieiev has already post the solution here: https://github.com/highcharts/highcharts-ios/issues/305#issuecomment-632622730

yAxis.stackLabels = HIStackLabels()
yAxis.stackLabels.enabled = true
yAxis.stackLabels.crop = false
yAxis.stackLabels.overflow = "hidden"
yAxis.stackLabels.style = HICSSObject()
yAxis.stackLabels.style.color = "gray"
yAxis.stackLabels.style.fontSize = "12"
yAxis.stackLabels.rotation = 270
yAxis.stackLabels.x = 13
yAxis.stackLabels.y = 10
yAxis.stackLabels.formatter = HIFunction(jsFunction: "function() { if (this.total < 1) { return false; } else if (this.total > 1000000) { return '$ ' + Highcharts.numberFormat(this.total / 1000000, 2) + 'M'; } else if (this.total > 1000) { return '$ ' + Highcharts.numberFormat(this.total / 1000, 2) + 'k'; } else { return '$ ' + Highcharts.numberFormat(this.total, 2); } }")
barotbhavesh commented 4 years ago

Thanks for the update it's working if I am using stacking if I am using a simple column chart at that time this code not working.

sebastianbochan commented 4 years ago

The same options you have in the regular datalabels.

Docs:

let dataLabels = HIDataLabels()
dataLabels.enabled = true
dataLabels.crop = false
dataLabels.overflow = "hidden"
dataLabels.style = HIStyle()
dataLabels.style.color = "gray"
dataLabels.style.fontSize = "12"
dataLabels.rotation = 270
dataLabels.y = 0
dataLabels.formatter = HIFunction(jsFunction: "function() { if (this.total > 1000000) { return '$ ' + Highcharts.numberFormat(this.total / 1000000, 2) + 'M'; } else if (this.total > 1000) { return '$ ' + Highcharts.numberFormat(this.total / 1000, 2) + 'k'; } else { return '$ ' + this.total; } }")
barotbhavesh commented 4 years ago

BEFORE YOUR REPLY I WAS TRIED @sebastianbochan Screenshot 2020-06-04 at 3 55 18 PM

ihnatmoisieiev commented 4 years ago

@barotbhavesh please check the demo below:

let options = HIOptions()

let chart = HIChart()
chart.events = HIEvents()
chart.events.load = HIFunction(jsFunction: "function() { var chart = this, bottom = chart.plotHeight - 20, series = chart.series, bbox, dl; series.forEach(function(serie, j) { serie.points.forEach(function(data, i) { dl = data.dataLabel, bbox = dl.getBBox(); if ((bottom - dl.alignAttr.y) < bbox.height) { data.dataLabel.attr({ y: bottom - (bbox.height / 2) }); } }); }); }")
options.chart = chart

let title = HITitle()
title.text = "Monthly Average Rainfall"
options.title = title

let plotOptions = HIPlotOptions()
plotOptions.column = HIColumn()
plotOptions.column.pointPadding = 0.2
plotOptions.column.borderWidth = 0
plotOptions.column.stacking = "normal"
options.plotOptions = plotOptions

let column = HIColumn()
let dataLabels = HIDataLabels()
dataLabels.crop = false
dataLabels.enabled = true
dataLabels.rotation = -90
dataLabels.color = HIColor(name: "white")
dataLabels.verticalAlign = "top"
column.dataLabels = [dataLabels]
column.data = [51550.75,29988.64,0, 216.56]

let line = HILine()
line.data = [28410.45,15879.97,0,0]

options.series = [column, line]
barotbhavesh commented 4 years ago

Yes thank you it's working Screenshot 2020-06-09 at 4 23 51 PM

But I need to show the short value

I am also trying this code Line

dataLabels.formatter = HIFunction(jsFunction: "function() { if (this.total > 1000000) { return '$ ' + Highcharts.numberFormat(this.total / 1000000, 2) + 'M'; } else if (this.total > 1000) { return '$ ' + Highcharts.numberFormat(this.total / 1000, 2) + 'k'; } else { return '$ ' + this.total; } }")

but not get success.

ihnatmoisieiev commented 4 years ago

@barotbhavesh it works for me

Simulator Screen Shot - iPhone 11 Pro - 2020-06-10 at 11 10 29

Also you can use this.y in your dataLabels formatter:

dataLabels.formatter = HIFunction(jsFunction: "function() { if (this.y > 1000000) { return '$ ' + Highcharts.numberFormat(this.y / 1000000, 2) + 'M'; } else if (this.y > 1000) { return '$ ' + Highcharts.numberFormat(this.y / 1000, 2) + 'k'; } else { return '$ ' + this.y; } }")
column.dataLabels = [dataLabels]
barotbhavesh commented 4 years ago

Yes, It's Working but I have an issue in the chart value Screenshot 2020-06-10 at 4 21 46 PM

in circle value not convert in short value

ihnatmoisieiev commented 4 years ago

@barotbhavesh just change the number format for this case

dataLabels.formatter = HIFunction(jsFunction: "function() { if (this.y > 1000000) { return '$ ' + Highcharts.numberFormat(this.y / 1000000, 2) + 'M'; } else if (this.y > 1000) { return '$ ' + Highcharts.numberFormat(this.y / 1000, 2) + 'k'; } else { return '$ ' + Highcharts.numberFormat(this.y, 2); } }")
column.dataLabels = [dataLabels]
barotbhavesh commented 4 years ago

yes its working thank you

Now I have another issue

In my other chart, I want to display a chart like this

Screenshot 2020-06-16 at 11 40 59 AM

I am trying to my self but empty data label Screenshot 2020-06-16 at 11 44 36 AM

sebastianbochan commented 4 years ago

Unfortunately we do not have an information how your data looks like. Please paste it here for the further debugging.

barotbhavesh commented 4 years ago

@ihnatmoisieiev can you please share your suggestion for the issue?

ihnatmoisieiev commented 4 years ago

@barotbhavesh as @sebastianbochan mentioned we don't know your data. Please share it.

ihnatmoisieiev commented 4 years ago

Closing due to inactivity.