Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧐[Question] how to connect Columns with annotations with labels? #2845

Open
d0ublezer0 opened this issue Jan 22, 2025 · 0 comments
Open

Comments

@d0ublezer0
Copy link

🧐 I need to create annotation polyline that connects some columns in Column chart, with text label on top center

How to do this?
The problem is: a cannot put text annotation between columns, only to dataset index.
So, i try to calculate column width with fixed chart width, but result is so unstable and not flexible.
In 1.x version i can use float indexes to put annotation between columns

💻 Code example


const DemoColumn = () => {
  const chartWidth = 800
  const columnWidth = 70

const data = [
  { type: 1, value: 2 },
  { type: 2, value: 1 },
  { type: 3, value:3 },
  { type: 4, value: 4 },

];
  const config = {
    data,
    xField: 'type',
    yField: 'value',
    width: chartWidth,
    style: {
      fill: ({ type }) => {
        if (type === '10-30分' || type === '30+分') {
          return '#22CBCC';
        }
        return '#2989FF';
      },
      minWidth: columnWidth,
      maxWidth: columnWidth,
    },
    scaleValue: {
      x: {
        label: false
      },
    },
    label: {
      text: (originData) => {
        const val = parseFloat(originData.value);
        return val
      },
    },
    
    legend: false,
       annotations: [
     
      {
        type: 'line',
        xField: 'type',
        yField: 'value',        
        data: [
          {type: 1, value: 2},
          {type: 1, value: 4.5},
          {type: 4, value: 4.5},
          {type: 4, value: 4},
          ],
        style: { 
          arrow: true, 
          stroke: 'red', 
          lineDash: [2, 2], 
        },
        tooltip: false
        
      },
         {
        type: 'text',
        xField: 'type',
        yField: 'value',
        data: [1,4.5],
        style: {
          text: 'label 100',
          // (chartWidth / columnCount / 2) * betweenConnectedColumns - ticksWidth
          dx: ((chartWidth/4) / 2) * 3 - 20,
          textAlign: 'center',
          fill: 'red',
          background: true,
          backgroundRadius: 4,
          backgroundFill: 'yellow',
          backgroundOpacity: 10,
          backgroundStroke:'red',          
        },
        tooltip: false,
      },
    ],
  };
  return <Column {...config} />;
};

there is old working example from 1.x Ant charts version

const annotations: = [{
          type: 'text',
          content,
// the non-integer position worked well
          position: [startIndex + (endIndex - startIndex) / 2, lineHeight],
        }]

🚑 Example, what i need

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant