可以在类别中使用Highcharts Scatter Plot吗?

时间:2013-05-08 22:56:07

标签: highcharts

Highcharts v3.01

我正在尝试使用散点图在命名类别中绘制点(这些点实际上是数字,但不在系列中,我不想要间隙)。

使用折线图类型可行,但我不愿意,因为我可能有数百个系列和散点更清晰。

我最接近的是:

编辑 - 我会发布描述性图片,但显然我需要声望点。叹。

请参见此处:http://i117.photobucket.com/albums/o63/Harry_Flashman/close_zpsfe6d3ea2.png

这是使用引用x和y的点,

data: [{x:108432,test:100,y:0}, {x:109802,test:100,y:51}, etc. ]

我想完全如上所述,但没有差距。

我能看到有一个非线性无间隙轴的唯一方法是使用类别,我以前在其他线型图上使用过,但从未使用过散点图​​。

如果我使用带有类别数组的x轴类型“category”,它只为每个分配一个散点值,其余为升序数字类别(即如果我使用点“名称,它不会对它们进行分组) “选项”。

xAxis: {
  type: category,
  categories: ['108432','109802','110240', etc. ]
}

数据点如下所示:

data: [{name:'108432',test:100,y:0}, {name:'109802',test:100,y:51}, etc. ]

这样结束。每个散点都有自己的类别。

http://i117.photobucket.com/albums/o63/Harry_Flashman/not_zps31aa4fef.png

任何帮助表示感谢,如果能让它发挥作用,这将是非常好的。

谢谢!

专利

PS。下面添加了整个图表脚本(减去大量数据)。这是“几乎可以工作”的版本。

$('#container').highcharts({
  chart:    { type: 'scatter', zoomType: 'xy'     },
  title:    { text: 'Revision vs Runtime Scatter' },
  subtitle: { text: 'L3 Performance Test'         },
  xAxis:    {
    title:      { enabled: true, text: 'Revision' },
    startOnTick:   true,
    endOnTick:     true,
    showLastLabel: true,
    showEmpty:     false,
    legend:      { y: 120, floating: true, backgroundColor: '#FFFFFF' },
    labels:      { rotation: -90, align: 'right' },
    categories:  ['101831','101849','101850','101857','101861','101866','101868','101878','101879','101880','101881','101882','101883','101884','101885','101888','101894','101900','101903','101905','101908','101913','101914']
  },
  yAxis:       { title: { text: 'Variance (%)' } },
  legend:      { layout: 'vertical' },
  plotOptions: {
    scatter: {
      marker: { radius: 5, states: { hover: { enabled: true, lineColor: 'rgb(100,100,100)' } } },
        states: { hover: { marker: { enabled: false } } },
        tooltip: {
          headerFormat: '<b></b>',
          pointFormat: '<b>Test {point.test}</b><br/>r{point.x}<br/>{point.y}% change<br/>{series.name}'
        }
      }
    },
    series: [{
      name: 'PRd',
      data: [{x:101857,test:267,y:0}, {x:101861,test:267,y:-1}, {x:101866,test:267,y:-0}, {x:101868,test:267,y:-1}, {x:101878,test:267,y:-1}, {x:101879,test:267,y:-1}, {x:101880,test:267,y:-0}, {x:101881,test:267,y:-0}, {x:101882,test:267,y:-0}, {x:101883,test:267,y:-0}, {x:101884,test:267,y:-0}, {x:101885,test:267,y:-0}, {x:101888,test:267,y:-0}, {x:101894,test:267,y:-1}, {x:101900,test:267,y:-0}, {x:101903,test:267,y:-0}, {x:101905,test:267,y:-1}, {x:101908,test:267,y:-1}, {x:101913,test:267,y:0}, {x:101914,test:267,y:1}, {x:101831,test:430,y:0}, {x:101849,test:430,y:1}, {x:101850,test:430,y:1}]
      }, {
      name: 'Non-PRd',
      data: [{x:101831,test:100,y:0}, {x:101849,test:100,y:51}, {x:101850,test:100,y:51}, {x:101857,test:100,y:52}, {x:101861,test:100,y:49}, {x:101866,test:100,y:50}, {x:101868,test:100,y:50}, {x:101878,test:100,y:50}, {x:101879,test:100,y:50}, {x:101880,test:100,y:50}, {x:101881,test:100,y:50}, {x:101882,test:100,y:50}, {x:101883,test:100,y:50}, {x:101884,test:100,y:50}, {x:101885,test:100,y:50}, {x:101888,test:100,y:50}, {x:101894,test:100,y:50}, {x:101900,test:100,y:50}, {x:101903,test:100,y:0}, {x:101905,test:100,y:50}, {x:101908,test:100,y:51}, {x:101913,test:100,y:50}, {x:101914,test:100,y:50}, {x:101831,test:10937,y:0}, {x:101849,test:10937,y:2}]
    }]
  });
});

1 个答案:

答案 0 :(得分:3)

好的,通过解决方法修复它,

基本上在Javascript中,我添加了一个位置,指向与点属于哪个类别相关的点数组(通过PHP生成,类别按升序排序)。相关位如下:

xAxis:    {
  categories: ['r101831', 'r101849', 'r101850']
}   

plotOptions: {
  tooltip: {
    headerFormat: '<b></b>',
    pointFormat: '
      <b>Test {point.test}</b><br/>
      r{point.revision}<br/>
      {point.y}% change<br/>
      {series.name}'
  }
}

series: [{
  name: 'PRd',
  data: [
  {x:3,revision:101831,test:267,y:0},
  {x:4,revision:101849,test:267,y:-1},
  {x:5,revision:101850,test:267,y:-0}
  ]}
]

最终结果看起来华丽,我喜欢HighCharts。

图片来源:http://i117.photobucket.com/albums/o63/Harry_Flashman/fixed_zps9952d58d.png