Avatar of altariamx2003
altariamx2003Flag for Mexico

asked on 

how to customize the text in the legend in highcharts

hi

i got this chart
User generated image
$(function () {
  $('#laprueba').highcharts
  ({
     title: { text: 'Resultados segun parametros seleccionados' },
     xAxis: { categories: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'] },
     tooltip: { shared: true }, 
     plotOptions: {   column: { stacking: 'normal' }   },
     yAxis: [
              { 
                labels: { enabled: false }, title: { text: '' },
	            allowDecimals: false, min: 0, title: { text: '' }, 
		        stackLabels: { enabled: true, formatter: function() { return  this.stack; } }
              },                            { 
                labels: { enabled: false }, title: { text: '' },
	            allowDecimals: false, min: 0, title: { text: '' }, 
		        stackLabels: { enabled: true, formatter: function() { return  this.stack; } }
              },                            { 
                labels: { enabled: false }, title: { text: '' },
	            allowDecimals: false, min: 0, title: { text: '' }, 
		        stackLabels: { enabled: true, formatter: function() { return  this.stack; } }
              }, 
            ],     plotOptions: {   column: { stacking: 'normal' }   },
            series: 
            [
               {
		 type: 'column',
                 name: 'Cursos-2016',
                 data: [4, 102, 14, 88, 42, 19, 12, 12, 14, 4, 1, 1], stack: '2016',color: Highcharts.getOptions().colors[0]
               },
               {
		 type: 'column', name: 'Cursos-2017',
                 data: [2, 2, 3,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ], stack: '2017',showInLegend: false,color: Highcharts.getOptions().colors[0]
               },
               {
		 type: 'column', name: 'Diplomados-2016',
                 data: [0,0 , 2, 18,0 , 71, 14, 5, 5,0 , 2, 1], stack: '2016',color: Highcharts.getOptions().colors[1]
               },
               {
		 type: 'column', name: 'Diplomados-2017',
                 data: [2, 2, 3, 1,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ], stack: '2017',showInLegend: false,color: Highcharts.getOptions().colors[1]
               },
	       {
                 name: 'Ventas (Inscripciones) 2016', type: 'spline', yAxis: 1,
                 data: [14022.9, 11284.99, 847, 37803.35, 18647.95, 22947, 21077, 31609.28, 40776.6, 3411, 14741, 19770],
                 marker: { enabled: true }, color: Highcharts.getOptions().colors[3],
                 tooltip: {  valuePrefix: '$ ', valueSuffix: ' USD' }
               },
 	       {
                 name: 'Ventas (Inscripciones) 2017', type: 'spline', yAxis: 2,
                 data: [14250, 700, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                 marker: { enabled: true }, color: Highcharts.getOptions().colors[4],
                 tooltip: {  valuePrefix: '$ ', valueSuffix: ' USD' }
               }
            ]
  });
});

Open in new window


I wanna know if it is possible to customize the legend section without to move any of my tooltip, I mean change the legend section from this:User generated image to thisUser generated image
JavaScriptScripting LanguagesHTML

Avatar of undefined
Last Comment
altariamx2003
ASKER CERTIFIED SOLUTION
Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of altariamx2003

ASKER

thx for your answer leonidas

I tried that, but the problem is that it change me the text of the last two series "Ventas (Inscripciones) 2016" and "Ventas (inscripciones) 2017"

It is possible to apply it just for the first two series????
Avatar of altariamx2003
altariamx2003
Flag of Mexico image

ASKER

I found how to modify the first 2 series name on the legend

legend: {
            layout: 'horizontal',
            labelFormatter: function () {
				if (this.name.indexOf("-") !=-1) 
				{ 
				  temp = this.name.split("-");
				  return temp[0]; 
				}
				else { return this.name; }
                
            }
        },

Open in new window


All credits goes to leonidas without his help I will never found the solution
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo