gpt4 book ai didi

javascript - 使用动态数据向 highcharts 图表添加不同的符号

转载 作者:太空宇宙 更新时间:2023-11-03 10:42:13 25 4
gpt4 key购买 nike

所以我有一个 highchats 图表,它从 MySQL 数据库动态获取数据。

我希望每个系列都有不同的符号,但无论我尝试什么都不起作用,我的主要问题是我不确定在我的示例中我需要在哪里定义不同种类的符号。

我的 HTML:

<div id="container"></div>
<br />
<table border="0" cellpadding="0" cellspacing="0" id="sheet6" class="sheet6 gridlines">
<col class="col0">
<col class="col1">
<col class="col2">
<col class="col3">
<tbody>
<tr class="row0">
<td class="column0 style119 s">Month</td>
<td class="column1 style117 f">Manual</td>
<td class="column2 style117 f">Automated</td>
<td class="column3 style117 f">Profit/Loss</td>
</tr>
<tr class="row1">
<td class="column0 style0 n">0</td>
<td class="column1 style118 f">0</td>
<td class="column2 style118 f">0</td>
<td class="column3 style118 f">0</td>
</tr>
<tr class="row2">
<td class="column0 style0 n">1</td>
<td class="column1 style118 f">119</td>
<td class="column2 style118 f">551</td>
<td class="column3 style118 f">-432</td>
</tr>
<tr class="row3">
<td class="column0 style0 n">2</td>
<td class="column1 style118 f">238</td>
<td class="column2 style118 f">717</td>
<td class="column3 style118 f">-479</td>
</tr>
<tr class="row4">
<td class="column0 style0 n">3</td>
<td class="column1 style118 f">357</td>
<td class="column2 style118 f">860</td>
<td class="column3 style118 f">-504</td>
</tr>
<tr class="row5">
<td class="column0 style0 n">4</td>
<td class="column1 style118 f">476</td>
<td class="column2 style118 f">980</td>
<td class="column3 style118 f">-504</td>
</tr>
<tr class="row6">
<td class="column0 style0 n">5</td>
<td class="column1 style118 f">595</td>
<td class="column2 style118 f">991</td>
<td class="column3 style118 f">-396</td>
</tr>
<tr class="row7">
<td class="column0 style0 n">6</td>
<td class="column1 style118 f">713</td>
<td class="column2 style118 f">1002</td>
<td class="column3 style118 f">-288</td>
</tr>
<tr class="row8">
<td class="column0 style0 n">7</td>
<td class="column1 style118 f">832</td>
<td class="column2 style118 f">1012</td>
<td class="column3 style118 f">-180</td>
</tr>
<tr class="row9">
<td class="column0 style0 n">8</td>
<td class="column1 style118 f">951</td>
<td class="column2 style118 f">1023</td>
<td class="column3 style118 f">-72</td>
</tr>
<tr class="row10">
<td class="column0 style0 n">9</td>
<td class="column1 style118 f">1070</td>
<td class="column2 style118 f">1034</td>
<td class="column3 style118 f">37</td>
</tr>
<tr class="row11">
<td class="column0 style0 n">10</td>
<td class="column1 style118 f">1189</td>
<td class="column2 style118 f">1044</td>
<td class="column3 style118 f">145</td>
</tr>
<tr class="row12">
<td class="column0 style0 n">11</td>
<td class="column1 style118 f">1308</td>
<td class="column2 style118 f">1055</td>
<td class="column3 style118 f">253</td>
</tr>
<tr class="row13">
<td class="column0 style0 n">12</td>
<td class="column1 style118 f">1427</td>
<td class="column2 style118 f">1066</td>
<td class="column3 style118 f">361</td>
</tr>
<tr class="row14">
<td class="column0 style0 n">13</td>
<td class="column1 style118 f">1546</td>
<td class="column2 style118 f">1077</td>
<td class="column3 style118 f">469</td>
</tr>
<tr class="row15">
<td class="column0 style0 n">14</td>
<td class="column1 style118 f">1665</td>
<td class="column2 style118 f">1087</td>
<td class="column3 style118 f">578</td>
</tr>
<tr class="row16">
<td class="column0 style0 n">15</td>
<td class="column1 style118 f">1784</td>
<td class="column2 style118 f">1098</td>
<td class="column3 style118 f">686</td>
</tr>
<tr class="row17">
<td class="column0 style0 n">16</td>
<td class="column1 style118 f">1903</td>
<td class="column2 style118 f">1109</td>
<td class="column3 style118 f">794</td>
</tr>
<tr class="row18">
<td class="column0 style0 n">17</td>
<td class="column1 style118 f">2022</td>
<td class="column2 style118 f">1119</td>
<td class="column3 style118 f">902</td>
</tr>
<tr class="row19">
<td class="column0 style0 n">18</td>
<td class="column1 style118 f">2140</td>
<td class="column2 style118 f">1130</td>
<td class="column3 style118 f">1010</td>
</tr>
<tr class="row20">
<td class="column0 style0 n">19</td>
<td class="column1 style118 f">2259</td>
<td class="column2 style118 f">1141</td>
<td class="column3 style118 f">1119</td>
</tr>
<tr class="row21">
<td class="column0 style0 n">20</td>
<td class="column1 style118 f">2378</td>
<td class="column2 style118 f">1152</td>
<td class="column3 style118 f">1227</td>
</tr>
<tr><td></td></tr> </tbody>
</table>

我的JS:

    Highcharts.setOptions({
lang: {
thousandsSep: ','
}
});


var chart = new Highcharts.Chart({
colors: ["#cc1c0d", "#1d63af" , "#9eb215"],
chart: {
type: 'line',
backgroundColor:'rgba(255, 255, 255, 0.85)',
renderTo: 'container'
},
data: {
table: 'sheet6',
complete: function(options){
var series = options.series[1],
point = series.data[8];

series.data[8] = {
x: point[0],
y: point[1],
marker: {
fillColor: '#1d63af',
symbol: 'circle',
radius: 4
}
};
}
},
title: {
text: 'Cost Comparison: Manual vs. Automated Testing'
},
xAxis: {
tickInterval:3,
title: {
text: 'Months'
},
plotLines: [{
color: '#d9d9d6',
dashStyle: 'line',
value: 0,
width: 1
},
{
color: '#d9d9d6',
dashStyle: 'line',
value: 12,
width: 1
},
{
color: '#d9d9d6',
dashStyle: 'line',
value: 24,
width: 1
},
{
color: '#d9d9d6',
dashStyle: 'line',
value: 36,
width: 1
},
{
color: '#d9d9d6',
dashStyle: 'line',
value: 48,
width: 1
}],
},
plotOptions: {
series: {
marker: {
symbol: 'circle',
radius: 3,
fillColor: '#FFFFFF',
lineWidth: 2,
lineColor: null // inherit from series
},
shadow: true
}
},
yAxis: {
allowDecimals: false,
title: {
text: 'Cost [kUSD]'
},
labels: {
formatter: function () {
return Highcharts.numberFormat(this.value,0);
}
}
},
credits: {
enabled: false
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: 'Month {point.x}: {point.y} kUSD'
},
});

您可以在下面的 fiddle 下看到这一切的示例。

我非常感谢任何指向正确方向的指示。

最佳答案

你的图表只有一个符号,因为你定义了

plotOptions: {
series: {
marker: {
symbol: 'circle',
[...]

将所有系列的符号设置为“圆”。

如果您删除该行,那么 Highcharts 将为每个系列赋予它自己的符号(参见 http://api.highcharts.com/highcharts#series.marker.symbol)。它将遍历预定义的默认值,即“圆形”、“方形”、“菱形”、“三 Angular 形”和“向下三 Angular 形”。

如果你想自定义订单,你可以通过调用来提供它

Highcharts.setOptions({symbols:["triangle","square","diamond","circle"]});

关于javascript - 使用动态数据向 highcharts 图表添加不同的符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36541377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com