question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Legend and title - ability to set chart title and legend

See original GitHub issue

I don’t know if this already exists, or if this should be part of the charts, but I thought I’d suggest these anyway in case it makes sense:

  • The ability to set a title that appears somewhere in the LineChart area. Something like chart.setTitle
  • The ability to show a legend (eg when using multiple line) indicating what the different line colors mean. I suppose this could be derived from something like Line.setName.

Anyway, thanks for all the work on this chart, it’s very nice and easy to use. The structure of the charts has been well thought out.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
lechocommented, Apr 25, 2016

Hi, I’m not working on that. I don’t understand what’s the problem and why many people ask about that. Legend can be created as separated view so you and anybody else could create it on your own. It is even a good idea to separate legend from chart view because legend view don’t have to be invalidated so often. Data sharing between chart and legend is also not an issue. What’s more everyone want the legend to look in a different way. So I have no plans to add legend until someone provide or propose some viable solution.

0reactions
abdeladim-scommented, Apr 26, 2018

Hi all, if someone still need to add titles as legend to their charts,this is my own implementation:

public void addTitles(LineChartView chart, List<Line> lines,
   		String[] titles, int textSize, String backgroundColor, int backgrounfAlpha) {
   	if (lines.size() != titles.length) {
   		return;
   	}
   	// set a linear layout container
   	LinearLayout listOfTitles = new LinearLayout(getActivity());
   	listOfTitles.setOrientation(LinearLayout.VERTICAL);
   	LayoutParams LLParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
   			LayoutParams.WRAP_CONTENT);
   	listOfTitles.setLayoutParams(LLParams);
              // set radius corners 
   	GradientDrawable shape = new GradientDrawable();
   	shape.setCornerRadius(8);
   	shape.setColor(Color.parseColor(backgroundColor));
   	shape.setAlpha(backgrounfAlpha);
   	listOfTitles.setBackground(shape);

   	TextView[] textViewTitles = new TextView[titles.length];

   	for (int i = 0; i < titles.length; i++) {
   		textViewTitles[i] = new TextView(getActivity());
   		textViewTitles[i].setTextColor(lines.get(i).getColor());
   		textViewTitles[i].setText(titles[i]);
   		textViewTitles[i].setTextSize(textSize);
   		listOfTitles.addView(textViewTitles[i]);
   	}

   	// get chart parent
   	ViewGroup v = (ViewGroup) chart.getParent();

   	v.addView(listOfTitles);

   	listOfTitles.bringToFront();
   	
   	// make the view draggable 
   	listOfTitles.setOnTouchListener(this);

   }

if you want to make the legend draggable : 1 - add implements OnTouchListener to your activity and then :

        float dX = 0;
	float dY = 0;
	@Override
	public boolean onTouch(View view, MotionEvent event) {
		switch (event.getActionMasked()) {
		case MotionEvent.ACTION_DOWN:
			dX = view.getX() - event.getRawX();
			dY = view.getY() - event.getRawY();
			break;

		case MotionEvent.ACTION_MOVE:
			view.setY(event.getRawY() + dY);
			view.setX(event.getRawX() + dX);
			break;

		default:
			return false;
		}
		return true;
	}

Thanks @lecho for the library!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change legend names - Microsoft Support
Change the legend name using select data​​ Select your chart in Excel, and click Design > Select Data. Click on the legend name...
Read more >
Excel charts: add title, customize chart axis, legend and data ...
The tutorial shows how to create and customize graphs in Excel: add a chart title, change the way that axes are displayed, format...
Read more >
How to Edit a Legend in Excel | CustomGuide
Change the Chart Title · Select the chart. · Right-click the chart title. · Click the Edit Text button. Titles and Legends. Double-click...
Read more >
How to change legend title in excel|MS Excel Quick tips
Contact me at catia.pro.user@gmail.com to get howENGINEERSdoit t shirt..!!This series is dedicated to those who would like to practice on ...
Read more >
Titles, Axis, Legend, Data Labels, Gridlines - YouTube
Learn how to add and change chart elements like axis titles, title of the chart, chart layout, data labels and chart legend.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found