label value overlapping due to overcrowd in pie chart - swift

I am working on pie chart. Text values of pie chart are overlapping due to multiple data as shown in figure below. I am not getting how to separate out these data with no overlapping labels.
My code is
pieChartDataSet.colors = colors
pieChartDataSet.valueFormatter = ChartValueFormatter()
pieChartDataSet.valueLinePart1Length = 0.7
pieChartDataSet.valueLinePart2Length = 0.3
//pieChartDataSet.valueLinePart1OffsetPercentage = 80.0
pieChartDataSet.valueLineColor = .black;
pieChartDataSet.valueTextColor = .black;
pieChartDataSet.valueFont = UIFont(name: "Verdana", size: 8.0)!
pieChartDataSet.valueLineVariableLength = true
pieChartDataSet.yValuePosition = .outsideSlice;
pieChartDataSet.xValuePosition = .outsideSlice;

Related

iOS Charts Github :: Spacing

I'm using ios-charts to build a line chart and have been customizing it's design. However I'm having some issues with changing some settings/designs right now. This is what it currently looks like.
I can't seem to add vertical spacing between the legend and the graphs x axis labels. They are too close together.
let xAxis = chartView.xAxis
xAxis.labelPosition = .bottom // Emphasis
xAxis.labelFont = UIFont.systemFont(ofSize: 12, weight: .regular)
xAxis.axisLineWidth = 1
xAxis.axisMinimum = 239
xAxis.axisMaximum = 249
//xAxis.yOffset = 15 // ONLY ADDS TOP SPACE
// Legend
chartView.rightAxis.enabled = false // remove from the right side
chartView.legend.font = UIFont.systemFont(ofSize: 12, weight: .regular)
chartView.legend.yEntrySpace = 10
chartView.legend.formSize = 10
chartView.legend.yOffset = 10 // ONLY ADDS BOTTOM SPACE
Setting the verticalAlignment to VerticalAlignment.top (it is VerticalAlignment.bottom by default) should use the yOffset as the top space.
You can use this parameter:
chartView.legend.yOffset

Pie Chart entries outside slices have different position offsets

The Charts library I'm using: Daniel Gindi - Charts
If you look at the above image, the position offset of entries outside each slice are variable both in distance from the slice as well as in alignment.
What I want:
Align the entry text to be at the center outside the slice. [Look at 1 & 3]
Keep all the slice texts equidistant from the slice. [Look at 3 & 6]
What I tried so far:
I tried to play with valueLinePart1Length and valueLinePart2Length, but this just helped a little, didn't solve the problem completely. Also I went through all the variables of PieChartDataSet.
Still haven't figured out how to fix this, can someone point out am I missing something or how to fix the issue.
Edit: Added code
let values: [Double] = [16, 6, 1, 3]
let chartEntries: [PieChartDataEntry] = pieChartEntries(for: values)
let pieChartDataSet = PieChartDataSet(values: chartEntries, label: nil)
pieChartDataSet.sliceSpace = 2
pieChartDataSet.colors = colors
pieChartDataSet.valueLineWidth = 0
pieChartDataSet.valueLinePart1Length = 0.4
pieChartDataSet.valueLinePart2Length = 0
pieChartDataSet.valueTextColor = .black
pieChartDataSet.yValuePosition = .outsideSlice
pieChartDataSet.valueLineVariableLength = false
let pieChartData = PieChartData(dataSet: pieChartDataSet)
pieChart.data = pieChartData
change the yValuePosition to .insideSlice

Render multiple BarChartDataSets using danielgindi/Charts

I'm trying to create a bar chart using danielgindi/Charts (based on MPAndroidChart). I would like to use multiple data sets, but when I try to provide multiple sets to the BarChartView no bars are rendered.
let barView = BarChartView()
let set1 = BarChartDataSet()
set1.addEntry(BarChartDataEntry(x: 1, y: 1))
let set2 = BarChartDataSet()
set2.addEntry(BarChartDataEntry(x: 2, y: 2))
barView.data = BarChartData(dataSets: [set1, set2])
contentView = barView
In the above example, I would expect two bars to be displayed. However, no bars will appear at all.
If I provide only one data set, the chart will render as expected.
barView.data = BarChartData(dataSets: [set1])
The problem is that with multiple groups, the position of the bars on the x-axis will change. However, the axis minimum and maximum values do not automatically resize to fit the new data. They must be resized manually. For example:
let groupSpace = 0.3
let barSpace = 0.0
let groupWidth = barData.groupWidth(groupSpace: groupSpace, barSpace: barSpace)
columnView.xAxis.axisMinimum = 0
columnView.xAxis.axisMaximum = groupWidth * numOfEntriesPerSet
columnView.groupBars(fromX: 0, groupSpace: groupSpace, barSpace: barSpace)

How do I complete remove the draw value on bar chart using iOS charts with swift 3

I am trying to remove the bottom draw values (in black) on my X axis. I tried self.chartActual.drawValueAboveBarEnabled = false but all that does is move the values to below the top of the bar. I also tried self.chartActual.xAxis.drawLabelsEnabled = false but that hides my top labels.
How do I remove the drawvalue on the X axis using ios-charts?
let datamore = BarChartData()
let ds12 = BarChartDataSet(values: dataEntries, label: nil)
datamore.addDataSet(ds12)
datamore.setDrawValues(false)
I needed the last line AFTER adding the data.

How to put show an outline for each chart series in a RadChart?

I'm trying to customize the appearance of an ASP Web Forms RadChart where the series have FillType = Solid while still allowing visibility of the lesser point values behind larger ones. What I really want is each series to have an outline placed on top of all the fills (basically the effect of having a ChartSeriesType.Line on top of a ChartSeriesType.Area).
I've experimented with setting LineAppearance.Shadow, color transparency, and combinations of those but it's still too difficult to discern background series values.
Is there not a simple way to turn on an outline for each series when using a solid fill? OR to set the transparency of the background fill only, not the edges?
Note the transparency in the above image. I'm afraid allowing more transparency improves the visibility of background values but results in a horrible collection of pastel colors.
I suggest you to go through telerik documentation page RadControls for ASP.NET AJAX Documentation -Styling Chart Elements and this nice example Creating RadChart Programmatically - more complex example.
Code snippet:
// Define chart and titleRadChart radChart = new RadChart();
radChart.ChartTitle.TextBlock.Text = "My RadChart";
radChart.ChartTitle.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.Blue;
// Define chart series
ChartSeries chartSeries = new ChartSeries();
chartSeries.Appearance.LabelAppearance.Visible = false;
chartSeries.Name = "GDP";
chartSeries.Type = ChartSeriesType.Line;
chartSeries.Appearance.LineSeriesAppearance.Color = System.Drawing.Color.BlueViolet;
// Define the items in the series
chartSeries.AddItem(1);
chartSeries.AddItem(1.5);
chartSeries.AddItem(2.0);
chartSeries.AddItem(2.5);
chartSeries.AddItem(3.5);
// visually enhance the datapoints
chartSeries.Appearance.PointMark.Dimensions.AutoSize = false;
chartSeries.Appearance.PointMark.Dimensions.Width = 5;
chartSeries.Appearance.PointMark.Dimensions.Height = 5;
chartSeries.Appearance.PointMark.FillStyle.MainColor = System.Drawing.Color.Black;
chartSeries.Appearance.PointMark.Visible = true;
// Define chart series
ChartSeries chartSeries2 = new ChartSeries();
chartSeries2.Appearance.LabelAppearance.Visible = false;
chartSeries2.Name = "GNP";
chartSeries2.Type = ChartSeriesType.Line;
chartSeries2.Appearance.LineSeriesAppearance.Color = System.Drawing.Color.Green;
// Define the items in the series
chartSeries2.AddItem(2);
chartSeries2.AddItem(3);
chartSeries2.AddItem(3.5);
chartSeries2.AddItem(4);
chartSeries2.AddItem(4.5);
// visually enhance the data points
chartSeries2.Appearance.PointMark.Dimensions.AutoSize = false;
chartSeries2.Appearance.PointMark.Dimensions.Width = 5;
chartSeries2.Appearance.PointMark.Dimensions.Height = 5;
chartSeries2.Appearance.PointMark.FillStyle.MainColor = System.Drawing.Color.Black;
chartSeries2.Appearance.PointMark.Visible = true;
// set the plot area gradient background fill
radChart.PlotArea.Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
radChart.PlotArea.Appearance.FillStyle.MainColor = System.Drawing.Color.FromArgb(65, 201, 254);
radChart.PlotArea.Appearance.FillStyle.SecondColor = System.Drawing.Color.FromArgb(0, 107, 186);
// Set text and line for X axis
radChart.PlotArea.XAxis.AxisLabel.TextBlock.Text = "Years";
radChart.PlotArea.XAxis.AxisLabel.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.Red;
radChart.PlotArea.XAxis.Appearance.Width = 3;
radChart.PlotArea.XAxis.Appearance.Color = System.Drawing.Color.Red;
// Set text and line for Y axis
radChart.PlotArea.YAxis.AxisLabel.TextBlock.Text = "%";
radChart.PlotArea.YAxis.AxisLabel.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.Red;
radChart.PlotArea.YAxis.Appearance.Width = 3;
radChart.PlotArea.YAxis.Appearance.Color = System.Drawing.Color.Red;
// Add the series to the chart, chart to page.radChart.Series.Add(chartSeries);radChart.Series.Add(chartSeries2);this.Page.Controls.Add(radChart)
Hope this help..