Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
Highcarts: oculta la categoría xAxis cuando la serie no está visible

Tengo un gráfico de columnas apiladas donde definí una serie por categoría xAxis. Cuando hago clic en la serie en la leyenda, la serie se oculta, que es lo que quiero. Pero si la serie no está al borde del eje X, la categoría permanece visible. Me gustaría eliminar la etiqueta xAxis para las series que no están visibles sin eliminarlas de la leyenda, para que puedan volver a aparecer cuando se haga clic nuevamente en la leyenda. ¿Alguna idea sobre cómo puedo lograr esto?

cuadro

Estoy usando HighchartsReact from 'highcharts-react-official' . El código para configurar mis opciones es el siguiente:

 const getHighChartsSeries = (columns: string[], tsvdata: tsvdata[]) => { const series = []; for (let serie in columns) { const seriedata: tsvdata = tsvdata.filter((m) => m.sample_id === columns[serie])[0]; const seriesColors = getSeriesColors(seriedata.data.map((m) => Number(m.seq_freq))); const data = seriedata.data.map((sd, index) => { return { x: Number(serie), y: Math.round(Number(sd.seq_freq) * 10000) / 100, name: sd.clone_id, color: seriesColors[index], }; }); const serieEntry: Highcharts.SeriesOptionsType = { name: columns[serie], type: 'column', data: data, color: baseColor, }; series.push(serieEntry); } return series; }; const setHighChartsOptions= (tsvdata: tsvdata[]) => { const columns = tsvdata.map((item) => item.sample_id); const series = getHighChartsSeries(columns, tsvdata); const options: Highcharts.Options = { chart: { type: 'column', zoomType: 'xy', }, title: { text: props.title, }, xAxis: { showEmpty: false, categories: columns, }, yAxis: { min: 0, max: 100, title: { text: 'Percentage', }, }, tooltip: { headerFormat: '<b>{point.x}:</b><br/>', pointFormat: '<b>{point.name}:</b> {point.y} %<br/>', }, plotOptions: { column: { stacking: 'normal', dataLabels: { enabled: true, format: '{point.name}', }, }, }, series: series, credits: { enabled: false, }, }; setOptions(options); };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En primer lugar, deberá usar legendItemClick para configurar su acción.

Referencia de la API: https://api.highcharts.com/highcharts/series.column.events.legendItemClick

Si solo desea eliminar xAxis.labels , simplemente actualícelos mediante labels.formatter :

 plotOptions: { column: { stacking: "normal", events: { legendItemClick: function () { let name = this.name; if (this.visible) { this.chart.update({ xAxis: { labels: { formatter() { if (this.value === name) { return ""; } else { return this.value; } } } } }); } else if (!this.visible) { this.chart.update({ xAxis: { labels: { formatter() { return this.value; } } } }); } } } } },

Demostración: https://codesandbox.io/s/highcharts-react-demo-forked-gcbz2g

Referencia de la API: https://api.highcharts.com/highcharts/xAxis.labels.formatter

Si desea eliminar las etiquetas y el espacio que deja una categoría oculta, debe usar el módulo broken-axis.js

 plotOptions: { column: { stacking: "normal", grouping: false, pointPlacement: null, events: { legendItemClick: function () { if (!this.visible) { breaks[this.index] = {}; this.chart.xAxis[0].update({ breaks: breaks }); } else { breaks[this.index] = { from: this.xData[0] - 0.5, to: this.xData[0] + 0.5, breakSize: 0 }; this.chart.xAxis[0].update({ breaks: breaks }); } } } } },

Demostración: https://codesandbox.io/s/highcharts-react-demo-forked-n502os?file=/demo.jsx:678-1453

Referencia de la API: https://api.highcharts.com/highcharts/xAxis.breaks

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!