我正在努力寻找一种方法来返回当前Y值工具提示中图表中的前一个Y值。我的想法是,我想要执行" this.y - this.y(-1)" (得到这个。(y-1))值并找出当前和之前的值之间的差异。理想情况下,这将位于图表
中每个值的工具提示中我的代码如下:
public class SingleCheckAdapter extends RecyclerView.Adapter<SingleCheckAdapter.SingleCheckViewHolder> {
private int mSelectedItem = -1;
private List<PersonItem> mSingleCheckList;
private Context mContext;
private AdapterView.OnItemClickListener onItemClickListener;
public SingleCheckAdapter(Context context, List<PersonItem> listItems) {
mContext = context;
mSingleCheckList = listItems;
}
@Override
public SingleCheckViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
LayoutInflater inflater = LayoutInflater.from(mContext);
final View view = inflater.inflate(R.layout.item_single_check, viewGroup, false);
return new SingleCheckViewHolder(view, this);
}
@Override
public void onBindViewHolder(SingleCheckViewHolder viewHolder, final int position) {
PersonItem item = mSingleCheckList.get(position);
try {
viewHolder.setDateToView(item, position);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public int getItemCount() {
return mSingleCheckList.size();
}
public void setOnItemClickListener(AdapterView.OnItemClickListener onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}
public void onItemHolderClick(SingleCheckViewHolder holder) {
if (onItemClickListener != null)
onItemClickListener.onItemClick(null, holder.itemView, holder.getAdapterPosition(), holder.getItemId());
}
class SingleCheckViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private SingleCheckAdapter mAdapter;
private RadioButton mRadio;
private TextView mText;
public SingleCheckViewHolder(View itemView, final SingleCheckAdapter mAdapter) {
super(itemView);
this.mAdapter = mAdapter;
mText = (TextView) itemView.findViewById(R.id.text);
mRadio = (RadioButton) itemView.findViewById(R.id.radio);
itemView.setOnClickListener(this);
mRadio.setOnClickListener(this);
}
public void setDateToView(PersonItem item, int position) throws Exception {
mRadio.setChecked(position == mSelectedItem);
mText.setText(item.getPersonName());
}
@Override
public void onClick(View v) {
mSelectedItem = getAdapterPosition();
notifyItemRangeChanged(0, mSingleCheckList.size());
mAdapter.onItemHolderClick(SingleCheckViewHolder.this);
}
}
答案 0 :(得分:1)
您需要在工具提示格式化程序中使用 this.point 对象的索引和系列属性。< / p>
tooltip: {
formatter:function(){
var diffText = '',
i = this.point.index;
if (i > 0) {
diffText = '<br><b>Difference: </b>' + (this.y - this.point.series.data[i-1].y);
}
return '<b>Date:</b> ' + Highcharts.dateFormat('%B %e %Y', this.x) + '<br>' + '<b>Amount:</b> ' + this.y + '<br>' + diffText;
}
},