MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

how to make empty space in a line chart?

Open lucifernipun22 opened this issue 3 years ago • 8 comments

0zwWc how can I achieve this?

lucifernipun22 avatar Feb 24 '22 06:02 lucifernipun22

WhatsApp Image 2022-02-24 at 18 37 39 How to get the spacing between null data which is show is the first image how to achieve this thing in this graph?

lucifernipun22 avatar Feb 24 '22 13:02 lucifernipun22

I think you can use two datasets. The line drawn from a dataset must be continuous.

VinsonGuo avatar Mar 02 '22 03:03 VinsonGuo

@VinsonGuo answer may be useful but not elegant. below is my advice: If you want certain data not show in line chart,you can just edit library class LineChartRenderer . eg:I add one code to show space when (int) e1.getX() %3 == 0 image then I get below image.

image

gs666 avatar Jun 09 '22 06:06 gs666

@VinsonGuo answer may be useful but not elegant. below is my advice: If you want certain data not show in line chart,you can just edit library class LineChartRenderer . eg:I add one code to show space when (int) e1.getX() %3 == 0 image then I get below image.

image

I cant seem to get this working, the line is not broken, its just joining the line between the gap.

Do you have example of code to check what options you are having for lines and chart?

Many thanks.

johnnyzen avatar Sep 05 '22 14:09 johnnyzen

Its ok, I got it working. Found this way was good for me

add line to LineChartRenderer class at same position as @VinsonGuo above if (e1.getData() == null) continue;

When y value null, create entry like this

lineDataSet.addEntry( Entry(index, 0.0f,null))

Linechart will not draw the line.

Also works with live updating data, where you use "chart.moveViewToX" to scroll the data coming through.

johnnyzen avatar Sep 06 '22 08:09 johnnyzen

@johnnyzen It's a good solution. However, I think we shouldn't alter the source code if we must do. In some cases, the gap of lines wouldn't be 3 or a fixed number, and these codes may affect other line charts that need a continuous line in the same project.

VinsonGuo avatar Sep 07 '22 06:09 VinsonGuo

@VinsonGuo thanks. Yeah i know its not great in that sense, but with other solutions, like the "use two datasets" techique, using chart.moveViewToX when scrolling live data causes the lines to join together when a break is needed. I've no idea why this happens.

johnnyzen avatar Sep 07 '22 07:09 johnnyzen

@johnnyzen It's a good solution. However, I think we shouldn't alter the source code if we must do. In some cases, the gap of lines wouldn't be 3 or a fixed number, and these codes may affect other line charts that need a continuous line in the same project.

I know what you mean.

We can create a new class extends LineChartRenderer,then just bind this render to our current chart,just like viewBinding.bubbleChart.renderer = heatMapChartRenderer.It can ensure the edited code won't affect other chart. 【明知道你是中国人,还要强行说英语感觉更累了,哈哈】

gs666 avatar Sep 07 '22 10:09 gs666