Highcharts Packed Bubble 自动脉动和移动

huangapple go评论87阅读模式
英文:

Highcharts Packed Bubble Automatically Pulsate & Move

问题

I am working with the Packed bubble chart in Highcharts and have been trying to create an effect where the individual bubbles grow and shrink plus random forces are applied so that the graph is constantly moving.

I have managed to create the base graph with the following code

randomInt = 300;

Highcharts.chart('container', {
  chart: {
    type: 'packedbubble',
    height: '100%'
  },
  plotOptions: {
    packedbubble: {
      minSize: '5%',
      maxSize: '100%',
      zMin: 0,
      zMax: 1000,
      layoutAlgorithm: {
        gravitationalConstant: 0.02,
        splitSeries: false,
        dragBetweenSeries: true,
        parentNodeLimit: true
      }
    }
  },
  series: [
    {
      name: 'Vegetable',
      data: [{
        name: 'Breakfast',
        value: 5
      },
      {
        name: 'Lunch',
        value: 5
      },
      {
        name: 'Lunch',
        value: 5
      },
      {
        name: 'Dinner',
        value: 5
      }]
    }, {
      name: 'Fruit',
      data: [{
        name: 'Breakfast',
        value: 5
      },
      {
        name: 'Lunch',
        value: 5
      }]
    }, {
      name: 'Grain',
      data: [{
        name: 'Breakfast',
        value: 5
      },
      {
        name: 'Breakfast',
        value: 5
      },
      {
        name: 'Lunch',
        value: 5
      },
      {
        name: 'Lunch',
        value: 5
      },
      {
        name: 'Dinner',
        value: 5
      },
      {
        name: 'Dinner',
        value: 5
      }]
    }]
});

I have attempting to set the value of each entry in series to a variable which changes over time using a simple function but the chart isn't updated to reflect these changing weightings.

To get the bubbles moving like they do when dragged I consulted the documentation here but I couldn't find any way to manually apply a force programmatically.

英文:

I am working with the Packed bubble chart in Highcharts and have been trying to create an effect where the individual bubbles grow and shrink plus random forces are applied so that the graph is constantly moving.

I have managed to create the base graph with the following code

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-js -->

randomInt = 300;
Highcharts.chart(&#39;container&#39;, {
chart: {
type: &#39;packedbubble&#39;,
height: &#39;100%&#39;
},
plotOptions: {
packedbubble: {
minSize: &#39;5%&#39;,
maxSize: &#39;100%&#39;,
zMin: 0,
zMax: 1000,
layoutAlgorithm: {
gravitationalConstant: 0.02,
splitSeries: false,
dragBetweenSeries: true,
parentNodeLimit: true
}
}
},
series: [
{
name: &#39;Vegetable&#39;,
data: [{
name: &#39;Breakfast&#39;,
value: 5
},
{
name: &#39;Lunch&#39;,
value: 5
},
{
name: &#39;Lunch&#39;,
value: 5
},
{
name: &#39;Dinner&#39;,
value: 5
}]
}, {
name: &#39;Fruit&#39;,
data: [{
name: &#39;Breakfast&#39;,
value: 5
},
{
name: &#39;Lunch&#39;,
value: 5
}]
}, {
name: &#39;Grain&#39;,
data: [{
name: &#39;Breakfast&#39;,
value: 5
},
{
name: &#39;Breakfast&#39;,
value: 5
},
{
name: &#39;Lunch&#39;,
value: 5
},
{
name: &#39;Lunch&#39;,
value: 5
},
{
name: &#39;Dinner&#39;,
value: 5
},
{
name: &#39;Dinner&#39;,
value: 5
}]
}]
});

<!-- language: lang-html -->

&lt;script src=&quot;https://code.highcharts.com/highcharts.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://code.highcharts.com/highcharts-more.js&quot;&gt;&lt;/script&gt;
&lt;figure class=&quot;highcharts-figure&quot;&gt;
&lt;div id=&quot;container&quot;&gt;&lt;/div&gt;
&lt;/figure&gt;

<!-- end snippet -->

I have attempting to set the value of each entry in series to a variable which changes over time using a simple function but the chart isn't updated to reflect these changing weightings.

To get the bubbles moving like they do when dragged I consulted the documentation here but I couldn't find any way to manually apply a force programmatically.

答案1

得分: 1

Highcharts有方法来动态更新图表元素。您可以使用chart.update()方法来一次性更新所有系列。您还可以使用series.setData()方法来更新特定系列的数据点,或者更精确地,如果您只想更新特定点,可以使用point.update()方法。

const chart = Highcharts.chart('container', {
  chart: {
    type: 'packedbubble'
  },
  plotOptions: {
    packedbubble: {
      minSize: '5%',
      maxSize: '100%',
      zMin: 0,
      zMax: 50
    }
  },
  series: [{
    data: [5, 4, 3]
  }, {
    data: [4, 5]
  }, {
    data: [5, 5, 5, 5]
  }]
});

setTimeout(function() {
  chart.series[0].setData([5, 14, 3])
}, 2000);

setTimeout(function() {
  chart.series[1].points[0].update({
    value: 50
  })
}, 4000);

Demo: https://jsfiddle.net/BlackLabel/s0k7fnhx/
API: https://api.highcharts.com/class-reference/Highcharts.Chart#update
https://api.highcharts.com/class-reference/Highcharts.Series#setData
https://api.highcharts.com/class-reference/Highcharts.Point#update

英文:

Highcharts has methods to dynamically update chart elements. You can use the char.update() method to update all series at once. You can also use the series.setData() method to update points for a specific series, or more precisely if you only want to update a specific point, you will achieve it by using point.update() method.

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-js -->

const chart = Highcharts.chart(&#39;container&#39;, {
chart: {
type: &#39;packedbubble&#39;
},
plotOptions: {
packedbubble: {
minSize: &#39;5%&#39;,
maxSize: &#39;100%&#39;,
zMin: 0,
zMax: 50
}
},
series: [{
data: [5, 4, 3]
}, {
data: [4, 5]
}, {
data: [5, 5, 5, 5]
}]
});
setTimeout(function() {
chart.series[0].setData([5, 14, 3])
}, 2000);
setTimeout(function() {
chart.series[1].points[0].update({
value: 50
})
}, 4000);

<!-- language: lang-html -->

&lt;script src=&quot;https://code.highcharts.com/highcharts.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://code.highcharts.com/highcharts-more.js&quot;&gt;&lt;/script&gt;
&lt;div id=&quot;container&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

Demo: https://jsfiddle.net/BlackLabel/s0k7fnhx/ <BR/>
API: https://api.highcharts.com/class-reference/Highcharts.Chart#update <BR/>
https://api.highcharts.com/class-reference/Highcharts.Series#setData <BR/>
https://api.highcharts.com/class-reference/Highcharts.Point#update

答案2

得分: 0

dataLabels enabled: true

dataLabels: {
enabled: true,
format: '{point.name}',
style: {
color: 'black',
textOutline: 'none',
fontWeight: 'normal'
}
}

https://jsfiddle.net/my9f382a/12/

英文:

Try dataLabels enabled: true

    dataLabels: {
enabled: true,
format: &#39;{point.name}&#39;,
style: {
color: &#39;black&#39;,
textOutline: &#39;none&#39;,
fontWeight: &#39;normal&#39;
}
}

https://jsfiddle.net/my9f382a/12/

huangapple
  • 本文由 发表于 2023年3月3日 19:49:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75626720.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定